* 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
#include "acelp_vectors.h"
#include "acelp_pitch_delay.h"
#include "lsp.h"
+#include "amr.h"
#include "amrnbdata.h"
/** 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
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];
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.
}
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);
if (update)
interpolate_lsf(p->lsf_q, lsf_q);
- lsf2lsp(lsf_q, lsp);
+ ff_acelp_lsf2lspd(lsp, lsf_q, LP_FILTER_ORDER);
}
/**
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++)
/// @}
-/// @defgroup amr_pitch_vector_decoding AMR pitch vector decoding functions
+/// @name AMR pitch vector decoding functions
/// @{
/**
/// @}
-/// @defgroup amr_algebraic_code_book AMR algebraic code book (fixed) vector decoding functions
+/// @name AMR algebraic code book (fixed) vector decoding functions
/// @{
/**
/// @}
-/// @defgroup amr_gain_decoding AMR gain decoding functions
+/// @name AMR gain decoding functions
/// @{
/**
/// @}
-/// @defgroup amr_pre_processing AMR pre-processing functions
+/// @name AMR preprocessing functions
/// @{
/**
/// @}
-/// @defgroup amr_synthesis AMR synthesis functions
+/// @name AMR synthesis functions
/// @{
/**
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
// 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
/// @{
/**
/// @}
-/// @defgroup amr_postproc AMR Post processing functions
+/// @name AMR Postprocessing functions
/// @{
/**
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);
}
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
}
-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},
};