2010-03-21 05:23:18 +01:00
|
|
|
#include "meta.h"
|
2017-10-14 12:42:44 +02:00
|
|
|
#include "../coding/coding.h"
|
2010-03-21 05:23:18 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
/* BNSF - Namco Bandai's Bandai Namco Sound Format/File */
|
2010-03-21 05:23:18 +01:00
|
|
|
VGMSTREAM * init_vgmstream_bnsf(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2017-10-14 12:42:44 +02:00
|
|
|
off_t start_offset = 0, first_offset = 0x0C;
|
|
|
|
int loop_flag = 0, channel_count = 0;
|
|
|
|
int sample_rate, num_samples, loop_start = 0, loop_end = 0, block_size;
|
|
|
|
uint32_t codec, subcodec = 0;
|
|
|
|
size_t sdat_size;
|
|
|
|
off_t loop_chunk = 0, sfmt_chunk, sdat_chunk;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
|
|
|
|
if (!check_extensions(streamFile,"bnsf"))
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0,streamFile) != 0x424E5346) /* "BNSF" */
|
2010-03-21 05:23:18 +01:00
|
|
|
goto fail;
|
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
codec = read_32bitBE(0x08,streamFile);
|
|
|
|
|
|
|
|
/* check RIFF size (for siren22 it's full size) */
|
|
|
|
if (read_32bitBE(0x04,streamFile) + (codec == 0x49533232 ? 0 : 8) != get_streamfile_size(streamFile))
|
|
|
|
goto fail;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
if (!find_chunk_be(streamFile, 0x73666d74,first_offset,0, &sfmt_chunk,NULL)) /* "sfmt" */
|
|
|
|
goto fail;
|
|
|
|
if (!find_chunk_be(streamFile, 0x73646174,first_offset,0, &sdat_chunk,&sdat_size)) /* "sdat" */
|
|
|
|
goto fail;
|
|
|
|
if ( find_chunk_be(streamFile, 0x6C6F6F70,first_offset,0, &loop_chunk,NULL)) { /* "loop" */
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_start = read_32bitBE(loop_chunk+0x00, streamFile);
|
|
|
|
loop_end = read_32bitBE(loop_chunk+0x04,streamFile);
|
2010-03-21 05:23:18 +01:00
|
|
|
}
|
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
subcodec = read_16bitBE(sfmt_chunk+0x00,streamFile);
|
|
|
|
channel_count = read_16bitBE(sfmt_chunk+0x02,streamFile);
|
|
|
|
sample_rate = read_32bitBE(sfmt_chunk+0x04,streamFile);
|
|
|
|
num_samples = read_32bitBE(sfmt_chunk+0x08,streamFile);
|
|
|
|
/* 0x0c: some kind of sample count (skip?), can be 0 when no loops */
|
|
|
|
block_size = read_16bitBE(sfmt_chunk+0x10,streamFile);
|
|
|
|
//block_samples = read_16bitBE(sfmt_chunk+0x12,streamFile);
|
|
|
|
/* max_samples = sdat_size/block_size*block_samples //num_samples is smaller */
|
2010-03-21 05:23:18 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
start_offset = sdat_chunk;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
2017-10-14 12:42:44 +02:00
|
|
|
vgmstream->num_samples = num_samples;
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
vgmstream->loop_end_sample = loop_end;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
vgmstream->meta_type = meta_BNSF;
|
2010-03-24 21:57:55 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
2010-03-21 05:23:18 +01:00
|
|
|
vgmstream->interleave_block_size = block_size/channel_count;
|
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
/* some IS14 voice files have 0x02 (Tales of Zestiria, The Idolm@ster 2); data looks normal and silent
|
|
|
|
* frames decode ok but rest fails, must be some subtle decoding variation (not encryption) */
|
|
|
|
if (subcodec != 0)
|
|
|
|
goto fail;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
switch (codec) {
|
2010-03-23 21:57:12 +01:00
|
|
|
#ifdef VGM_USE_G7221
|
2017-10-14 12:42:44 +02:00
|
|
|
case 0x49533134: /* "IS14" */
|
|
|
|
vgmstream->coding_type = coding_G7221C;
|
|
|
|
vgmstream->codec_data = init_g7221(vgmstream->channels, vgmstream->interleave_block_size);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
2010-03-23 21:57:12 +01:00
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
break;
|
|
|
|
#endif
|
2015-01-25 06:08:25 +01:00
|
|
|
#ifdef VGM_USE_G719
|
2017-10-14 12:42:44 +02:00
|
|
|
case 0x49533232: /* "IS22" */
|
|
|
|
vgmstream->coding_type = coding_G719;
|
|
|
|
vgmstream->codec_data = init_g719(vgmstream->channels, vgmstream->interleave_block_size);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2015-01-25 06:08:25 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-21 05:23:18 +01:00
|
|
|
|
|
|
|
|
2017-10-14 12:42:44 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2010-03-21 05:23:18 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-10-14 12:42:44 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2010-03-21 05:23:18 +01:00
|
|
|
return NULL;
|
|
|
|
}
|