From 7c10b87b5744179f16411f5981e96738021ec7ca Mon Sep 17 00:00:00 2001 From: Rostislav Pehlivanov Date: Fri, 26 Jun 2015 21:16:34 +0100 Subject: [PATCH] aacenc: add support for coding of intensity stereo scalefactor indices This commit adds support for the coding of intensity stereo scalefactor indices. It does not do any marking of such bands and as such does no functional changes to the encoder. It removes any old twoloop specific code for PNS and moves it into a seperate function which handles setting of scalefactor indices for PNS and IS bands. Reviewed-by: Claudio Freire Signed-off-by: Michael Niedermayer --- libavcodec/aaccoder.c | 37 +++++++++++++++++++++++++++++++++++++ libavcodec/aacenc.c | 6 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index 2f99924821..cd996b2430 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -595,6 +595,43 @@ typedef struct TrellisPath { #define TRELLIS_STAGES 121 #define TRELLIS_STATES (SCALE_MAX_DIFF+1) +static void set_special_band_scalefactors(AACEncContext *s, SingleChannelElement *sce) +{ + int w, g, start = 0; + int minscaler_n = sce->sf_idx[0], minscaler_i = sce->sf_idx[0]; + int bands = 0; + + for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { + start = 0; + for (g = 0; g < sce->ics.num_swb; g++) { + if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) { + sce->sf_idx[w*16+g] = av_clip(ceilf(log2f(sce->is_ener[w*16+g])*2), -155, 100); + minscaler_i = FFMIN(minscaler_i, sce->sf_idx[w*16+g]); + bands++; + } else if (sce->band_type[w*16+g] == NOISE_BT) { + sce->sf_idx[w*16+g] = av_clip(4+log2f(sce->pns_ener[w*16+g])*2, -100, 155); + minscaler_n = FFMIN(minscaler_n, sce->sf_idx[w*16+g]); + bands++; + } + start += sce->ics.swb_sizes[g]; + } + } + + if (!bands) + return; + + /* Clip the scalefactor indices */ + for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { + for (g = 0; g < sce->ics.num_swb; g++) { + if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) { + sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_i, minscaler_i + SCALE_MAX_DIFF); + } else if (sce->band_type[w*16+g] == NOISE_BT) { + sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_n, minscaler_n + SCALE_MAX_DIFF); + } + } + } +} + static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 897c3a10df..3a512ffeee 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -389,7 +389,7 @@ static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce) { int diff, off_sf = sce->sf_idx[0], off_pns = sce->sf_idx[0] - NOISE_OFFSET; - int noise_flag = 1; + int off_is = 0, noise_flag = 1; int i, w; for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { @@ -402,6 +402,10 @@ static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, put_bits(&s->pb, NOISE_PRE_BITS, diff + NOISE_PRE); continue; } + } else if (sce->band_type[w*16 + i] == INTENSITY_BT || + sce->band_type[w*16 + i] == INTENSITY_BT2) { + diff = sce->sf_idx[w*16 + i] - off_is; + off_is = sce->sf_idx[w*16 + i]; } else { diff = sce->sf_idx[w*16 + i] - off_sf; off_sf = sce->sf_idx[w*16 + i];