From b4fff010dd3706949840b88d162ee6de94da92e2 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 9 Mar 2019 23:27:28 +0100 Subject: [PATCH] Add AAC .strm [Cursed Castilla (3DS)] --- src/formats.c | 1 + src/libvgmstream.vcproj | 4 ++ src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 ++ src/meta/meta.h | 2 + src/meta/strm_abylight.c | 71 ++++++++++++++++++++++++++++++++ src/vgmstream.c | 3 +- src/vgmstream.h | 2 + 8 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/meta/strm_abylight.c diff --git a/src/formats.c b/src/formats.c index a239fd82..ced8d4f6 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1173,6 +1173,7 @@ static const meta_info meta_info_list[] = { {meta_208, "Ocean .208 header"}, {meta_DSP_DS2, "LucasArts .DS2 header"}, {meta_MUS_VC, "Vicious Cycle .MUS header"}, + {meta_STRM_ABYLIGHT, "Abylight STRM header"}, }; diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 82ae649e..99f5e18e 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -1457,6 +1457,10 @@ + + + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index d08c1a6f..ded3ecb1 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -898,6 +898,9 @@ meta\Source Files + + meta\Source Files + meta\Source Files diff --git a/src/meta/meta.h b/src/meta/meta.h index 5bdca2ad..62fcfe8c 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -835,4 +835,6 @@ VGMSTREAM * init_vgmstream_ffdl(STREAMFILE * streamFile); VGMSTREAM * init_vgmstream_mus_vc(STREAMFILE * streamFile); +VGMSTREAM * init_vgmstream_strm_abylight(STREAMFILE * streamFile); + #endif /*_META_H*/ diff --git a/src/meta/strm_abylight.c b/src/meta/strm_abylight.c new file mode 100644 index 00000000..c5f884da --- /dev/null +++ b/src/meta/strm_abylight.c @@ -0,0 +1,71 @@ +#include "meta.h" +#include "../coding/coding.h" + + +/* .STRM - from Abylight 3DS games [Cursed Castilla (3DS)] */ +VGMSTREAM * init_vgmstream_strm_abylight(STREAMFILE *streamFile) { + VGMSTREAM * vgmstream = NULL; + off_t start_offset; + int loop_flag, channel_count, sample_rate; + size_t data_size; + + + /* check extension */ + if ( !check_extensions(streamFile,"strm") ) + goto fail; + + /* check header */ + if (read_32bitBE(0x00,streamFile) != 0x5354524D) /* "STRM" */ + goto fail; + if (read_32bitLE(0x04,streamFile) != 0x03E8) /* version 1000? */ + goto fail; + + loop_flag = 0; + channel_count = 2; /* there are various possible fields but all files are stereo */ + sample_rate = read_32bitLE(0x08,streamFile); + + start_offset = 0x1e; + data_size = read_32bitLE(0x10,streamFile); + if (data_size != get_streamfile_size(streamFile) - start_offset) + goto fail; + if (data_size != read_32bitLE(0x18,streamFile)) + goto fail; + + + /* build the VGMSTREAM */ + vgmstream = allocate_vgmstream(channel_count,loop_flag); + if (!vgmstream) goto fail; + + vgmstream->sample_rate = sample_rate; + vgmstream->num_samples = aac_get_samples(streamFile, start_offset, data_size); + + vgmstream->meta_type = meta_STRM_ABYLIGHT; + +#ifdef VGM_USE_FFMPEG + { + ffmpeg_codec_data *ffmpeg_data = NULL; + + ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset,data_size); + if (!ffmpeg_data) goto fail; + vgmstream->codec_data = ffmpeg_data; + vgmstream->coding_type = coding_FFmpeg; + vgmstream->layout_type = layout_none; + + /* apparently none, or maybe ~600 */ + //if (!ffmpeg_data->skipSamples) + // ffmpeg_set_skip_samples(ffmpeg_data, 1024); + //vgmstream->num_samples -= 1024; + } +#else + goto fail; +#endif + + /* open the file for reading */ + if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) ) + goto fail; + return vgmstream; + +fail: + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/vgmstream.c b/src/vgmstream.c index 3decee66..d95a5108 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -471,6 +471,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = { init_vgmstream_dsp_ds2, init_vgmstream_ffdl, init_vgmstream_mus_vc, + init_vgmstream_strm_abylight, /* 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 */ @@ -569,7 +570,7 @@ static VGMSTREAM * init_vgmstream_internal(STREAMFILE *streamFile) { } /* files can have thousands subsongs, but let's put a limit */ - if (vgmstream->num_streams < 0 || vgmstream->num_streams > 65535) { + if (vgmstream->num_streams < 0 || vgmstream->num_streams > VGMSTREAM_MAX_SUBSONGS) { VGM_LOG("VGMSTREAM: wrong num_streams (ns=%i)\n", vgmstream->num_streams); close_vgmstream(vgmstream); continue; diff --git a/src/vgmstream.h b/src/vgmstream.h index 2abfc545..62eecf05 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -11,6 +11,7 @@ enum { STREAM_NAME_SIZE = 255 }; enum { VGMSTREAM_MAX_CHANNELS = 64 }; enum { VGMSTREAM_MIN_SAMPLE_RATE = 300 }; /* 300 is Wwise min */ enum { VGMSTREAM_MAX_SAMPLE_RATE = 96000 }; +enum { VGMSTREAM_MAX_SUBSONGS = 65535 }; #include "streamfile.h" @@ -725,6 +726,7 @@ typedef enum { meta_208, meta_DSP_DS2, meta_MUS_VC, + meta_STRM_ABYLIGHT, } meta_t;