From 41c04bec0ad306cf6d0b9af19f904a7c86582bdf Mon Sep 17 00:00:00 2001 From: Lynne Date: Sat, 16 Mar 2024 04:29:07 +0100 Subject: [PATCH] aacdec: move fixed-point clipping to a separate function --- libavcodec/aac/aacdec_dsp_template.c | 17 +++++++++++++++++ libavcodec/aacdec.h | 2 ++ libavcodec/aacdec_template.c | 15 +-------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libavcodec/aac/aacdec_dsp_template.c b/libavcodec/aac/aacdec_dsp_template.c index a72ccf891c..adcafa10e7 100644 --- a/libavcodec/aac/aacdec_dsp_template.c +++ b/libavcodec/aac/aacdec_dsp_template.c @@ -554,6 +554,21 @@ static void AAC_RENAME(imdct_and_windowing_eld)(AACDecContext *ac, SingleChannel memcpy( saved, buf, n * sizeof(*saved)); } +static void AAC_RENAME(clip_output)(AACDecContext *ac, ChannelElement *che, + int type, int samples) +{ +#if USE_FIXED + /* preparation for resampler */ + for (int j = 0; j < samples; j++){ + che->ch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128, + INT32_MIN, INT32_MAX-0x8000)+0x8000; + if (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) + che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128, + INT32_MIN, INT32_MAX-0x8000)+0x8000; + } +#endif +} + const AACDecDSP AAC_RENAME(aac_dsp) = { .init_tables = &AAC_RENAME(init_tables), @@ -571,4 +586,6 @@ const AACDecDSP AAC_RENAME(aac_dsp) = { .apply_dependent_coupling = AAC_RENAME(apply_dependent_coupling), .apply_independent_coupling = AAC_RENAME(apply_independent_coupling), + + .clip_output = AAC_RENAME(clip_output), }; diff --git a/libavcodec/aacdec.h b/libavcodec/aacdec.h index 91ffb877da..c8bcae4c4f 100644 --- a/libavcodec/aacdec.h +++ b/libavcodec/aacdec.h @@ -239,6 +239,8 @@ typedef struct AACDecDSP { void (*imdct_and_windowing_960)(AACDecContext *ac, SingleChannelElement *sce); void (*imdct_and_windowing_ld)(AACDecContext *ac, SingleChannelElement *sce); void (*imdct_and_windowing_eld)(AACDecContext *ac, SingleChannelElement *sce); + + void (*clip_output)(AACDecContext *ac, ChannelElement *che, int type, int samples); } AACDecDSP; /** diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 3c77b41694..d56801fc66 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -2129,20 +2129,7 @@ static void spectral_to_sample(AACDecContext *ac, int samples) } if (type <= TYPE_CCE) apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, ac->dsp.apply_independent_coupling); - -#if USE_FIXED - { - int j; - /* preparation for resampler */ - for(j = 0; jch[0].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[0].output_fixed[j]*128, - INT32_MIN, INT32_MAX-0x8000)+0x8000; - if (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) - che->ch[1].output_fixed[j] = (int32_t)av_clip64((int64_t)che->ch[1].output_fixed[j]*128, - INT32_MIN, INT32_MAX-0x8000)+0x8000; - } - } -#endif /* USE_FIXED */ + ac->dsp.clip_output(ac, che, type, samples); che->present = 0; } else if (che) { av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i);