2010-09-11 22:57:39 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2011-01-12 02:50:45 +01:00
|
|
|
/* .BAF - Bizarre Creations (Blur, James Bond 007: Blood Stone, etc) */
|
2010-09-11 22:57:39 +02:00
|
|
|
|
|
|
|
VGMSTREAM * init_vgmstream_baf(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
char filename[260];
|
2011-01-12 02:50:45 +01:00
|
|
|
off_t WAVE_size,DATA_size;
|
2010-09-11 22:57:39 +02:00
|
|
|
off_t start_offset;
|
2011-01-12 02:50:45 +01:00
|
|
|
long sample_count;
|
2010-09-11 22:57:39 +02:00
|
|
|
|
2011-01-12 02:50:45 +01:00
|
|
|
const int frame_size = 33;
|
|
|
|
const int frame_samples = 64;
|
2010-09-11 22:57:39 +02:00
|
|
|
int channels;
|
|
|
|
int loop_flag = 0;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
|
|
|
if (strcasecmp("baf",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check WAVE */
|
|
|
|
if (read_32bitBE(0,streamFile) != 0x57415645) goto fail;
|
|
|
|
WAVE_size = read_32bitBE(4,streamFile);
|
|
|
|
if (WAVE_size != 0x4c) goto fail;
|
|
|
|
/* check for DATA after WAVE */
|
|
|
|
if (read_32bitBE(WAVE_size,streamFile) != 0x44415441) goto fail;
|
|
|
|
/* check that WAVE size is data size */
|
2011-01-12 02:50:45 +01:00
|
|
|
DATA_size = read_32bitBE(0x30,streamFile);
|
|
|
|
if (read_32bitBE(WAVE_size+4,streamFile)-8 != DATA_size) goto fail;
|
2010-09-11 22:57:39 +02:00
|
|
|
|
2011-01-12 02:50:45 +01:00
|
|
|
sample_count = read_32bitBE(0x44,streamFile);
|
|
|
|
|
|
|
|
/* unsure how to detect channel count, so use a hack */
|
|
|
|
channels = (long long)DATA_size / frame_size * frame_samples / sample_count;
|
2010-09-11 22:57:39 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channels,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
|
|
|
start_offset = WAVE_size + 8;
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x40,streamFile);
|
2011-01-12 02:50:45 +01:00
|
|
|
vgmstream->num_samples = sample_count;
|
2010-09-11 22:57:39 +02:00
|
|
|
|
2011-01-12 02:50:45 +01:00
|
|
|
vgmstream->coding_type = coding_BAF_ADPCM;
|
2010-09-11 22:57:39 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
2011-01-12 02:50:45 +01:00
|
|
|
vgmstream->interleave_block_size = frame_size;
|
2010-09-11 22:57:39 +02:00
|
|
|
vgmstream->meta_type = meta_BAF;
|
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
STREAMFILE *file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!file) goto fail;
|
|
|
|
for (i=0;i<channels;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = file;
|
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=start_offset+vgmstream->interleave_block_size*i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|