#include "acelp_vectors.h"
#include "acelp_pitch_delay.h"
#include "lsp.h"
+#include "amr.h"
#include "amrnbdata.h"
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
/// @{
-/**
- * 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)
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++)
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;
}
/// @}
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 = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_AMR_NB,
.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 = (enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
};