First BFSTM support (needs work for 9+ channels), experimental NSMBU bfwav support

This commit is contained in:
soneek 2014-10-18 17:54:31 -04:00
parent 9a03256df2
commit 52d3f06162
9 changed files with 209 additions and 5 deletions

View File

@ -297,7 +297,9 @@ bool input_vgmstream::g_is_our_path(const char * p_path,const char * p_extension
if(!stricmp_utf8(p_extension,"bar")) return 1;
if(!stricmp_utf8(p_extension,"bcstm")) return 1;
if(!stricmp_utf8(p_extension,"bcwav")) return 1;
if(!stricmp_utf8(p_extension,"bfstm")) return 1;
if(!stricmp_utf8(p_extension,"bfwav")) return 1;
if(!stricmp_utf8(p_extension,"bfwavnsmbu")) return 1;
if(!stricmp_utf8(p_extension,"bg00")) return 1;
if(!stricmp_utf8(p_extension,"bgw")) return 1;
if(!stricmp_utf8(p_extension,"bh2pcm")) return 1;
@ -622,7 +624,9 @@ DECLARE_MULTIPLE_FILE_TYPE("BAF Audio File (*.BAF)", baf);
DECLARE_MULTIPLE_FILE_TYPE("BAR Audio File (*.BAR)", bar);
DECLARE_MULTIPLE_FILE_TYPE("BCSTM Audio File (*.BCSTM)", bcstm);
DECLARE_MULTIPLE_FILE_TYPE("BCWAV Audio File (*.BCWAV)", bcwav);
DECLARE_MULTIPLE_FILE_TYPE("BFSTM Audio File (*.BFSTM)", bfstm);
DECLARE_MULTIPLE_FILE_TYPE("BFWAV Audio File (*.BFWAV)", bfwav);
DECLARE_MULTIPLE_FILE_TYPE("BFWAV Audio File [2] (*.BFWAV)", bfwavnsmbu);
DECLARE_MULTIPLE_FILE_TYPE("BG00 Audio File (*.BG00)", bg00);
DECLARE_MULTIPLE_FILE_TYPE("BGW Audio File (*.BGW)", bgw);
DECLARE_MULTIPLE_FILE_TYPE("BH2PCM Audio File (*.BH2PCM)", bh2pcm);

View File

@ -294,6 +294,7 @@ META_OBJS=meta/adx_header.o \
meta/ps2_vbk.o \
meta/otm.o \
meta/bcstm.o \
meta/bfstm.o \
meta/bfwav.o
OBJECTS=vgmstream.o streamfile.o util.o $(CODING_OBJS) $(LAYOUT_OBJS) $(META_OBJS)

View File

@ -238,7 +238,8 @@ libmeta_la_SOURCES += ps2_2pfs.c
libmeta_la_SOURCES += ubi_ckd.c
libmeta_la_SOURCES += otm.c
libmeta_la_SOURCES += bcstm.c
libmeta_la_SOURCES += bfwav.c
libmeta_la_SOURCES += bfwav.c
libmeta_la_SOURCES += bfstm.c
libmeta_la_SOURCES += ps2_vbk.c
EXTRA_DIST = meta.h

182
src/meta/bfstm.c Normal file
View File

@ -0,0 +1,182 @@
#include "meta.h"
#include "../util.h"
VGMSTREAM * init_vgmstream_bfstm(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[260];
coding_t coding_type;
off_t head_offset;
off_t seek_offset;
off_t data_offset;
int codec_number;
int channel_count;
int loop_flag;
int ima = 0;
off_t start_offset;
/* check extension, case insensitive */
streamFile->get_name(streamFile, filename, sizeof(filename));
if (strcasecmp("bfstm", filename_extension(filename)))
goto fail;
/* check header */
if ((uint32_t)read_32bitBE(0, streamFile) != 0x4653544D) /* "FSTM" */
goto fail;
if ((uint32_t)read_32bitBE(4, streamFile) != 0xFEFF0040)
goto fail;
int founddata = 0;
off_t tempoffset1 = 0x8;
while (!(founddata))
{
if ((uint32_t)read_32bitBE(tempoffset1, streamFile) == 0x40020000)
{
data_offset = read_32bitBE(tempoffset1 + 4, streamFile);
founddata++;
break;
}
tempoffset1++;
}
/* get head offset, check */
head_offset = read_32bitBE(0x18, streamFile);
if ((uint32_t)read_32bitBE(head_offset, streamFile) != 0x494E464F) /* "INFO" */
goto fail;
seek_offset = read_32bitBE(0x24, streamFile);
/* check type details */
codec_number = read_8bit(head_offset + 0x20, streamFile);
loop_flag = read_8bit(head_offset + 0x21, streamFile);
channel_count = read_8bit(head_offset + 0x22, streamFile);
switch (codec_number) {
case 0:
coding_type = coding_PCM8;
break;
case 1:
coding_type = coding_PCM16LE;
break;
case 2:
coding_type = coding_NGC_DSP;
break;
default:
goto fail;
}
if (channel_count < 1) goto fail;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = read_32bitBE(head_offset + 0x2c, streamFile);
vgmstream->sample_rate = (uint16_t)read_16bitBE(head_offset + 0x26, streamFile);
/* channels and loop flag are set by allocate_vgmstream */
if (ima) //Shift the loop points back slightly to avoid stupid pops in some IMA streams due to DC offsetting
{
vgmstream->loop_start_sample = read_32bitBE(head_offset + 0x28, streamFile);
if (vgmstream->loop_start_sample > 10000)
{
vgmstream->loop_start_sample -= 5000;
vgmstream->loop_end_sample = vgmstream->num_samples - 5000;
}
else
vgmstream->loop_end_sample = vgmstream->num_samples;
}
else
{
vgmstream->loop_start_sample = read_32bitBE(head_offset + 0x28, streamFile);
vgmstream->loop_end_sample = vgmstream->num_samples;
}
vgmstream->coding_type = coding_type;
if (channel_count == 1)
vgmstream->layout_type = layout_none;
else
{
if (ima)
vgmstream->layout_type = layout_interleave;
else
vgmstream->layout_type = layout_interleave_shortblock;
}
vgmstream->meta_type = meta_FSTM;
if (ima)
vgmstream->interleave_block_size = 0x200;
else {
vgmstream->interleave_block_size = read_32bitBE(head_offset + 0x34, streamFile);
vgmstream->interleave_smallblock_size = read_32bitBE(head_offset + 0x44, streamFile);
}
if (vgmstream->coding_type == coding_NGC_DSP) {
off_t coef_offset;
off_t tempoffset2 = head_offset;
int foundcoef = 0;
int i, j;
int coef_spacing = 0x2E;
while (!(foundcoef))
{
if ((uint32_t)read_32bitBE(tempoffset2, streamFile) == 0x41020000)
{
coef_offset = read_32bitBE(tempoffset2 + 4, streamFile) + tempoffset2 + (channel_count * 8) - 4 - head_offset;
foundcoef++;
break;
}
tempoffset2++;
}
for (j = 0; j<vgmstream->channels; j++) {
for (i = 0; i<16; i++) {
vgmstream->ch[j].adpcm_coef[i] = read_16bitBE(head_offset + coef_offset + j*coef_spacing + i * 2, streamFile);
}
}
}
if (ima) // No SEEK (ADPC) header, so just start where the SEEK header is supposed to be.
start_offset = seek_offset;
else if (vgmstream->coding_type == coding_NGC_DSP)
start_offset = data_offset + 0x20;
else // No SEEK header and not IMA, so just start after the DATA header
start_offset = 0x120;
/* open the file for reading by each channel */
{
int i;
for (i = 0; i<channel_count; i++) {
if (vgmstream->layout_type == layout_interleave_shortblock)
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
vgmstream->interleave_block_size);
else if (vgmstream->layout_type == layout_interleave)
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
STREAMFILE_DEFAULT_BUFFER_SIZE);
else
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
0x1000);
if (!vgmstream->ch[i].streamfile) goto fail;
vgmstream->ch[i].channel_start_offset =
vgmstream->ch[i].offset =
start_offset + i*vgmstream->interleave_block_size;
}
}
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}

View File

@ -17,6 +17,7 @@ VGMSTREAM * init_vgmstream_bfwav(STREAMFILE *streamFile) {
int big_endian = 1;
int ima = 0;
int nsmbu_flag = 0;
int32_t(*read_32bit)(off_t, STREAMFILE*) = NULL;
int16_t(*read_16bit)(off_t, STREAMFILE*) = NULL;
read_16bit = read_16bitBE;
@ -24,9 +25,11 @@ VGMSTREAM * init_vgmstream_bfwav(STREAMFILE *streamFile) {
/* check extension, case insensitive */
streamFile->get_name(streamFile, filename, sizeof(filename));
if (strcasecmp("bfwav", filename_extension(filename)))
goto fail;
if (strcasecmp("bfwav", filename_extension(filename))) {
if (strcasecmp("bfwavnsmbu",filename_extension(filename))) goto fail;
else nsmbu_flag = 1;
}
/* check header */
if ((uint32_t)read_32bitBE(0, streamFile) != 0x46574156) /* "FWAV" */
goto fail;
@ -75,6 +78,8 @@ VGMSTREAM * init_vgmstream_bfwav(STREAMFILE *streamFile) {
/* fill in the vital statistics */
vgmstream->num_samples = read_32bit(head_offset + 0x14, streamFile);
vgmstream->sample_rate = (uint16_t)read_16bit(head_offset + 0xE, streamFile);
if (nsmbu_flag)
vgmstream->sample_rate /= 2;
/* channels and loop flag are set by allocate_vgmstream */
vgmstream->loop_start_sample = read_32bit(head_offset + 0x10, streamFile);

View File

@ -636,6 +636,8 @@ VGMSTREAM * init_vgmstream_otm(STREAMFILE* streamFile);
VGMSTREAM * init_vgmstream_bcstm(STREAMFILE* streamFile);
VGMSTREAM * init_vgmstream_bfstm(STREAMFILE* streamFile);
VGMSTREAM * init_vgmstream_bfwav(STREAMFILE* streamFile);
#endif

View File

@ -18,6 +18,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
init_vgmstream_adx,
init_vgmstream_brstm,
init_vgmstream_bfwav,
init_vgmstream_bfstm,
init_vgmstream_nds_strm,
init_vgmstream_agsc,
init_vgmstream_ngc_adpdtk,
@ -2192,6 +2193,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
break;
case meta_CWAV:
snprintf(temp,TEMPSIZE,"Nintendo CWAV header");
break;
case meta_FWAV:
snprintf(temp,TEMPSIZE,"Nintendo FWAV header");
break;
case meta_PSX_XA:
snprintf(temp,TEMPSIZE,"RIFF/CDXA header");
@ -3072,6 +3076,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case meta_CSTM:
snprintf(temp,TEMPSIZE,"Nintendo 3DS CSTM Header");
break;
case meta_FSTM:
snprintf(temp,TEMPSIZE,"Nintendo Wii U FSTM Header");
break;
case meta_3DS_IDSP:
snprintf(temp,TEMPSIZE,"Nintendo 3DS IDSP Header");
break;

View File

@ -568,6 +568,7 @@ typedef enum {
meta_PS2_VBK,
meta_OTM, // Otomedius (Arcade)
meta_CSTM, // Nintendo 3DS CSTM
meta_FSTM, // Nintendo Wii U FSTM
meta_3DS_IDSP, // Nintendo 3DS IDSP
#ifdef VGM_USE_MP4V2
meta_MP4,

View File

@ -109,7 +109,8 @@ char * extension_list[] = {
"bcstm\0BCSTM Audio File (*.BCSTM)\0",
"bcwav\0BCWAV (*.BCWAV)\0",
"bdsp\0BDSP Audio File (*.BDSP)\0",
"bfwav\0BFWAV Audio File (*.BFWAV)\0",
"bfstm\0BFSTM Audio File (*.BFSTM)\0",
"bfwav;bfwavnsmbu\0BFWAV Audio File (*.BFWAV)\0",
"bg00\0BG00 Audio File (*.BG00)\0",
"bgw\0BGW Audio File (*.BGW)\0",
"bh2pcm\0BH2PCM Audio File (*.BH2PCM)\0",