diff options
author | Maxim Poliakovski <max_pole@gmx.de> | 2013-10-02 04:23:16 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-10-02 12:44:02 +0400 |
commit | d49f3fa5794c9f17e058a6bce3ce6eac870ef85c (patch) | |
tree | 361fdfad4a493c195371c6e36832a35fc5a95b8a /libavcodec/atrac3.c | |
parent | 4fa2484067d19a69dfe6f6e6b67a58fcba380a27 (diff) |
atrac3: Generalize gain compensation code
Move it to the ATRAC common code, so it can be reused
in the umpcoming ATRAC3+ decoder.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/atrac3.c')
-rw-r--r-- | libavcodec/atrac3.c | 76 |
1 files changed, 7 insertions, 69 deletions
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index f68b33cce3..245805c8ef 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -55,12 +55,6 @@ #define SAMPLES_PER_FRAME 1024 #define MDCT_SIZE 512 -typedef struct AtracGainInfo { - int num_points; - int lev_code[8]; - int loc_code[8]; -} AtracGainInfo; - typedef struct GainBlock { AtracGainInfo g_block[4]; } GainBlock; @@ -112,7 +106,8 @@ typedef struct ATRAC3Context { int scrambled_stream; //@} - FFTContext mdct_ctx; + AtracGCContext gainc_ctx; + FFTContext mdct_ctx; FmtConvertContext fmt_conv; AVFloatDSPContext fdsp; } ATRAC3Context; @@ -444,63 +439,6 @@ static int decode_gain_control(GetBitContext *gb, GainBlock *block, } /** - * Apply gain parameters and perform the MDCT overlapping part - * - * @param input input buffer - * @param prev previous buffer to perform overlap against - * @param output output buffer - * @param gain1 current band gain info - * @param gain2 next band gain info - */ -static void gain_compensate_and_overlap(float *input, float *prev, - float *output, AtracGainInfo *gain1, - AtracGainInfo *gain2) -{ - float g1, g2, gain_inc; - int i, j, num_data, start_loc, end_loc; - - - if (gain2->num_points == 0) - g1 = 1.0; - else - g1 = gain_tab1[gain2->lev_code[0]]; - - if (gain1->num_points == 0) { - for (i = 0; i < 256; i++) - output[i] = input[i] * g1 + prev[i]; - } else { - num_data = gain1->num_points; - gain1->loc_code[num_data] = 32; - gain1->lev_code[num_data] = 4; - - for (i = 0, j = 0; i < num_data; i++) { - start_loc = gain1->loc_code[i] * 8; - end_loc = start_loc + 8; - - g2 = gain_tab1[gain1->lev_code[i]]; - gain_inc = gain_tab2[gain1->lev_code[i + 1] - - gain1->lev_code[i ] + 15]; - - /* interpolate */ - for (; j < start_loc; j++) - output[j] = (input[j] * g1 + prev[j]) * g2; - - /* interpolation is done over eight samples */ - for (; j < end_loc; j++) { - output[j] = (input[j] * g1 + prev[j]) * g2; - g2 *= gain_inc; - } - } - - for (; j < 256; j++) - output[j] = input[j] * g1 + prev[j]; - } - - /* Delay for the overlapping part. */ - memcpy(prev, &input[256], 256 * sizeof(*prev)); -} - -/** * Combine the tonal band spectrum and regular band spectrum * * @param spectrum output spectrum buffer @@ -690,11 +628,10 @@ static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf)); /* gain compensation and overlapping */ - gain_compensate_and_overlap(snd->imdct_buf, - &snd->prev_frame[band * 256], - &output[band * 256], - &gain1->g_block[band], - &gain2->g_block[band]); + ff_atrac_gain_compensation(&q->gainc_ctx, snd->imdct_buf, + &snd->prev_frame[band * 256], + &gain1->g_block[band], &gain2->g_block[band], + 256, &output[band * 256]); } /* Swap the gain control buffers for the next frame. */ @@ -987,6 +924,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) q->matrix_coeff_index_next[i] = 3; } + ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3); avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_fmt_convert_init(&q->fmt_conv, avctx); |