From 01cd37356725d5c8c1f8efb4e67a4ac707dd1b09 Mon Sep 17 00:00:00 2001 From: bnnm Date: Wed, 9 Dec 2020 21:18:13 +0100 Subject: [PATCH] Fix some .NAAC looping issues --- src/meta/naac.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/meta/naac.c b/src/meta/naac.c index 9f649cf4..f8b7fd53 100644 --- a/src/meta/naac.c +++ b/src/meta/naac.c @@ -1,51 +1,56 @@ #include "meta.h" #include "../coding/coding.h" + /* .NAAC - from Namco 3DS games (Ace Combat - Assault Horizon Legacy, Taiko no Tatsujin Don to Katsu no Jikuu Daibouken) */ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channel_count; + int loop_flag, channels; size_t data_size; - /* check extension */ - if ( !check_extensions(sf,"naac") ) + + /* checks */ + if (!check_extensions(sf,"naac")) goto fail; - /* check header */ - if (read_32bitBE(0x00,sf) != 0x41414320) /* "AAC " */ + if (read_u32be(0x00,sf) != 0x41414320) /* "AAC " */ goto fail; - if (read_32bitLE(0x04,sf) != 0x01) /* version? */ + if (read_u32le(0x04,sf) != 0x01) /* version? */ goto fail; start_offset = 0x1000; - loop_flag = (read_32bitLE(0x18,sf) != 0); - channel_count = read_32bitLE(0x08,sf); + loop_flag = (read_s32le(0x18,sf) != 0); + channels = read_s32le(0x08,sf); /* build the VGMSTREAM */ - vgmstream = allocate_vgmstream(channel_count,loop_flag); + vgmstream = allocate_vgmstream(channels, loop_flag); if (!vgmstream) goto fail; - vgmstream->sample_rate = read_32bitLE(0x0c,sf); - vgmstream->num_samples = read_32bitLE(0x10,sf); /* without skip_samples */ - vgmstream->loop_start_sample = read_32bitLE(0x14,sf); /* with skip_samples */ - vgmstream->loop_end_sample = read_32bitLE(0x18,sf); - /* 0x1c: loop start offset, 0x20: loop end offset (within data) */ - data_size = read_32bitLE(0x24,sf); - /* 0x28: unknown; 0x2c: table start offset?; 0x30: seek table (always 0xFD0, padded) */ + vgmstream->sample_rate = read_s32le(0x0c,sf); + vgmstream->num_samples = read_s32le(0x10,sf); /* without skip_samples */ + vgmstream->loop_start_sample = read_s32le(0x14,sf); /* with skip_samples */ + vgmstream->loop_end_sample = read_s32le(0x18,sf) + 1; /* without skip_samples */ + /* 0x1c: loop start offset */ + /* 0x20: loop end offset (within data) */ + data_size = read_u32le(0x24,sf); + /* 0x28: unknown */ + /* 0x2c: table start offset? */ + /* 0x30: seek table (always 0xFD0, padded) */ vgmstream->meta_type = meta_NAAC; #ifdef VGM_USE_FFMPEG { - vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset,data_size); + vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, data_size); if (!vgmstream->codec_data) goto fail; vgmstream->coding_type = coding_FFmpeg; vgmstream->layout_type = layout_none; /* observed default, some files start without silence though seems correct when loop_start=0 */ ffmpeg_set_skip_samples(vgmstream->codec_data, 1024); /* raw AAC doesn't set this */ - vgmstream->num_samples -= 1024; + vgmstream->num_samples -= 1024; /* may end with 1024 of silence? */ + vgmstream->loop_end_sample -= 1024; } #else goto fail;