X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Famrnbdec.c;h=501b1377808d29e79a62e073d7c5df9f054e0890;hb=ff17fc6353c6513316b1132f27ac2a7a8d81b9ec;hp=e5a82b493a24725aa2ec14f67f3e77cc35078326;hpb=95c6b5ebc88532e6492845e3ad3579d551ff43e6;p=ffmpeg diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c index e5a82b493a2..501b1377808 100644 --- a/libavcodec/amrnbdec.c +++ b/libavcodec/amrnbdec.c @@ -3,26 +3,26 @@ * Copyright (c) 2006-2007 Robert Swain * Copyright (c) 2009 Colin McQuillan * - * 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 */ /** - * @file libavcodec/amrnbdec.c + * @file * AMR narrowband decoder * * This decoder uses floats for simplicity and so is not bit-exact. One @@ -52,6 +52,7 @@ #include "acelp_vectors.h" #include "acelp_pitch_delay.h" #include "lsp.h" +#include "amr.h" #include "amrnbdata.h" @@ -82,7 +83,7 @@ /** Maximum sharpening factor * * The specification says 0.8, which should be 13107, but the reference C code - * uses 13017 instead. (Amusingly the same applies to SHARP_MAX in g729dec.c.) + * uses 13017 instead. (Amusingly the same applies to SHARP_MAX in bitexact G.729.) */ #define SHARP_MAX 0.79449462890625 @@ -153,7 +154,7 @@ static av_cold int amrnb_decode_init(AVCodecContext *avctx) AMRContext *p = avctx->priv_data; int i; - avctx->sample_fmt = SAMPLE_FMT_FLT; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; // p->excitation always points to the same position in p->excitation_buf p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1]; @@ -195,46 +196,17 @@ static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf, p->bad_frame_indicator = !get_bits1(&gb); // quality bit skip_bits(&gb, 2); // two padding bits - if (mode <= MODE_DTX) { - uint16_t *data = (uint16_t *)&p->frame; - const uint8_t *order = amr_unpacking_bitmaps_per_mode[mode]; - int field_size; - - memset(&p->frame, 0, sizeof(AMRNBFrame)); - buf++; - while ((field_size = *order++)) { - int field = 0; - int field_offset = *order++; - while (field_size--) { - int bit = *order++; - field <<= 1; - field |= buf[bit >> 3] >> (bit & 7) & 1; - } - data[field_offset] = field; - } - } + if (mode < MODE_DTX) + ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1, + amr_unpacking_bitmaps_per_mode[mode]); return mode; } -/// @defgroup amr_lpc_decoding AMR pitch LPC coefficient decoding functions +/// @name AMR pitch LPC coefficient decoding functions /// @{ -/** - * Convert an lsf vector into an lsp vector. - * - * @param lsf input lsf vector - * @param lsp output lsp vector - */ -static void lsf2lsp(const float *lsf, double *lsp) -{ - int i; - - for (i = 0; i < LP_FILTER_ORDER; i++) - lsp[i] = cos(2.0 * M_PI * lsf[i]); -} - /** * Interpolate the LSF vector (used for fixed gain smoothing). * The interpolation is done over all four subframes even in MODE_12k2. @@ -283,7 +255,7 @@ static void lsf2lsp_for_mode12k2(AMRContext *p, double lsp[LP_FILTER_ORDER], } if (update) - memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(float)); + memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); for (i = 0; i < LP_FILTER_ORDER; i++) lsf_q[i] = lsf_r[i] * (LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0); @@ -293,7 +265,7 @@ static void lsf2lsp_for_mode12k2(AMRContext *p, double lsp[LP_FILTER_ORDER], if (update) interpolate_lsf(p->lsf_q, lsf_q); - lsf2lsp(lsf_q, lsp); + ff_acelp_lsf2lspd(lsp, lsf_q, LP_FILTER_ORDER); } /** @@ -357,7 +329,7 @@ static void lsf2lsp_3(AMRContext *p) interpolate_lsf(p->lsf_q, lsf_q); memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); - lsf2lsp(lsf_q, p->lsp[3]); + ff_acelp_lsf2lspd(p->lsp[3], lsf_q, LP_FILTER_ORDER); // interpolate LSP vectors at subframes 1, 2 and 3 for (i = 1; i <= 3; i++) @@ -369,7 +341,7 @@ static void lsf2lsp_3(AMRContext *p) /// @} -/// @defgroup amr_pitch_vector_decoding AMR pitch vector decoding functions +/// @name AMR pitch vector decoding functions /// @{ /** @@ -431,7 +403,7 @@ static void decode_pitch_vector(AMRContext *p, /// @} -/// @defgroup amr_algebraic_code_book AMR algebraic code book (fixed) vector decoding functions +/// @name AMR algebraic code book (fixed) vector decoding functions /// @{ /** @@ -575,7 +547,7 @@ static void pitch_sharpening(AMRContext *p, int subframe, enum Mode mode, /// @} -/// @defgroup amr_gain_decoding AMR gain decoding functions +/// @name AMR gain decoding functions /// @{ /** @@ -661,7 +633,7 @@ static void decode_gains(AMRContext *p, const AMRNBSubframe *amr_subframe, /// @} -/// @defgroup amr_pre_processing AMR pre-processing functions +/// @name AMR preprocessing functions /// @{ /** @@ -779,7 +751,7 @@ static const float *anti_sparseness(AMRContext *p, AMRFixed *fixed_sparse, /// @} -/// @defgroup amr_synthesis AMR synthesis functions +/// @name AMR synthesis functions /// @{ /** @@ -796,7 +768,7 @@ static int synthesis(AMRContext *p, float *lpc, float fixed_gain, const float *fixed_vector, float *samples, uint8_t overflow) { - int i, overflow_temp = 0; + int i; float excitation[AMR_SUBFRAME_SIZE]; // if an overflow has been detected, the pitch vector is scaled down by a @@ -831,18 +803,16 @@ static int synthesis(AMRContext *p, float *lpc, // detect overflow for (i = 0; i < AMR_SUBFRAME_SIZE; i++) if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) { - overflow_temp = 1; - samples[i] = av_clipf(samples[i], -AMR_SAMPLE_BOUND, - AMR_SAMPLE_BOUND); + return 1; } - return overflow_temp; + return 0; } /// @} -/// @defgroup amr_update AMR update functions +/// @name AMR update functions /// @{ /** @@ -867,7 +837,7 @@ static void update_state(AMRContext *p) /// @} -/// @defgroup amr_postproc AMR Post processing functions +/// @name AMR Postprocessing functions /// @{ /** @@ -943,7 +913,7 @@ static void postfilter(AMRContext *p, float *lpc, float *buf_out) ff_tilt_compensation(&p->tilt_mem, tilt_factor(lpc_n, lpc_d), buf_out, AMR_SUBFRAME_SIZE); - ff_adaptive_gain_control(buf_out, speech_gain, AMR_SUBFRAME_SIZE, + ff_adaptive_gain_control(buf_out, buf_out, speech_gain, AMR_SUBFRAME_SIZE, AMR_AGC_ALPHA, &p->postfilter_agc); } @@ -1044,14 +1014,11 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, update_state(p); } - ff_acelp_apply_order_2_transfer_function(buf_out, highpass_zeros, - highpass_poles, highpass_gain, + ff_acelp_apply_order_2_transfer_function(buf_out, buf_out, highpass_zeros, + highpass_poles, + highpass_gain * AMR_SAMPLE_SCALE, p->high_pass_mem, AMR_BLOCK_SIZE); - for (i = 0; i < AMR_BLOCK_SIZE; i++) - buf_out[i] = av_clipf(buf_out[i] * AMR_SAMPLE_SCALE, - -1.0, 32767.0 / 32768.0); - /* Update averaged lsf vector (used for fixed gain smoothing). * * Note that lsf_avg should not incorporate the current frame's LSFs @@ -1069,13 +1036,13 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, } -AVCodec amrnb_decoder = { +AVCodec ff_amrnb_decoder = { .name = "amrnb", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_AMR_NB, .priv_data_size = sizeof(AMRContext), .init = amrnb_decode_init, .decode = amrnb_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate NarrowBand"), - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_FLT,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, };