Skip to content

Commit

Permalink
Merge pull request #416 from bnnm/ads-fsb
Browse files Browse the repository at this point in the history
ads fsb
  • Loading branch information
bnnm committed May 26, 2019
2 parents 78a36e6 + 272a234 commit 50309c1
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/formats.c
Expand Up @@ -73,6 +73,7 @@ static const char* extension_list[] = {
"b1s",
"baf",
"baka",
"bank",
"bar",
"bcstm",
"bcwav",
Expand Down
12 changes: 8 additions & 4 deletions src/libvgmstream.vcproj
Expand Up @@ -608,10 +608,14 @@
RelativePath=".\meta\fsb.c"
>
</File>
<File
RelativePath=".\meta\fsb5.c"
>
</File>
<File
RelativePath=".\meta\fsb5.c"
>
</File>
<File
RelativePath=".\meta\fsb5_fev.c"
>
</File>
<File
RelativePath=".\meta\fsb_encrypted.c"
>
Expand Down
1 change: 1 addition & 0 deletions src/libvgmstream.vcxproj
Expand Up @@ -275,6 +275,7 @@
<ClCompile Include="meta\flx.c" />
<ClCompile Include="meta\fsb.c" />
<ClCompile Include="meta\fsb5.c" />
<ClCompile Include="meta\fsb5_fev.c" />
<ClCompile Include="meta\fsb_encrypted.c" />
<ClCompile Include="meta\gca.c" />
<ClCompile Include="meta\gcsw.c" />
Expand Down
3 changes: 3 additions & 0 deletions src/libvgmstream.vcxproj.filters
Expand Up @@ -391,6 +391,9 @@
<ClCompile Include="meta\fsb5.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\fsb5_fev.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\fsb_encrypted.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
Expand Down
54 changes: 54 additions & 0 deletions src/meta/fsb5_fev.c
@@ -0,0 +1,54 @@
#include "meta.h"
#include "../coding/coding.h"

/* FEV+FSB5 container [Shantae: Half-Genie Hero (Switch)] */
VGMSTREAM * init_vgmstream_fsb5_fev_bank(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
off_t subfile_offset, chunk_offset, first_offset = 0x0c;
size_t subfile_size, chunk_size;


/* checks */
if (!check_extensions(streamFile, "bank"))
goto fail;

if (read_32bitBE(0x00,streamFile) != 0x52494646) /* "RIFF" */
goto fail;
if (read_32bitBE(0x08,streamFile) != 0x46455620) /* "FEV " */
goto fail;

/* .fev is an event format referencing various external .fsb, but FMOD can bake .fev and .fsb to
* form a .bank, which is the format we support here (regular .fev is complex and not very interesting).
* Format is RIFF with FMT (main), LIST (config) and SND (FSB5 data), we want the FSB5 offset inside LIST */
if (!find_chunk_le(streamFile, 0x4C495354,first_offset,0, &chunk_offset,NULL)) /* "LIST" */
goto fail;

if (read_32bitBE(chunk_offset+0x00,streamFile) != 0x50524F4A || /* "PROJ" */
read_32bitBE(chunk_offset+0x04,streamFile) != 0x424E4B49) /* "BNKI" */
goto fail; /* event .fev has "OBCT" instead of "BNKI" */

/* inside BNKI is a bunch of LIST each with event subchunks and finally the fsb offset */
first_offset = chunk_offset + 0x04;
if (!find_chunk_le(streamFile, 0x534E4448,first_offset,0, &chunk_offset,&chunk_size)) /* "SNDH" */
goto fail;

if (chunk_size != 0x0c)
goto fail; /* assuming only one FSB5 is possible */
subfile_offset = read_32bitLE(chunk_offset+0x04,streamFile);
subfile_size = read_32bitLE(chunk_offset+0x08,streamFile);


temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, "fsb");
if (!temp_streamFile) goto fail;

vgmstream = init_vgmstream_fsb5(temp_streamFile);
close_streamfile(temp_streamFile);

return vgmstream;

fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}
2 changes: 2 additions & 0 deletions src/meta/meta.h
Expand Up @@ -852,4 +852,6 @@ VGMSTREAM * init_vgmstream_xwma_konami(STREAMFILE* streamFile);

VGMSTREAM * init_vgmstream_9tav(STREAMFILE* streamFile);

VGMSTREAM * init_vgmstream_fsb5_fev_bank(STREAMFILE * streamFile);

#endif /*_META_H*/
12 changes: 9 additions & 3 deletions src/meta/ps2_ads.c
Expand Up @@ -35,7 +35,7 @@ VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile) {
{
codec = read_32bitLE(0x08,streamFile);
sample_rate = read_32bitLE(0x0C,streamFile);
channel_count = read_32bitLE(0x10,streamFile); /* up to 4 [Eve of Extinction (PS2)]*/
channel_count = read_32bitLE(0x10,streamFile); /* up to 4 [Eve of Extinction (PS2)] */
interleave = read_32bitLE(0x14,streamFile); /* set even when mono */


Expand Down Expand Up @@ -150,7 +150,7 @@ VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile) {
loop_start_sample = loop_start / 2 / channel_count;
is_loop_samples = 1;
}
else if ((loop_start % 0x800 == 0) && loop_start > 0) {/* sector-aligned, min/0 is 0x800 */
else if ((loop_start % 0x800 == 0) && loop_start > 0) { /* sector-aligned, min/0 is 0x800 */
/* cavia games: loop_start is offset [Drakengard 1/2, GITS: Stand Alone Complex] */
/* offset is absolute from the "cavia stream format" container that adjusts ADS start */
loop_flag = 1;
Expand Down Expand Up @@ -192,12 +192,18 @@ VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile) {
loop_start_offset = loop_start * 0x20;
loop_end_offset = loop_end * 0x20;
}
else if (loop_end <= body_size / 0x20 && coding_type == coding_PSX) { /* close to body_size */
else if (loop_end <= body_size / 0x20 && coding_type == coding_PSX) {
/* various games: loops is address * 0x20 [Fire Pro Wrestling Returns, A.C.E. - Another Century's Episode] */
loop_flag = 1;
loop_start_offset = loop_start * 0x20;
loop_end_offset = loop_end * 0x20;
}
else if (loop_end <= body_size / 0x10 && coding_type == coding_PSX
&& (read_32bitBE(0x28 + loop_end*0x10 + 0x10 + 0x00, streamFile) == 0x00077777 ||
read_32bitBE(0x28 + loop_end*0x10 + 0x20 + 0x00, streamFile) == 0x00077777)) {
/* not-quite-looping sfx, ending with a "non-looping PS-ADPCM end frame" [Kono Aozora ni Yakusoku, Chanter] */
loop_flag = 0;
}
else if ((loop_end > body_size / 0x20 && coding_type == coding_PSX) ||
(loop_end > body_size / 0x70 && coding_type == coding_PCM16LE)) {
/* various games: loops in samples [Eve of Extinction, Culdcept, WWE Smackdown! 3] */
Expand Down
1 change: 1 addition & 0 deletions src/vgmstream.c
Expand Up @@ -479,6 +479,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_msf_konami,
init_vgmstream_xwma_konami,
init_vgmstream_9tav,
init_vgmstream_fsb5_fev_bank,

/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */
init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */
Expand Down

0 comments on commit 50309c1

Please sign in to comment.