From 4a178e4e44c7657906213b52bbc02a07083664f6 Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 23 Jul 2021 15:52:31 +0200 Subject: [PATCH] ffmpeg: AAC cleanup and doc --- src/coding/coding.h | 2 +- src/coding/ffmpeg_decoder_custom_opus.c | 6 ++---- src/coding/ffmpeg_decoder_utils.c | 4 ++-- src/meta/ffmpeg.c | 3 +++ src/meta/naac.c | 10 +++++----- src/meta/strm_abylight.c | 11 +++++------ src/meta/txth.c | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/coding/coding.h b/src/coding/coding.h index 360c4eb0..e44ecb9e 100644 --- a/src/coding/coding.h +++ b/src/coding/coding.h @@ -572,7 +572,7 @@ STREAMFILE* ffmpeg_get_streamfile(ffmpeg_codec_data* data); /* ffmpeg_decoder_utils.c (helper-things) */ ffmpeg_codec_data* init_ffmpeg_atrac3_raw(STREAMFILE* sf, off_t offset, size_t data_size, int sample_count, int channels, int sample_rate, int block_align, int encoder_delay); ffmpeg_codec_data* init_ffmpeg_atrac3_riff(STREAMFILE* sf, off_t offset, int* out_samples); -ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size); +ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size, int skip_samples); /* ffmpeg_decoder_custom_opus.c (helper-things) */ diff --git a/src/coding/ffmpeg_decoder_custom_opus.c b/src/coding/ffmpeg_decoder_custom_opus.c index cc97594c..463f3300 100644 --- a/src/coding/ffmpeg_decoder_custom_opus.c +++ b/src/coding/ffmpeg_decoder_custom_opus.c @@ -764,10 +764,8 @@ static ffmpeg_codec_data* init_ffmpeg_custom_opus_config(STREAMFILE* sf, off_t s /* FFmpeg + libopus: skips samples, notifies skip in codecCtx->delay (not in stream->skip_samples) * FFmpeg + opus: *doesn't* skip, also notifies skip in codecCtx->delay, hurray (possibly fixed in recent versions) - * FFmpeg + opus is audibly buggy with some low bitrate SSB Ultimate files too */ - //if (ffmpeg_data->skipSamples <= 0) { - // ffmpeg_set_skip_samples(ffmpeg_data, skip); - //} + * FFmpeg + opus is audibly buggy with some low bitrate SSB Ultimate files */ + //ffmpeg_set_skip_samples(ffmpeg_data, skip); close_streamfile(temp_sf); return ffmpeg_data; diff --git a/src/coding/ffmpeg_decoder_utils.c b/src/coding/ffmpeg_decoder_utils.c index 31237a88..3c3feed8 100644 --- a/src/coding/ffmpeg_decoder_utils.c +++ b/src/coding/ffmpeg_decoder_utils.c @@ -187,7 +187,7 @@ fail: return NULL; } -ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) { +ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size, int skip_samples) { ffmpeg_codec_data* data = NULL; data = init_ffmpeg_offset(sf, offset, size); @@ -199,7 +199,7 @@ ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) { /* raw AAC doesn't set this, while some decoders like FAAD remove 1024, * but should be handled in container as each encoder uses its own value * (Apple: 2112, FAAD: probably 1024, etc) */ - //ffmpeg_set_skip_samples(data, 1024); + ffmpeg_set_skip_samples(data, skip_samples); return data; fail: diff --git a/src/meta/ffmpeg.c b/src/meta/ffmpeg.c index 0bade7e6..5067d2f0 100644 --- a/src/meta/ffmpeg.c +++ b/src/meta/ffmpeg.c @@ -82,6 +82,9 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) { * .mus: Marc Ecko's Getting Up (PC) */ if (!num_samples && check_extensions(sf, "mp3,lmp3,mus")) { num_samples = mpeg_get_samples(sf, 0x00, get_streamfile_size(sf)); + + /* this seems correct thankfully */ + //ffmpeg_set_skip_samples(data, encoder_delay); } #endif diff --git a/src/meta/naac.c b/src/meta/naac.c index 6069dd00..67ba55e4 100644 --- a/src/meta/naac.c +++ b/src/meta/naac.c @@ -6,7 +6,7 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) { VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channels; + int loop_flag, channels, skip_samples; size_t data_size; @@ -22,6 +22,7 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) { start_offset = 0x1000; loop_flag = (read_s32le(0x18,sf) != 0); channels = read_s32le(0x08,sf); + skip_samples = 1024; /* raw AAC doesn't set this */ /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channels, loop_flag); @@ -42,15 +43,14 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) { #ifdef VGM_USE_FFMPEG { - vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size); + vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size, skip_samples); 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->loop_end_sample -= 1024; + vgmstream->num_samples -= skip_samples; + vgmstream->loop_end_sample -= skip_samples; /* for some reason last frame is ignored/bugged in various decoders (gives EOF errors) */ } #else diff --git a/src/meta/strm_abylight.c b/src/meta/strm_abylight.c index cb97bcc5..cfdda7f3 100644 --- a/src/meta/strm_abylight.c +++ b/src/meta/strm_abylight.c @@ -4,9 +4,9 @@ /* .STRM - from Abylight 3DS games [Cursed Castilla (3DS)] */ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) { - VGMSTREAM * vgmstream = NULL; + VGMSTREAM* vgmstream = NULL; off_t start_offset; - int loop_flag, channel_count, sample_rate; + int loop_flag, channel_count, sample_rate, skip_samples; size_t data_size; @@ -22,6 +22,7 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) { loop_flag = 0; channel_count = 2; /* there are various possible fields but all files are stereo */ sample_rate = read_32bitLE(0x08,sf); + skip_samples = 1024; /* assumed, maybe a bit more */ start_offset = 0x1e; data_size = read_32bitLE(0x10,sf); @@ -42,14 +43,12 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) { #ifdef VGM_USE_FFMPEG { - vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size); + vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size, skip_samples); if (!vgmstream->codec_data) goto fail; vgmstream->coding_type = coding_FFmpeg; vgmstream->layout_type = layout_none; - /* assumed, maybe a bit more */ - ffmpeg_set_skip_samples(vgmstream->codec_data, 1024); - vgmstream->num_samples -= 1024; + vgmstream->num_samples -= skip_samples; } #else goto fail; diff --git a/src/meta/txth.c b/src/meta/txth.c index 74f514ae..418506a7 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -486,7 +486,7 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) { vgmstream->num_samples = ffmpeg_data->totalSamples; /* sometimes works */ } else if (txth.codec == AAC) { - ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size); + ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size, 0); if (!ffmpeg_data) goto fail; } else {