X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fra144.c;h=ccaa149b0a4ffa742a2e29331d678855c0821817;hb=612cc0712836af2f025b0c68b11da29b9f259d5a;hp=d49e0a0e8e2aed82fcda00ac1ce9c019757235ab;hpb=6ea6c8ebcfae8413311f087ecbcd07f0063c2529;p=ffmpeg diff --git a/libavcodec/ra144.c b/libavcodec/ra144.c index d49e0a0e8e2..ccaa149b0a4 100644 --- a/libavcodec/ra144.c +++ b/libavcodec/ra144.c @@ -1,26 +1,28 @@ /* * Real Audio 1.0 (14.4K) - * Copyright (c) 2003 the ffmpeg project + * Copyright (c) 2003 The FFmpeg project * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include "avcodec.h" +#include "celp_filters.h" +#include "mathops.h" #include "ra144.h" const int16_t ff_gain_val_tab[256][3] = { @@ -1502,8 +1504,8 @@ const int16_t * const ff_lpc_refl_cb[10]={ lpc_refl_cb6, lpc_refl_cb7, lpc_refl_cb8, lpc_refl_cb9, lpc_refl_cb10 }; -void ff_add_wav(int16_t *dest, int n, int skip_first, int *m, const int16_t *s1, - const int8_t *s2, const int8_t *s3) +static void add_wav(int16_t *dest, int n, int skip_first, int *m, + const int16_t *s1, const int8_t *s2, const int8_t *s3) { int i; int v[3]; @@ -1543,22 +1545,22 @@ void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset) int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx) { int b, i, j; - int buffer1[10]; - int buffer2[10]; + int buffer1[LPC_ORDER]; + int buffer2[LPC_ORDER]; int *bp1 = buffer1; int *bp2 = buffer2; - for (i=0; i < 10; i++) + for (i=0; i < LPC_ORDER; i++) buffer2[i] = coefs[i]; - refl[9] = bp2[9]; + refl[LPC_ORDER-1] = bp2[LPC_ORDER-1]; - if ((unsigned) bp2[9] + 0x1000 > 0x1fff) { + if ((unsigned) bp2[LPC_ORDER-1] + 0x1000 > 0x1fff) { av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); return 1; } - for (i=8; i >= 0; i--) { + for (i = LPC_ORDER-2; i >= 0; i--) { b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12); if (!b) @@ -1579,16 +1581,16 @@ int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx) /** * Evaluate the LPC filter coefficients from the reflection coefficients. - * Does the inverse of the eval_refl() function. + * Does the inverse of the ff_eval_refl() function. */ void ff_eval_coefs(int *coefs, const int *refl) { - int buffer[10]; + int buffer[LPC_ORDER]; int *b1 = buffer; int *b2 = coefs; int i, j; - for (i=0; i < 10; i++) { + for (i=0; i < LPC_ORDER; i++) { b1[i] = refl[i] << 4; for (j=0; j < i; j++) @@ -1597,7 +1599,7 @@ void ff_eval_coefs(int *coefs, const int *refl) FFSWAP(int *, b1, b2); } - for (i=0; i < 10; i++) + for (i=0; i < LPC_ORDER; i++) coefs[i] >>= 4; } @@ -1605,7 +1607,7 @@ void ff_int_to_int16(int16_t *out, const int *inp) { int i; - for (i=0; i < 10; i++) + for (i = 0; i < LPC_ORDER; i++) *out++ = *inp++; } @@ -1628,9 +1630,9 @@ unsigned int ff_rms(const int *data) { int i; unsigned int res = 0x10000; - int b = 10; + int b = LPC_ORDER; - for (i=0; i < 10; i++) { + for (i = 0; i < LPC_ORDER; i++) { res = (((0x1000000 - data[i]*data[i]) >> 12) * res) >> 12; if (res == 0) @@ -1647,13 +1649,13 @@ unsigned int ff_rms(const int *data) int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy) { - int work[10]; + int work[LPC_ORDER]; int b = NBLOCKS - a; int i; // Interpolate block coefficients from the this frame's forth block and // last frame's forth block. - for (i=0; i<10; i++) + for (i = 0; i < LPC_ORDER; i++) out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2; if (ff_eval_refl(work, out, ractx->avctx)) { @@ -1684,3 +1686,36 @@ int ff_irms(const int16_t *data) return 0x20000000 / (ff_t_sqrt(sum) >> 8); } + +void ff_subblock_synthesis(RA144Context *ractx, const uint16_t *lpc_coefs, + int cba_idx, int cb1_idx, int cb2_idx, + int gval, int gain) +{ + uint16_t buffer_a[BLOCKSIZE]; + uint16_t *block; + int m[3]; + + if (cba_idx) { + cba_idx += BLOCKSIZE/2 - 1; + ff_copy_and_dup(buffer_a, ractx->adapt_cb, cba_idx); + m[0] = (ff_irms(buffer_a) * gval) >> 12; + } else { + m[0] = 0; + } + m[1] = (ff_cb1_base[cb1_idx] * gval) >> 8; + m[2] = (ff_cb2_base[cb2_idx] * gval) >> 8; + memmove(ractx->adapt_cb, ractx->adapt_cb + BLOCKSIZE, + (BUFFERSIZE - BLOCKSIZE) * sizeof(*ractx->adapt_cb)); + + block = ractx->adapt_cb + BUFFERSIZE - BLOCKSIZE; + + add_wav(block, gain, cba_idx, m, cba_idx? buffer_a: NULL, + ff_cb1_vects[cb1_idx], ff_cb2_vects[cb2_idx]); + + memcpy(ractx->curr_sblock, ractx->curr_sblock + BLOCKSIZE, + LPC_ORDER*sizeof(*ractx->curr_sblock)); + + if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + LPC_ORDER, lpc_coefs, + block, BLOCKSIZE, LPC_ORDER, 1, 0, 0xfff)) + memset(ractx->curr_sblock, 0, (LPC_ORDER+BLOCKSIZE)*sizeof(*ractx->curr_sblock)); +}