diff --git a/src/coding/vorbis_custom_utils_vid1.c b/src/coding/vorbis_custom_utils_vid1.c index 6da8c264..327a1f20 100644 --- a/src/coding/vorbis_custom_utils_vid1.c +++ b/src/coding/vorbis_custom_utils_vid1.c @@ -1,9 +1,9 @@ #include "vorbis_custom_decoder.h" +#ifdef VGM_USE_VORBIS #define BITSTREAM_READ_ONLY /* config */ #include "vorbis_bitreader.h" -#ifdef VGM_USE_VORBIS #include diff --git a/src/coding/vorbis_custom_utils_wwise.c b/src/coding/vorbis_custom_utils_wwise.c index cc7dc285..54d4a39f 100644 --- a/src/coding/vorbis_custom_utils_wwise.c +++ b/src/coding/vorbis_custom_utils_wwise.c @@ -1,7 +1,7 @@ #include "vorbis_custom_decoder.h" -#include "vorbis_bitreader.h" #ifdef VGM_USE_VORBIS +#include "vorbis_bitreader.h" #include #define WWISE_VORBIS_USE_PRECOMPILED_WVC 1 /* if enabled vgmstream weights ~150kb more but doesn't need external .wvc packets */ diff --git a/src/meta/ao.c b/src/meta/ao.c index 5c151ff9..44dfae54 100644 --- a/src/meta/ao.c +++ b/src/meta/ao.c @@ -2,18 +2,17 @@ #include "../coding/coding.h" /* .AO - from AlphaOgg lib [Cloudphobia (PC), GEO ~The Sword Millennia~ Kasumi no Tani no Kaibutsu (PC)] */ -VGMSTREAM* init_vgmstream_ao(STREAMFILE *sf) { +VGMSTREAM* init_vgmstream_ao(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; off_t start_offset; /* checks */ - if (!check_extensions(sf,"ao")) - goto fail; if (!is_id64be(0x00,sf, "ALPHAOGG")) goto fail; + if (!check_extensions(sf,"ao")) + goto fail; -#ifdef VGM_USE_VORBIS { ogg_vorbis_meta_info_t ovmi = {0}; int sample_rate = read_u32le(0xF0, sf); /* Ogg header */ @@ -29,9 +28,6 @@ VGMSTREAM* init_vgmstream_ao(STREAMFILE *sf) { start_offset = 0xc8; vgmstream = init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); } -#else - goto fail; -#endif return vgmstream; fail: diff --git a/src/meta/atsl.c b/src/meta/atsl.c index fb12d0fa..c1f27293 100644 --- a/src/meta/atsl.c +++ b/src/meta/atsl.c @@ -10,7 +10,7 @@ VGMSTREAM* init_vgmstream_atsl(STREAMFILE* sf) { int type, big_endian = 0, entries; uint32_t subfile_offset = 0, subfile_size = 0, header_size, entry_size; - VGMSTREAM* (*init_vgmstream)(STREAMFILE* sf) = NULL; + init_vgmstream_t init_vgmstream = NULL; const char* fake_ext; @@ -47,7 +47,6 @@ VGMSTREAM* init_vgmstream_atsl(STREAMFILE* sf) { type = read_u16le(0x0c, sf); switch(type) { -#ifdef VGM_USE_VORBIS case 0x0100: /* KOVS */ init_vgmstream = init_vgmstream_ogg_vorbis; fake_ext = "kvs"; @@ -58,7 +57,6 @@ VGMSTREAM* init_vgmstream_atsl(STREAMFILE* sf) { fake_ext = "kvs"; entry_size = 0x3c; break; -#endif case 0x0200: /* ATRAC3 */ init_vgmstream = init_vgmstream_riff; fake_ext = "at3"; diff --git a/src/meta/encrypted.c b/src/meta/encrypted.c index e27a7658..1ecf8372 100644 --- a/src/meta/encrypted.c +++ b/src/meta/encrypted.c @@ -38,9 +38,8 @@ VGMSTREAM* init_vgmstream_encrypted(STREAMFILE* sf) { temp_sf = setup_ogg_vorbis_streamfile(sf, cfg); if (!temp_sf) goto fail; -#ifdef VGM_USE_VORBIS + vgmstream = init_vgmstream_ogg_vorbis(temp_sf); -#endif close_streamfile(temp_sf); return vgmstream; } diff --git a/src/meta/ffdl.c b/src/meta/ffdl.c index b9440b61..866dbe1a 100644 --- a/src/meta/ffdl.c +++ b/src/meta/ffdl.c @@ -1,97 +1,96 @@ -#include "meta.h" -#include "../coding/coding.h" - - -/* FFDL - Matrix Software wrapper [Final Fantasy Dimensions (Android/iOS)] */ -VGMSTREAM * init_vgmstream_ffdl(STREAMFILE *sf) { - VGMSTREAM * vgmstream = NULL; - STREAMFILE *temp_sf = NULL; - int loop_flag = 0, is_ffdl = 0; - int32_t num_samples = 0, loop_start_sample = 0, loop_end_sample = 0; - off_t start_offset; - size_t file_size; - - - /* checks */ - /* .ogg/logg: probable extension for Android - * .mp4/lmp4: probable extension for iOS - * .bin: iOS FFDL extension - * (extensionless): for FFDL files without names in Android .obb bigfile */ - if (!check_extensions(sf, "ogg,logg,mp4,lmp4,bin,")) - goto fail; - - /* "FFDL" is a wrapper used in all of the game's files, that may contain standard - * Ogg/MP4 or "mtxs" w/ loops + Ogg/MP4, and may concatenate multiple of them - * (without size in sight), so they should be split externally first. */ - - start_offset = 0x00; - - /* may start with wrapper (not split) */ - if (read_u32be(0x00,sf) == 0x4646444C) { /* "FFDL" */ - is_ffdl = 1; - start_offset += 0x04; - } - - /* may start with sample info (split) or after "FFDL" */ - if (read_u32be(start_offset+0x00,sf) == 0x6D747873) { /* "mtxs" */ - is_ffdl = 1; - - num_samples = read_s32le(start_offset + 0x04,sf); - loop_start_sample = read_s32le(start_offset + 0x08,sf); - loop_end_sample = read_s32le(start_offset + 0x0c,sf); - loop_flag = !(loop_start_sample==0 && loop_end_sample==num_samples); - - start_offset += 0x10; - } - - /* don't parse regular files */ - if (!is_ffdl) - goto fail; - - file_size = get_streamfile_size(sf) - start_offset; - - if (read_u32be(start_offset + 0x00,sf) == 0x4F676753) { /* "OggS" */ -#ifdef VGM_USE_VORBIS - temp_sf = setup_subfile_streamfile(sf, start_offset, file_size, "ogg"); - if (!temp_sf) goto fail; - - vgmstream = init_vgmstream_ogg_vorbis(temp_sf); - if (!vgmstream) goto fail; -#else - goto fail; -#endif - } - else if (read_u32be(start_offset + 0x04,sf) == 0x66747970) { /* "ftyp" after atom size */ -#ifdef VGM_USE_FFMPEG - temp_sf = setup_subfile_streamfile(sf, start_offset, file_size, "mp4"); - if (!temp_sf) goto fail; - - vgmstream = init_vgmstream_mp4_aac_ffmpeg(temp_sf); - if (!vgmstream) goto fail; -#else - goto fail; -#endif - } - else { - goto fail; - } - - /* install loops */ - if (loop_flag) { - /* num_samples is erratic (can be bigger = padded, or smaller = cut; doesn't matter for looping though) */ - //;VGM_ASSERT(vgmstream->num_samples != num_samples, - // "FFDL: mtxs samples = %i vs num_samples = %i\n", num_samples, vgmstream->num_samples); - //vgmstream->num_samples = num_samples; - - /* loop samples are within num_samples, and don't have encoder delay (loop_start=0 starts from encoder_delay) */ - vgmstream_force_loop(vgmstream, 1, loop_start_sample, loop_end_sample); - } - - close_streamfile(temp_sf); - return vgmstream; - -fail: - close_streamfile(temp_sf); - close_vgmstream(vgmstream); - return NULL; -} +#include "meta.h" +#include "../coding/coding.h" + + +/* FFDL - Matrix Software wrapper [Final Fantasy Dimensions (Android/iOS)] */ +VGMSTREAM* init_vgmstream_ffdl(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + STREAMFILE* temp_sf = NULL; + int loop_flag = 0, is_ffdl = 0; + int32_t num_samples = 0, loop_start_sample = 0, loop_end_sample = 0; + off_t start_offset; + size_t file_size; + + + /* checks */ + if (!is_id32be(0x00,sf, "FFDL") && + !is_id32be(0x00,sf, "mtxs")) + goto fail; + + /* .ogg/logg: probable extension for Android + * .mp4/lmp4: probable extension for iOS + * .bin: iOS FFDL extension + * (extensionless): for FFDL files without names in Android .obb bigfile */ + if (!check_extensions(sf, "ogg,logg,mp4,lmp4,bin,")) + goto fail; + + /* "FFDL" is a wrapper used in all of the game's files, that may contain standard + * Ogg/MP4 or "mtxs" w/ loops + Ogg/MP4, and may concatenate multiple of them + * (without size in sight), so they should be split externally first. */ + + /* may start with wrapper (not split) */ + start_offset = 0x00; + if (is_id32be(0x00,sf, "FFDL")) { + is_ffdl = 1; + start_offset += 0x04; + } + + /* may start with sample info (split) or after "FFDL" */ + if (is_id32be(start_offset+0x00,sf, "mtxs")) { + is_ffdl = 1; + + num_samples = read_s32le(start_offset + 0x04,sf); + loop_start_sample = read_s32le(start_offset + 0x08,sf); + loop_end_sample = read_s32le(start_offset + 0x0c,sf); + loop_flag = !(loop_start_sample==0 && loop_end_sample==num_samples); + + start_offset += 0x10; + } + + /* don't parse regular files */ + if (!is_ffdl) + goto fail; + + file_size = get_streamfile_size(sf) - start_offset; + + if (read_u32be(start_offset + 0x00,sf) == 0x4F676753) { /* "OggS" */ + temp_sf = setup_subfile_streamfile(sf, start_offset, file_size, "ogg"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_ogg_vorbis(temp_sf); + if (!vgmstream) goto fail; + } + else if (read_u32be(start_offset + 0x04,sf) == 0x66747970) { /* "ftyp" after atom size */ +#ifdef VGM_USE_FFMPEG + temp_sf = setup_subfile_streamfile(sf, start_offset, file_size, "mp4"); + if (!temp_sf) goto fail; + + vgmstream = init_vgmstream_mp4_aac_ffmpeg(temp_sf); + if (!vgmstream) goto fail; +#else + goto fail; +#endif + } + else { + goto fail; + } + + /* install loops */ + if (loop_flag) { + /* num_samples is erratic (can be bigger = padded, or smaller = cut; doesn't matter for looping though) */ + //;VGM_ASSERT(vgmstream->num_samples != num_samples, + // "FFDL: mtxs samples = %i vs num_samples = %i\n", num_samples, vgmstream->num_samples); + //vgmstream->num_samples = num_samples; + + /* loop samples are within num_samples, and don't have encoder delay (loop_start=0 starts from encoder_delay) */ + vgmstream_force_loop(vgmstream, 1, loop_start_sample, loop_end_sample); + } + + close_streamfile(temp_sf); + return vgmstream; + +fail: + close_streamfile(temp_sf); + close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/his.c b/src/meta/his.c index e9b9fdcd..3034db0e 100644 --- a/src/meta/his.c +++ b/src/meta/his.c @@ -5,47 +5,50 @@ /* HIS - Her Interactive games [Nancy Drew series (PC)] */ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) { VGMSTREAM * vgmstream = NULL; - int channel_count, loop_flag = 0, bps, sample_rate, num_samples, version; + int channels, loop_flag = 0, bps, sample_rate, num_samples, version; off_t start_offset; /* checks */ + if (!is_id32be(0x00,sf, "Her ") && + !is_id32be(0x00,sf, "HIS\0")) + goto fail; if (!check_extensions(sf, "his")) goto fail; - if (read_32bitBE(0x00,sf) == 0x48657220) { /* "Her Interactive Sound\x1a" */ + if (is_id32be(0x00,sf, "Her ")) { /* "Her Interactive Sound\x1a" */ /* Nancy Drew: Secrets Can Kill (PC) */ version = 0; - channel_count = read_16bitLE(0x16,sf); - sample_rate = read_32bitLE(0x18,sf); + channels = read_u16le(0x16,sf); + sample_rate = read_u32le(0x18,sf); /* 0x1c: bitrate */ /* 0x20: block size */ - bps = read_16bitLE(0x22,sf); + bps = read_u16le(0x22,sf); - if (read_32bitBE(0x24,sf) != 0x64617461) /* "data" */ + if (!is_id32be(0x24,sf, "data")) goto fail; - num_samples = pcm_bytes_to_samples(read_32bitLE(0x28,sf), channel_count, bps); + num_samples = pcm_bytes_to_samples(read_u32le(0x28,sf), channels, bps); start_offset = 0x2c; } - else if (read_32bitBE(0x00,sf) == 0x48495300) { /* HIS\0 */ + else if (is_id32be(0x00,sf, "HIS\0")) { /* most(?) others */ - version = read_32bitLE(0x04,sf); + version = read_u32le(0x04,sf); /* 0x08: codec */ - channel_count = read_16bitLE(0x0a,sf); - sample_rate = read_32bitLE(0x0c,sf); + channels = read_u16le(0x0a,sf); + sample_rate = read_u32le(0x0c,sf); /* 0x10: bitrate */ /* 0x14: block size */ - bps = read_16bitLE(0x16,sf); + bps = read_u16le(0x16,sf); - num_samples = pcm_bytes_to_samples(read_32bitLE(0x18,sf), channel_count, bps); /* true even for Ogg */ + num_samples = pcm_bytes_to_samples(read_u32le(0x18,sf), channels, bps); /* true even for Ogg */ /* later games use "OggS" */ if (version == 1) start_offset = 0x1c; /* Nancy Drew: The Final Scene (PC) */ - else if (version == 2 && read_32bitBE(0x1e,sf) == 0x4F676753) + else if (version == 2 && is_id32be(0x1e,sf, "OggS")) start_offset = 0x1e; /* Nancy Drew: The Haunted Carousel (PC) */ - else if (version == 2 && read_32bitBE(0x20,sf) == 0x4F676753) + else if (version == 2 && is_id32be(0x20,sf, "OggS")) start_offset = 0x20; /* Nancy Drew: The Silent Spy (PC) */ else goto fail; @@ -56,18 +59,14 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) { if (version == 2) { -#ifdef VGM_USE_VORBIS ogg_vorbis_meta_info_t ovmi = {0}; ovmi.meta_type = meta_HIS; return init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); -#else - goto fail; -#endif } /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; vgmstream->meta_type = meta_HIS; @@ -89,7 +88,7 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) { goto fail; } - if (!vgmstream_open_stream(vgmstream,sf,start_offset)) + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) goto fail; return vgmstream; diff --git a/src/meta/ikm.c b/src/meta/ikm.c index 57962d15..f73db803 100644 --- a/src/meta/ikm.c +++ b/src/meta/ikm.c @@ -10,14 +10,14 @@ VGMSTREAM* init_vgmstream_ikm_ps2(STREAMFILE* sf) { /* checks */ - if ( !check_extensions(sf,"ikm") ) + if (!is_id32be(0x00,sf, "IKM\0")) goto fail; - if (read_u32be(0x00,sf) != 0x494B4D00) /* "IKM\0" */ + if (!check_extensions(sf,"ikm")) goto fail; - if (read_u32be(0x40,sf) != 0x41535400) /* "AST\0" */ - goto fail; /* 0x20: type 03? */ + if (!is_id32be(0x40,sf, "AST\0")) + goto fail; loop_flag = (read_s32le(0x14, sf) > 0); channel_count = read_s32le(0x50, sf); @@ -53,23 +53,24 @@ VGMSTREAM* init_vgmstream_ikm_pc(STREAMFILE* sf) { /* checks */ - if ( !check_extensions(sf,"ikm") ) + if (!is_id32be(0x00,sf, "IKM\0")) goto fail; - if (read_u32be(0x00,sf) != 0x494B4D00) /* "IKM\0" */ + if (!check_extensions(sf,"ikm")) goto fail; /* 0x20: type 01? */ /* find "OggS" start */ - if (read_u32be(0x30,sf) == 0x4F676753) { + if (is_id32be(0x30,sf, "OggS")) { start_offset = 0x30; /* Chaos Legion (PC) */ - } else if (read_u32be(0x800,sf) == 0x4F676753) { + } + else if (is_id32be(0x800,sf, "OggS")) { start_offset = 0x800; /* Legend of Galactic Heroes (PC) */ - } else { + } + else { goto fail; } -#ifdef VGM_USE_VORBIS { ogg_vorbis_meta_info_t ovmi = {0}; @@ -82,9 +83,6 @@ VGMSTREAM* init_vgmstream_ikm_pc(STREAMFILE* sf) { vgmstream = init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); } -#else - goto fail; -#endif return vgmstream; @@ -102,13 +100,14 @@ VGMSTREAM* init_vgmstream_ikm_psp(STREAMFILE* sf) { /* checks */ + if (!is_id32be(0x00,sf, "IKM\0")) + goto fail; if (!check_extensions(sf,"ikm")) goto fail; - if (read_u32be(0x00,sf) != 0x494B4D00) /* "IKM\0" */ - goto fail; - if (read_u32be(0x800,sf) != 0x52494646) /* "RIFF" */ - goto fail; + /* 0x20: type 00? */ + if (!is_id32be(0x800,sf, "RIFF")) + goto fail; /* loop values (pre-adjusted without encoder delay) at 0x14/18 are found in the RIFF too */ data_size = read_s32le(0x24, sf); diff --git a/src/meta/meta.h b/src/meta/meta.h index 807a6d75..32d354d9 100644 --- a/src/meta/meta.h +++ b/src/meta/meta.h @@ -3,6 +3,8 @@ #include "../vgmstream.h" +typedef VGMSTREAM* (*init_vgmstream_t)(STREAMFILE* sf); + VGMSTREAM* init_vgmstream_silence(int channels, int sample_rate, int32_t num_samples); VGMSTREAM* init_vgmstream_silence_container(int total_subsongs); @@ -116,8 +118,7 @@ VGMSTREAM * init_vgmstream_vpk(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile); -#ifdef VGM_USE_VORBIS -VGMSTREAM * init_vgmstream_ogg_vorbis(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_ogg_vorbis(STREAMFILE* sf); typedef struct { int loop_flag; @@ -142,16 +143,15 @@ typedef struct { } ogg_vorbis_meta_info_t; -VGMSTREAM* init_vgmstream_ogg_vorbis_config(STREAMFILE *sf, off_t start, const ogg_vorbis_meta_info_t* ovmi); -#endif +VGMSTREAM* init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi); -VGMSTREAM * init_vgmstream_hca(STREAMFILE *streamFile); -VGMSTREAM * init_vgmstream_hca_subkey(STREAMFILE *streamFile, uint16_t subkey); +VGMSTREAM* init_vgmstream_hca(STREAMFILE* sf); +VGMSTREAM* init_vgmstream_hca_subkey(STREAMFILE* sf, uint16_t subkey); #ifdef VGM_USE_FFMPEG -VGMSTREAM * init_vgmstream_ffmpeg(STREAMFILE *streamFile); +VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf); -VGMSTREAM * init_vgmstream_mp4_aac_ffmpeg(STREAMFILE * streamFile); +VGMSTREAM* init_vgmstream_mp4_aac_ffmpeg(STREAMFILE* sf); #endif #if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC) diff --git a/src/meta/mogg.c b/src/meta/mogg.c index 40be9d99..e08e9866 100644 --- a/src/meta/mogg.c +++ b/src/meta/mogg.c @@ -1,39 +1,27 @@ -/* -2017-12-10: Preliminary MOGG Support. As long as the stream is unencrypted, this should be fine. - This will also work on unconventional 5 channel Vorbis streams but some sound cards might not like it. - TODO (Eventually): Add decryption for encrypted MOGG types (Rock Band, etc.) - - -bxaimc -*/ - #include "meta.h" #include "../coding/coding.h" -/* MOGG - Harmonix Music Systems (Guitar Hero)[Unencrypted Type] */ -VGMSTREAM* init_vgmstream_mogg(STREAMFILE *sf) { -#ifdef VGM_USE_VORBIS +/* MOGG - Harmonix Music Systems's Ogg (unencrypted type) [Guitar Hero II (X360)] */ +VGMSTREAM* init_vgmstream_mogg(STREAMFILE* sf) { off_t start_offset; + /* checks */ + if (read_u32le(0x00, sf) != 0x0A) /* type? */ + goto fail; + if (!check_extensions(sf, "mogg")) goto fail; { ogg_vorbis_meta_info_t ovmi = {0}; - VGMSTREAM * result = NULL; ovmi.meta_type = meta_MOGG; - start_offset = read_32bitLE(0x04, sf); - result = init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); - - if (result != NULL) { - return result; - } + start_offset = read_u32le(0x04, sf); + return init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); } fail: - /* clean up anything we may have opened */ -#endif return NULL; } diff --git a/src/meta/mups.c b/src/meta/mups.c index fbfa5c65..53f13549 100644 --- a/src/meta/mups.c +++ b/src/meta/mups.c @@ -6,30 +6,27 @@ /* MUPS - from Watermelon/HUCARD games (same programmer) [Pier Solar and the Great Architects (PC), Ghost Blade HD (PC/Switch)] */ VGMSTREAM* init_vgmstream_mups(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; - STREAMFILE *temp_sf = NULL; + STREAMFILE* temp_sf = NULL; /* checks */ + if (!is_id32be(0x00,sf, "MUPS")) + goto fail; + /* mups: header id? * (extensionless): default? */ if (!check_extensions(sf, "mups,")) goto fail; - if (read_u32be(0x00,sf) != 0x4D555053) /* "MUPS" */ - goto fail; - if (read_u32be(0x08,sf) != 0x50737348) /* "PssH" */ + if (!is_id32be(0x08,sf, "PssH")) goto fail; /* just an Ogg with changed OggS/vorbis words (see streamfile) */ temp_sf = setup_mups_streamfile(sf, 0x08); if (!temp_sf) goto fail; -#ifdef VGM_USE_VORBIS vgmstream = init_vgmstream_ogg_vorbis(temp_sf); if (!vgmstream) goto fail; -#else - goto fail; -#endif close_streamfile(temp_sf); diff --git a/src/meta/mus_acm.c b/src/meta/mus_acm.c index 03c50233..68704556 100644 --- a/src/meta/mus_acm.c +++ b/src/meta/mus_acm.c @@ -11,11 +11,11 @@ #endif -static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_loop_flag, int *out_loop_start_index, int *out_loop_end_index); +static char** parse_mus(STREAMFILE* sf, int *out_file_count, int *out_loop_flag, int *out_loop_start_index, int *out_loop_end_index); static void clean_mus(char** mus_filenames, int file_count); /* .MUS - playlist for InterPlay games [Planescape: Torment (PC), Baldur's Gate Enhanced Edition (PC)] */ -VGMSTREAM * init_vgmstream_mus_acm(STREAMFILE *streamFile) { +VGMSTREAM* init_vgmstream_mus_acm(STREAMFILE* sf) { VGMSTREAM * vgmstream = NULL; segmented_layout_data *data = NULL; @@ -27,11 +27,11 @@ VGMSTREAM * init_vgmstream_mus_acm(STREAMFILE *streamFile) { /* checks */ - if (!check_extensions(streamFile, "mus")) + if (!check_extensions(sf, "mus")) goto fail; /* get file paths from the .MUS text file */ - mus_filenames = parse_mus(streamFile, &segment_count, &loop_flag, &loop_start_index, &loop_end_index); + mus_filenames = parse_mus(sf, &segment_count, &loop_flag, &loop_start_index, &loop_end_index); if (!mus_filenames) goto fail; /* init layout */ @@ -40,24 +40,22 @@ VGMSTREAM * init_vgmstream_mus_acm(STREAMFILE *streamFile) { /* open each segment subfile */ for (i = 0; i < segment_count; i++) { - STREAMFILE* temp_streamFile = streamFile->open(streamFile, mus_filenames[i], STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!temp_streamFile) goto fail; + STREAMFILE* temp_sf = sf->open(sf, mus_filenames[i], STREAMFILE_DEFAULT_BUFFER_SIZE); + if (!temp_sf) goto fail; /* find .ACM type */ - switch(read_32bitBE(0x00,temp_streamFile)) { + switch(read_32bitBE(0x00,temp_sf)) { case 0x97280301: /* ACM header id [Planescape: Torment (PC)] */ - data->segments[i] = init_vgmstream_acm(temp_streamFile); + data->segments[i] = init_vgmstream_acm(temp_sf); break; -#ifdef VGM_USE_VORBIS case 0x4F676753: /* "OggS" [Planescape: Torment Enhanced Edition (PC)] */ - data->segments[i] = init_vgmstream_ogg_vorbis(temp_streamFile); + data->segments[i] = init_vgmstream_ogg_vorbis(temp_sf); break; -#endif default: data->segments[i] = NULL; break; } - close_streamfile(temp_streamFile); + close_streamfile(temp_sf); if (!data->segments[i]) goto fail; @@ -184,7 +182,7 @@ fail: return 1; } -static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_loop_flag, int *out_loop_start_index, int *out_loop_end_index) { +static char** parse_mus(STREAMFILE *sf, int *out_file_count, int *out_loop_flag, int *out_loop_start_index, int *out_loop_end_index) { char** names = NULL; char filename[NAME_LENGTH]; @@ -204,7 +202,7 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo /* read file name base */ - bytes_read = read_line(line, sizeof(line), mus_offset, streamFile, &line_ok); + bytes_read = read_line(line, sizeof(line), mus_offset, sf, &line_ok); if (!line_ok) goto fail; mus_offset += bytes_read; memcpy(name_base,line,sizeof(name_base)); @@ -217,7 +215,7 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo } /* read track entry count */ - bytes_read = read_line(line, sizeof(line), mus_offset, streamFile, &line_ok); + bytes_read = read_line(line, sizeof(line), mus_offset, sf, &line_ok); if (!line_ok) goto fail; if (line[0] == '\0') goto fail; mus_offset += bytes_read; @@ -235,7 +233,7 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo } dir_name[0]='\0'; - streamFile->get_name(streamFile,filename,sizeof(filename)); + sf->get_name(sf,filename,sizeof(filename)); concatn(sizeof(dir_name),dir_name,filename); /* find directory name for the directory contianing the MUS */ @@ -262,7 +260,7 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo for (i = 0; i < file_count; i++) { int fields_matched; - bytes_read = read_line(line,sizeof(line), mus_offset, streamFile, &line_ok); + bytes_read = read_line(line,sizeof(line), mus_offset, sf, &line_ok); if (!line_ok) goto fail; mus_offset += bytes_read; @@ -308,13 +306,13 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo concatn(NAME_LENGTH,names[i],name); concatn(NAME_LENGTH,names[i],".ACM"); - if (!exists(names[i],streamFile)) { + if (!exists(names[i],sf)) { /* We can't test for the directory until we have a file name * to look for, so we do it here with the first file that seems to * be in a subdirectory */ if (subdir_name[0]=='\0') { - if (find_directory_name(name_base, dir_name, sizeof(subdir_name), subdir_name, name, filename, streamFile)) + if (find_directory_name(name_base, dir_name, sizeof(subdir_name), subdir_name, name, filename, sf)) goto fail; } @@ -325,7 +323,7 @@ static char** parse_mus(STREAMFILE *streamFile, int *out_file_count, int *out_lo concatn(NAME_LENGTH,names[i],name); concatn(NAME_LENGTH,names[i],".ACM"); - if (!exists(names[i],streamFile)) goto fail; + if (!exists(names[i],sf)) goto fail; } } diff --git a/src/meta/nwav.c b/src/meta/nwav.c index a9557722..62855a0d 100644 --- a/src/meta/nwav.c +++ b/src/meta/nwav.c @@ -2,37 +2,35 @@ #include "../coding/coding.h" /* NWAV - from Chunsoft games [Fuurai no Shiren Gaiden: Onnakenshi Asuka Kenzan! (PC)] */ -VGMSTREAM * init_vgmstream_nwav(STREAMFILE *sf) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_nwav(STREAMFILE* sf) { off_t start_offset; /* checks */ + if (!is_id32be(0x00,sf, "NWAV")) + goto fail; /* .nwav: header id (no filenames in bigfiles) */ - if ( !check_extensions(sf,"nwav") ) - goto fail; - if (read_32bitBE(0x00,sf) != 0x4E574156) /* "NWAV" */ + if (!check_extensions(sf,"nwav,") ) goto fail; -#ifdef VGM_USE_VORBIS { ogg_vorbis_meta_info_t ovmi = {0}; int channels; /* 0x04: version? */ /* 0x08: crc? */ - ovmi.stream_size = read_32bitLE(0x0c, sf); - ovmi.loop_end = read_32bitLE(0x10, sf); /* num_samples, actually */ + ovmi.stream_size = read_u32le(0x0c, sf); + ovmi.loop_end = read_u32le(0x10, sf); /* num_samples, actually */ /* 0x14: sample rate */ /* 0x18: bps? (16) */ - channels = read_8bit(0x19, sf); - start_offset = read_16bitLE(0x1a, sf); + channels = read_u8(0x19, sf); + start_offset = read_u16le(0x1a, sf); - ovmi.loop_flag = read_16bitLE(0x1c, sf) != 0; /* loop count? -1 = loops */ + ovmi.loop_flag = read_u16le(0x1c, sf) != 0; /* loop count? -1 = loops */ /* 0x1e: always 2? */ /* 0x20: always 1? */ - ovmi.loop_start = read_32bitLE(0x24, sf); + ovmi.loop_start = read_u32le(0x24, sf); /* 0x28: always 1? */ /* 0x2a: always 1? */ /* 0x2c: always null? */ @@ -43,15 +41,9 @@ VGMSTREAM * init_vgmstream_nwav(STREAMFILE *sf) { ovmi.loop_start = ovmi.loop_start / sizeof(int16_t) / channels; ovmi.loop_end = ovmi.loop_end / sizeof(int16_t) / channels; - vgmstream = init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); + return init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi); } -#else - goto fail; -#endif - - return vgmstream; fail: - close_vgmstream(vgmstream); return NULL; } diff --git a/src/meta/ogg_vorbis.c b/src/meta/ogg_vorbis.c index beb13415..fea8a905 100644 --- a/src/meta/ogg_vorbis.c +++ b/src/meta/ogg_vorbis.c @@ -1,4 +1,3 @@ -#ifdef VGM_USE_VORBIS #include #include #include "meta.h" @@ -6,6 +5,28 @@ #include "ogg_vorbis_streamfile.h" +#ifdef VGM_USE_VORBIS +static VGMSTREAM* _init_vgmstream_ogg_vorbis(STREAMFILE* sf); +static VGMSTREAM* _init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi); +#endif + +VGMSTREAM* init_vgmstream_ogg_vorbis(STREAMFILE* sf) { +#ifdef VGM_USE_VORBIS + return _init_vgmstream_ogg_vorbis(sf); +#else + return NULL; +#endif +} + +VGMSTREAM* init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi) { +#ifdef VGM_USE_VORBIS + return _init_vgmstream_ogg_vorbis_config(sf, start, ovmi); +#else + return NULL; +#endif +} + +#ifdef VGM_USE_VORBIS static void um3_ogg_decryption_callback(void* ptr, size_t size, size_t nmemb, void* datasource) { uint8_t *ptr8 = ptr; size_t bytes_read = size * nmemb; @@ -110,8 +131,8 @@ static const uint32_t xiph_mappings[] = { }; -/* Ogg Vorbis, may contain loop comments */ -VGMSTREAM* init_vgmstream_ogg_vorbis(STREAMFILE* sf) { +/* Ogg Vorbis - standard .ogg with (possibly) loop comments/metadata */ +static VGMSTREAM* _init_vgmstream_ogg_vorbis(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; STREAMFILE* temp_sf = NULL; ogg_vorbis_io_config_data cfg = {0}; @@ -416,7 +437,7 @@ VGMSTREAM* init_vgmstream_ogg_vorbis(STREAMFILE* sf) { ovmi.meta_type = meta_OGG_VORBIS; } - vgmstream = init_vgmstream_ogg_vorbis_config(temp_sf != NULL ? temp_sf : sf, start_offset, &ovmi); + vgmstream = _init_vgmstream_ogg_vorbis_config(temp_sf != NULL ? temp_sf : sf, start_offset, &ovmi); close_streamfile(temp_sf); return vgmstream; @@ -426,7 +447,7 @@ fail: return NULL; } -VGMSTREAM* init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi) { +static VGMSTREAM* _init_vgmstream_ogg_vorbis_config(STREAMFILE* sf, off_t start, const ogg_vorbis_meta_info_t* ovmi) { VGMSTREAM* vgmstream = NULL; ogg_vorbis_codec_data* data = NULL; ogg_vorbis_io io = {0}; diff --git a/src/meta/ogv_3rdeye.c b/src/meta/ogv_3rdeye.c index 553d5109..20f3be37 100644 --- a/src/meta/ogv_3rdeye.c +++ b/src/meta/ogv_3rdeye.c @@ -3,15 +3,14 @@ /* OGV - .ogg container (not related to ogv video) [Bloody Rondo (PC)] */ VGMSTREAM* init_vgmstream_ogv_3rdeye(STREAMFILE* sf) { - VGMSTREAM* vgmstream = NULL; - off_t subfile_offset, subfile_size; + uint32_t subfile_offset, subfile_size; /* checks */ - if (!check_extensions(sf,"ogv")) - goto fail; if (!is_id32be(0x00,sf, "OGV\0")) goto fail; + if (!check_extensions(sf,"ogv")) + goto fail; /* 0x04: PCM size */ subfile_size = read_u32le(0x08, sf); @@ -20,21 +19,15 @@ VGMSTREAM* init_vgmstream_ogv_3rdeye(STREAMFILE* sf) { /* no loops (files bgm does full loops but sfx doesn't) */ -#ifdef VGM_USE_VORBIS { ogg_vorbis_meta_info_t ovmi = {0}; ovmi.meta_type = meta_OGV_3RDEYE; ovmi.stream_size = subfile_size; - vgmstream = init_vgmstream_ogg_vorbis_config(sf, subfile_offset, &ovmi); + return init_vgmstream_ogg_vorbis_config(sf, subfile_offset, &ovmi); } -#else - goto fail; -#endif - return vgmstream; fail: - close_vgmstream(vgmstream); return NULL; } diff --git a/src/meta/psb.c b/src/meta/psb.c index d6bf160d..37bb9b9f 100644 --- a/src/meta/psb.c +++ b/src/meta/psb.c @@ -292,8 +292,6 @@ fail: } -typedef VGMSTREAM* (*init_vgmstream_t)(STREAMFILE* sf); - static VGMSTREAM* try_init_vgmstream(STREAMFILE* sf, init_vgmstream_t init_vgmstream, const char* extension, uint32_t offset, uint32_t size) { STREAMFILE* temp_sf = NULL; VGMSTREAM* v = NULL; diff --git a/src/meta/sps_n1.c b/src/meta/sps_n1.c index 7a55020d..eed3d11c 100644 --- a/src/meta/sps_n1.c +++ b/src/meta/sps_n1.c @@ -12,8 +12,8 @@ VGMSTREAM* init_vgmstream_sps_n1(STREAMFILE* sf) { off_t subfile_offset; size_t subfile_size; - VGMSTREAM* (*init_vgmstream_subfile)(STREAMFILE*) = NULL; - const char* extension; + init_vgmstream_t init_vgmstream = NULL; + const char* extension = NULL; uint32_t (*read_u32)(off_t,STREAMFILE*); uint16_t (*read_u16)(off_t,STREAMFILE*); @@ -38,12 +38,12 @@ VGMSTREAM* init_vgmstream_sps_n1(STREAMFILE* sf) { switch(type) { case 1: - init_vgmstream_subfile = init_vgmstream_vag; + init_vgmstream = init_vgmstream_vag; extension = "vag"; break; case 2: - init_vgmstream_subfile = init_vgmstream_riff; + init_vgmstream = init_vgmstream_riff; extension = "at3"; break; @@ -59,7 +59,7 @@ VGMSTREAM* init_vgmstream_sps_n1(STREAMFILE* sf) { temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, extension); if (!temp_sf) goto fail; - vgmstream = init_vgmstream_subfile(temp_sf); + vgmstream = init_vgmstream(temp_sf); if (!vgmstream) goto fail; vgmstream->sample_rate = sample_rate; /* .vag header doesn't match */ @@ -81,7 +81,7 @@ VGMSTREAM* init_vgmstream_sps_n1_segmented(STREAMFILE* sf) { int loop_flag, type, sample_rate; int i, segment; - VGMSTREAM* (*init_vgmstream_subfile)(STREAMFILE*) = NULL; + init_vgmstream_t init_vgmstream = NULL; const char* extension; segmented_layout_data* data = NULL; int segment_count, loop_start_segment, loop_end_segment; @@ -101,15 +101,13 @@ VGMSTREAM* init_vgmstream_sps_n1_segmented(STREAMFILE* sf) { /* 0x0c: num_samples (slightly smaller than added samples?) */ switch(type) { - #ifdef VGM_USE_VORBIS case 7: - init_vgmstream_subfile = init_vgmstream_ogg_vorbis; + init_vgmstream = init_vgmstream_ogg_vorbis; extension = "ogg"; break; - #endif case 9: - init_vgmstream_subfile = init_vgmstream_opus_std; + init_vgmstream = init_vgmstream_opus_std; extension = "opus"; break; @@ -155,7 +153,7 @@ VGMSTREAM* init_vgmstream_sps_n1_segmented(STREAMFILE* sf) { temp_sf = setup_subfile_streamfile(sf, segment_offset,segment_size, extension); if (!temp_sf) goto fail; - data->segments[segment] = init_vgmstream_subfile(temp_sf); + data->segments[segment] = init_vgmstream(temp_sf); close_streamfile(temp_sf); if (!data->segments[segment]) goto fail; diff --git a/src/meta/xnb.c b/src/meta/xnb.c index 25d42c2a..0b8152e1 100644 --- a/src/meta/xnb.c +++ b/src/meta/xnb.c @@ -17,10 +17,10 @@ VGMSTREAM* init_vgmstream_xnb(STREAMFILE* sf) { /* checks */ - if (!check_extensions(sf,"xnb")) - goto fail; if ((read_u32be(0x00, sf) & 0xFFFFFF00) != get_id32be("XNB\0")) goto fail; + if (!check_extensions(sf,"xnb")) + goto fail; /* XNA Studio platforms: 'w' = Windows, 'm' = Windows Phone 7, 'x' = X360 * MonoGame extensions: 'i' = iOS, 'a' = Android, 'X' = MacOSX, 'P' = PS4, 'S' = Switch, etc */ @@ -184,10 +184,9 @@ VGMSTREAM* init_vgmstream_xnb(STREAMFILE* sf) { if (!temp_sf) goto fail; if (is_ogg) { -#ifdef VGM_USE_VORBIS vgmstream = init_vgmstream_ogg_vorbis(temp_sf); -#endif - } else { + } + else { vgmstream = init_vgmstream_riff(temp_sf); } close_streamfile(temp_sf); diff --git a/src/vgmstream.c b/src/vgmstream.c index 04edd13e..f05370cb 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -59,9 +59,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_caf, init_vgmstream_vpk, init_vgmstream_genh, -#ifdef VGM_USE_VORBIS init_vgmstream_ogg_vorbis, -#endif init_vgmstream_sli_ogg, init_vgmstream_sfl_ogg, init_vgmstream_sadb,