mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 23:10:10 +01:00
Add FSB5 PCM16BE/VAG/XWMA and improve rare behaviors (from tool tests)
This commit is contained in:
parent
8f17cf75d6
commit
4703dcaf4f
136
src/meta/fsb5.c
136
src/meta/fsb5.c
@ -10,7 +10,7 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
size_t SampleHeaderLength, NameTableLength, SampleDataLength, BaseHeaderLength, StreamSize = 0, ExtraInfoSize = 0;
|
||||
|
||||
uint32_t NumSamples = 0, LoopStart = 0, LoopEnd = 0;
|
||||
int LoopFlag = 0, ChannelCount = 0, Version, SampleRate = 0, CodingID;
|
||||
int LoopFlag = 0, ChannelCount = 0, Version, SampleRate = 0, Codec, Flags = 0;
|
||||
int TotalSubsongs, TargetSubsong = streamFile->stream_index;
|
||||
int i;
|
||||
|
||||
@ -29,17 +29,20 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
SampleHeaderLength = read_32bitLE(0x0C,streamFile);
|
||||
NameTableLength = read_32bitLE(0x10,streamFile);
|
||||
SampleDataLength = read_32bitLE(0x14,streamFile);
|
||||
CodingID = read_32bitLE(0x18,streamFile);
|
||||
/* type 0x01 - 0x1c(8): zero, 0x24(16): hash, 0x34(8): unk
|
||||
* type 0x00 has an extra field (always 0?) at 0x1c */
|
||||
BaseHeaderLength = (Version==0x00) ? 0x40 : 0x3C;
|
||||
Codec = read_32bitLE(0x18,streamFile);
|
||||
/* version 0x01 - 0x1c(4): zero, 0x24(16): hash, 0x34(8): unk
|
||||
* version 0x00 has an extra field (always 0?) at 0x1c */
|
||||
if (Version == 0x01) {
|
||||
Flags = read_32bitLE(0x20,streamFile); /* found by tests and assumed to be flags, no games known */
|
||||
}
|
||||
BaseHeaderLength = (Version==0x00) ? 0x40 : 0x3C;
|
||||
|
||||
if ((SampleHeaderLength + NameTableLength + SampleDataLength + BaseHeaderLength) != get_streamfile_size(streamFile)) {
|
||||
VGM_LOG("FSB5: bad size (%x + %x + %x + %x != %x)\n", SampleHeaderLength, NameTableLength, SampleDataLength, BaseHeaderLength, get_streamfile_size(streamFile));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (TargetSubsong == 0) TargetSubsong = 1; /* default to 1 */
|
||||
if (TargetSubsong == 0) TargetSubsong = 1;
|
||||
if (TargetSubsong > TotalSubsongs || TotalSubsongs <= 0) goto fail;
|
||||
|
||||
SampleHeaderStart = BaseHeaderLength;
|
||||
@ -49,34 +52,34 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
for (i = 1; i <= TotalSubsongs; i++) {
|
||||
off_t DataStart = 0;
|
||||
size_t StreamHeaderLength = 0;
|
||||
uint32_t SampleMode1, SampleMode2;
|
||||
uint32_t SampleMode1, SampleMode2; /* maybe one uint64? */
|
||||
|
||||
|
||||
/* seems ok but could use some testing against FMOD's SDK */
|
||||
SampleMode1 = (uint32_t)read_32bitLE(SampleHeaderStart+0x00,streamFile);
|
||||
SampleMode2 = (uint32_t)read_32bitLE(SampleHeaderStart+0x04,streamFile);
|
||||
StreamHeaderLength += 0x08;
|
||||
|
||||
/* get samples */
|
||||
NumSamples = ((SampleMode2 >> 2) & 0x3FFFFFFF); /* bits 31..2 (30) */
|
||||
NumSamples = ((SampleMode2 >> 2) & 0x3FFFFFFF); /* bits2: 31..2 (30) */
|
||||
|
||||
/* get offset inside data section */
|
||||
DataStart = ((SampleMode1 >> 7) & 0x1FFFFFF) << 5; /* bits 31..8 (25) * 0x20 */
|
||||
//SampleMode2 bits 1..0 part of DataStart for files larger than 0x3FFFFFE0?
|
||||
/* up to 0x07FFFFFF * 0x20 = full 32b offset 0xFFFFFFE0 (recheck, after 0x80000000 some calcs may be off?) */
|
||||
DataStart = ((SampleMode2 & 0x03) << 25) | ((SampleMode1 >> 7) & 0x1FFFFFF) << 5; /* bits2: 1..0 (2) | bits1: 31..8 (25) */
|
||||
|
||||
/* get channels (from tests seems correct, but multichannel isn't very common, ex. no 4ch mode?) */
|
||||
switch ((SampleMode1 >> 5) & 0x03) { /* bits 7..6 (2) */
|
||||
/* get channels */
|
||||
switch ((SampleMode1 >> 5) & 0x03) { /* bits1: 7..6 (2) */
|
||||
case 0: ChannelCount = 1; break;
|
||||
case 1: ChannelCount = 2; break;
|
||||
case 2: ChannelCount = 6; break;/* some Dark Souls 2 MPEG; some IMA ADPCM */
|
||||
case 3: ChannelCount = 8; break;/* some IMA ADPCM */
|
||||
default: /* other values (ex. 10ch) are specified in the extra flags, using 0 here */
|
||||
/* other channels (ex. 4/10/12ch) use 0 here + set extra flags */
|
||||
default: /* not possible */
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* get sample rate */
|
||||
switch ((SampleMode1 >> 1) & 0x0f) { /* bits 5..1 (4) */
|
||||
case 0: SampleRate = 4000; break; //???
|
||||
switch ((SampleMode1 >> 1) & 0x0f) { /* bits1: 5..1 (4) */
|
||||
case 0: SampleRate = 4000; break;
|
||||
case 1: SampleRate = 8000; break;
|
||||
case 2: SampleRate = 11000; break;
|
||||
case 3: SampleRate = 11025; break;
|
||||
@ -86,14 +89,14 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
case 7: SampleRate = 32000; break;
|
||||
case 8: SampleRate = 44100; break;
|
||||
case 9: SampleRate = 48000; break;
|
||||
case 10: SampleRate = 96000; break; //???
|
||||
default: /* probably specified in the extra flags */
|
||||
SampleRate = 44100;
|
||||
break;
|
||||
case 10: SampleRate = 96000; break;
|
||||
/* other sample rates (ex. 3000/64000/192000) use 0 here + set extra flags */
|
||||
default: /* 11-15: rejected (FMOD error) */
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* get extra flags */
|
||||
if (SampleMode1 & 0x01) { /* bit 0 (1) */
|
||||
if (SampleMode1 & 0x01) { /* bits1: 0 (1) */
|
||||
uint32_t ExtraFlag, ExtraFlagStart, ExtraFlagType, ExtraFlagSize, ExtraFlagEnd;
|
||||
|
||||
ExtraFlagStart = SampleHeaderStart+0x08;
|
||||
@ -104,13 +107,13 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
ExtraFlagEnd = (ExtraFlag & 0x01); /* bit 0 (1) */
|
||||
|
||||
switch(ExtraFlagType) {
|
||||
case 0x01: /* Channel Info */
|
||||
case 0x01: /* channels */
|
||||
ChannelCount = read_8bit(ExtraFlagStart+0x04,streamFile);
|
||||
break;
|
||||
case 0x02: /* Sample Rate Info */
|
||||
case 0x02: /* sample rate */
|
||||
SampleRate = read_32bitLE(ExtraFlagStart+0x04,streamFile);
|
||||
break;
|
||||
case 0x03: /* Loop Info */
|
||||
case 0x03: /* loop info */
|
||||
LoopStart = read_32bitLE(ExtraFlagStart+0x04,streamFile);
|
||||
if (ExtraFlagSize > 0x04) /* probably not needed */
|
||||
LoopEnd = read_32bitLE(ExtraFlagStart+0x08,streamFile);
|
||||
@ -126,14 +129,15 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
case 0x06: /* XMA seek table */
|
||||
/* no need for it */
|
||||
break;
|
||||
case 0x07: /* DSP coeffs */
|
||||
case 0x07: /* DSP coefs */
|
||||
ExtraInfoStart = ExtraFlagStart + 0x04;
|
||||
break;
|
||||
case 0x09: /* ATRAC9 config */
|
||||
ExtraInfoStart = ExtraFlagStart + 0x04;
|
||||
ExtraInfoSize = ExtraFlagSize;
|
||||
break;
|
||||
case 0x0a: /* XWMA data */
|
||||
case 0x0a: /* XWMA config */
|
||||
ExtraInfoStart = ExtraFlagStart + 0x04;
|
||||
break;
|
||||
case 0x0b: /* Vorbis setup ID and seek table */
|
||||
ExtraInfoStart = ExtraFlagStart + 0x04;
|
||||
@ -202,7 +206,7 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
|
||||
|
||||
/* parse codec */
|
||||
switch (CodingID) {
|
||||
switch (Codec) {
|
||||
case 0x00: /* FMOD_SOUND_FORMAT_NONE */
|
||||
goto fail;
|
||||
|
||||
@ -212,48 +216,65 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
vgmstream->interleave_block_size = 0x01;
|
||||
break;
|
||||
|
||||
case 0x02: /* FMOD_SOUND_FORMAT_PCM16 */
|
||||
vgmstream->coding_type = coding_PCM16LE;
|
||||
case 0x02: /* FMOD_SOUND_FORMAT_PCM16 [Shantae Risky's Revenge (PC)] */
|
||||
vgmstream->coding_type = (Flags & 0x01) ? coding_PCM16BE : coding_PCM16LE;
|
||||
vgmstream->layout_type = ChannelCount == 1 ? layout_none : layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x02;
|
||||
break;
|
||||
|
||||
case 0x03: /* FMOD_SOUND_FORMAT_PCM24 */
|
||||
goto fail; /* not used */
|
||||
VGM_LOG("FSB5: FMOD_SOUND_FORMAT_PCM24 found\n");
|
||||
goto fail;
|
||||
|
||||
case 0x04: /* FMOD_SOUND_FORMAT_PCM32 */
|
||||
goto fail; /* not used */
|
||||
VGM_LOG("FSB5: FMOD_SOUND_FORMAT_PCM32 found\n");
|
||||
goto fail;
|
||||
|
||||
case 0x05: /* FMOD_SOUND_FORMAT_PCMFLOAT [Anima - Gate of Memories (PC)] */
|
||||
case 0x05: /* FMOD_SOUND_FORMAT_PCMFLOAT [Anima: Gate of Memories (PC)] */
|
||||
vgmstream->coding_type = coding_PCMFLOAT;
|
||||
vgmstream->layout_type = (ChannelCount == 1) ? layout_none : layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x04;
|
||||
break;
|
||||
|
||||
case 0x06: /* FMOD_SOUND_FORMAT_GCADPCM [Sonic Boom - Fire and Ice (3DS)] */
|
||||
vgmstream->coding_type = coding_NGC_DSP_subint;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->interleave_block_size = 0x02;
|
||||
case 0x06: /* FMOD_SOUND_FORMAT_GCADPCM [Sonic Boom: Fire and Ice (3DS)] */
|
||||
if (Flags & 0x02) { /* non-interleaved mode */
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = (StreamSize / ChannelCount);
|
||||
}
|
||||
else {
|
||||
vgmstream->coding_type = coding_NGC_DSP_subint;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->interleave_block_size = 0x02;
|
||||
}
|
||||
|
||||
dsp_read_coefs_be(vgmstream,streamFile,ExtraInfoStart,0x2E);
|
||||
break;
|
||||
|
||||
case 0x07: /* FMOD_SOUND_FORMAT_IMAADPCM */
|
||||
case 0x07: /* FMOD_SOUND_FORMAT_IMAADPCM [Skylanders] */
|
||||
vgmstream->coding_type = (vgmstream->channels > 2) ? coding_FSB_IMA : coding_XBOX_IMA;
|
||||
vgmstream->layout_type = layout_none;
|
||||
break;
|
||||
|
||||
case 0x08: /* FMOD_SOUND_FORMAT_VAG */
|
||||
goto fail; /* not used */
|
||||
case 0x08: /* FMOD_SOUND_FORMAT_VAG [from fsbankex tests, no known games] */
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
if (Flags & 0x02) { /* non-interleaved mode */
|
||||
vgmstream->interleave_block_size = (StreamSize / ChannelCount);
|
||||
}
|
||||
else {
|
||||
vgmstream->interleave_block_size = 0x10;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x09: /* FMOD_SOUND_FORMAT_HEVAG */
|
||||
case 0x09: /* FMOD_SOUND_FORMAT_HEVAG [Guacamelee (Vita)] */
|
||||
vgmstream->coding_type = coding_HEVAG;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x10;
|
||||
break;
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
case 0x0A: {/* FMOD_SOUND_FORMAT_XMA */
|
||||
case 0x0A: {/* FMOD_SOUND_FORMAT_XMA [Dark Souls 2 (X360)] */
|
||||
uint8_t buf[0x100];
|
||||
int bytes, block_size, block_count;
|
||||
|
||||
@ -261,8 +282,6 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
block_count = StreamSize / block_size + (StreamSize % block_size ? 1 : 0);
|
||||
|
||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, vgmstream->num_samples, StreamSize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size);
|
||||
if (bytes <= 0) goto fail;
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, StartOffset,StreamSize);
|
||||
if ( !vgmstream->codec_data ) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
@ -272,7 +291,7 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
#endif
|
||||
|
||||
#ifdef VGM_USE_MPEG
|
||||
case 0x0B: {/* FMOD_SOUND_FORMAT_MPEG */
|
||||
case 0x0B: {/* FMOD_SOUND_FORMAT_MPEG [Final Fantasy X HD (PS3), Shantae Risky's Revenge (PC)] */
|
||||
mpeg_custom_config cfg = {0};
|
||||
|
||||
cfg.fsb_padding = (vgmstream->channels > 2 ? 16 : 4); /* observed default */
|
||||
@ -283,7 +302,8 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case 0x0C: /* FMOD_SOUND_FORMAT_CELT */
|
||||
case 0x0C: /* FMOD_SOUND_FORMAT_CELT [BIT.TRIP Presents Runner2 (PC), Full Bore (PC)] */
|
||||
VGM_LOG("FSB5: FMOD_SOUND_FORMAT_CELT found\n");
|
||||
goto fail;
|
||||
|
||||
#ifdef VGM_USE_ATRAC9
|
||||
@ -317,11 +337,28 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
}
|
||||
#endif
|
||||
|
||||
case 0x0E: /* FMOD_SOUND_FORMAT_XWMA */
|
||||
goto fail;
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
case 0x0E: { /* FMOD_SOUND_FORMAT_XWMA [from fsbankex tests, no known games] */
|
||||
uint8_t buf[0x100];
|
||||
int bytes, format, average_bps, block_align;
|
||||
|
||||
format = read_16bitBE(ExtraInfoStart+0x00,streamFile);
|
||||
block_align = (uint16_t)read_16bitBE(ExtraInfoStart+0x02,streamFile);
|
||||
average_bps = (uint32_t)read_32bitBE(ExtraInfoStart+0x04,streamFile);
|
||||
/* rest: seek entries + mini seek table? */
|
||||
/* XWMA encoder only does up to 6ch (doesn't use FSB multistreams for more) */
|
||||
|
||||
bytes = ffmpeg_make_riff_xwma(buf,0x100, format, StreamSize, vgmstream->channels, vgmstream->sample_rate, average_bps, block_align);
|
||||
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, StartOffset,StreamSize);
|
||||
if ( !vgmstream->codec_data ) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VGM_USE_VORBIS
|
||||
case 0x0F: {/* FMOD_SOUND_FORMAT_VORBIS */
|
||||
case 0x0F: {/* FMOD_SOUND_FORMAT_VORBIS [Shantae Half Genie Hero (PC), Pokemon Go (iOS)] */
|
||||
vorbis_custom_config cfg = {0};
|
||||
|
||||
cfg.channels = vgmstream->channels;
|
||||
@ -337,13 +374,14 @@ VGMSTREAM * init_vgmstream_fsb5(STREAMFILE *streamFile) {
|
||||
}
|
||||
#endif
|
||||
|
||||
case 0x10: /* FMOD_SOUND_FORMAT_FADPCM */
|
||||
case 0x10: /* FMOD_SOUND_FORMAT_FADPCM [Dead Rising 4 (PC), Sine Mora Ex (Switch)] */
|
||||
vgmstream->coding_type = coding_FADPCM;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = 0x8c;
|
||||
break;
|
||||
|
||||
default:
|
||||
VGM_LOG("FSB5: unknown codec %x found\n", Codec);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user