diff --git a/src/meta/tgc.c b/src/meta/tgc.c index a865309e..806f8e65 100644 --- a/src/meta/tgc.c +++ b/src/meta/tgc.c @@ -2,24 +2,36 @@ #include "../coding/coding.h" /* Tiger Game.com ADPCM file */ -VGMSTREAM * init_vgmstream_tgc(STREAMFILE *streamFile) { - VGMSTREAM * vgmstream = NULL; +VGMSTREAM* init_vgmstream_tgc(STREAMFILE* sf) { + VGMSTREAM* vgmstream = NULL; + uint16_t size; + off_t start_offset; + /* checks */ - if (!check_extensions(streamFile, "4")) + if (read_u8(0x00, sf) != 0) goto fail; + if (!check_extensions(sf, "4")) + goto fail; + + size = read_u16be(0x01, sf); + if (size != get_streamfile_size(sf)) + goto fail; + start_offset = 0x03; + + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(1, 0); if (!vgmstream) goto fail; vgmstream->sample_rate = 8000; - vgmstream->num_samples = ((uint16_t)read_16bitBE(1, streamFile) - 3) * 2; + vgmstream->num_samples = (size - 0x03) * 2; vgmstream->meta_type = meta_TGC; vgmstream->layout_type = layout_none; vgmstream->coding_type = coding_TGC; - if (!vgmstream_open_stream(vgmstream, streamFile, 3)) + if (!vgmstream_open_stream(vgmstream, sf, start_offset)) goto fail; return vgmstream; diff --git a/src/vgmstream.c b/src/vgmstream.c index f3ad67ff..012adc5d 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -470,7 +470,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_csb, init_vgmstream_fwse, init_vgmstream_fda, - init_vgmstream_tgc, init_vgmstream_kwb, init_vgmstream_lrmd, init_vgmstream_bkhd, @@ -538,6 +537,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = { init_vgmstream_seb, init_vgmstream_ps2_pnb, init_vgmstream_sli_ogg, + init_vgmstream_tgc, /* 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 */