#include <string.h>
#include <math.h>
#include "avcodec.h"
#include "get_bits.h"
#include "libavutil/common.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "acelp_pitch_delay.h"
#include "lsp.h"
#include "amrnbdata.h"
Go to the source code of this file.
Data Structures | |
struct | AMRContext |
Defines | |
#define | AMR_BLOCK_SIZE 160 |
samples per frame | |
#define | AMR_SAMPLE_BOUND 32768.0 |
threshold for synthesis overflow | |
#define | AMR_SAMPLE_SCALE (2.0 / 32768.0) |
Scale from constructed speech to [-1,1]. | |
#define | PRED_FAC_MODE_12k2 0.65 |
Prediction factor for 12.2kbit/s mode. | |
#define | LSF_R_FAC (8000.0 / 32768.0) |
LSF residual tables to Hertz. | |
#define | MIN_LSF_SPACING (50.0488 / 8000.0) |
Ensures stability of LPC filter. | |
#define | PITCH_LAG_MIN_MODE_12k2 18 |
Lower bound on decoded lag search in 12.2kbit/s mode. | |
#define | MIN_ENERGY -14.0 |
Initial energy in dB. | |
#define | SHARP_MAX 0.79449462890625 |
Maximum sharpening factor. | |
#define | AMR_TILT_RESPONSE 22 |
Number of impulse response coefficients used for tilt factor. | |
#define | AMR_TILT_GAMMA_T 0.8 |
Tilt factor = 1st reflection coefficient * gamma_t. | |
#define | AMR_AGC_ALPHA 0.9 |
Adaptive gain control factor used in post-filter. | |
Functions | |
static void | weighted_vector_sumd (double *out, const double *in_a, const double *in_b, double weight_coeff_a, double weight_coeff_b, int length) |
Double version of ff_weighted_vector_sumf(). | |
static av_cold int | amrnb_decode_init (AVCodecContext *avctx) |
static enum Mode | unpack_bitstream (AMRContext *p, const uint8_t *buf, int buf_size) |
Unpack an RFC4867 speech frame into the AMR frame mode and parameters. | |
static void | lsf2lsp (const float *lsf, double *lsp) |
Convert an lsf vector into an lsp vector. | |
static void | interpolate_lsf (float lsf_q[4][LP_FILTER_ORDER], float *lsf_new) |
Interpolate the LSF vector (used for fixed gain smoothing). | |
static void | lsf2lsp_for_mode12k2 (AMRContext *p, double lsp[LP_FILTER_ORDER], const float lsf_no_r[LP_FILTER_ORDER], const int16_t *lsf_quantizer[5], const int quantizer_offset, const int sign, const int update) |
Decode a set of 5 split-matrix quantized lsf indexes into an lsp vector. | |
static void | lsf2lsp_5 (AMRContext *p) |
Decode a set of 5 split-matrix quantized lsf indexes into 2 lsp vectors. | |
static void | lsf2lsp_3 (AMRContext *p) |
Decode a set of 3 split-matrix quantized lsf indexes into an lsp vector. | |
static void | decode_pitch_lag_1_6 (int *lag_int, int *lag_frac, int pitch_index, const int prev_lag_int, const int subframe) |
Like ff_decode_pitch_lag(), but with 1/6 resolution. | |
static void | decode_pitch_vector (AMRContext *p, const AMRNBSubframe *amr_subframe, const int subframe) |
static void | decode_10bit_pulse (int code, int pulse_position[8], int i1, int i2, int i3) |
Decode a 10-bit algebraic codebook index from a 10.2 kbit/s frame. | |
static void | decode_8_pulses_31bits (const int16_t *fixed_index, AMRFixed *fixed_sparse) |
Decode the algebraic codebook index to pulse positions and signs and construct the algebraic codebook vector for MODE_10k2. | |
static void | decode_fixed_sparse (AMRFixed *fixed_sparse, const uint16_t *pulses, const enum Mode mode, const int subframe) |
Decode the algebraic codebook index to pulse positions and signs, then construct the algebraic codebook vector. | |
static void | pitch_sharpening (AMRContext *p, int subframe, enum Mode mode, AMRFixed *fixed_sparse) |
Apply pitch lag to obtain the sharpened fixed vector (section 6.1.2). | |
static float | fixed_gain_smooth (AMRContext *p, const float *lsf, const float *lsf_avg, const enum Mode mode) |
fixed gain smoothing Note that where the spec specifies the "spectrum in the q domain" in section 6.1.4, in fact frequencies should be used. | |
static void | decode_gains (AMRContext *p, const AMRNBSubframe *amr_subframe, const enum Mode mode, const int subframe, float *fixed_gain_factor) |
Decode pitch gain and fixed gain factor (part of section 6.1.3). | |
static void | apply_ir_filter (float *out, const AMRFixed *in, const float *filter) |
Circularly convolve a sparse fixed vector with a phase dispersion impulse response filter (D.6.2 of G.729 and 6.1.5 of AMR). | |
static const float * | anti_sparseness (AMRContext *p, AMRFixed *fixed_sparse, const float *fixed_vector, float fixed_gain, float *out) |
Reduce fixed vector sparseness by smoothing with one of three IR filters. | |
static int | synthesis (AMRContext *p, float *lpc, float fixed_gain, const float *fixed_vector, float *samples, uint8_t overflow) |
Conduct 10th order linear predictive coding synthesis. | |
static void | update_state (AMRContext *p) |
Update buffers and history at the end of decoding a subframe. | |
static float | tilt_factor (float *lpc_n, float *lpc_d) |
Get the tilt factor of a formant filter from its transfer function. | |
static void | postfilter (AMRContext *p, float *lpc, float *buf_out) |
Perform adaptive post-filtering to enhance the quality of the speech. | |
static int | amrnb_decode_frame (AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
Variables | |
AVCodec | amrnb_decoder |
This decoder uses floats for simplicity and so is not bit-exact. One difference is that differences in phase can accumulate. The test sequences in 3GPP TS 26.074 can still be useful.
Definition in file amrnbdec.c.
#define AMR_AGC_ALPHA 0.9 |
Adaptive gain control factor used in post-filter.
Definition at line 94 of file amrnbdec.c.
Referenced by postfilter().
#define AMR_BLOCK_SIZE 160 |
#define AMR_SAMPLE_BOUND 32768.0 |
threshold for synthesis overflow
Definition at line 59 of file amrnbdec.c.
Referenced by synthesis().
#define AMR_SAMPLE_SCALE (2.0 / 32768.0) |
Scale from constructed speech to [-1,1].
AMR is designed to produce 16-bit PCM samples (3GPP TS 26.090 4.2) but upscales by two (section 6.2.2).
Fundamentally, this scale is determined by energy_mean through the fixed vector contribution to the excitation vector.
Definition at line 70 of file amrnbdec.c.
Referenced by amrnb_decode_frame().
#define AMR_TILT_GAMMA_T 0.8 |
Tilt factor = 1st reflection coefficient * gamma_t.
Definition at line 92 of file amrnbdec.c.
Referenced by tilt_factor().
#define AMR_TILT_RESPONSE 22 |
Number of impulse response coefficients used for tilt factor.
Definition at line 90 of file amrnbdec.c.
Referenced by tilt_factor().
#define LSF_R_FAC (8000.0 / 32768.0) |
LSF residual tables to Hertz.
Definition at line 75 of file amrnbdec.c.
Referenced by lsf2lsp_3(), lsf2lsp_5(), and lsf2lsp_for_mode12k2().
#define MIN_ENERGY -14.0 |
Initial energy in dB.
Also used for bad frames (unimplemented).
Definition at line 80 of file amrnbdec.c.
Referenced by amrnb_decode_init().
#define MIN_LSF_SPACING (50.0488 / 8000.0) |
Ensures stability of LPC filter.
Definition at line 76 of file amrnbdec.c.
Referenced by lsf2lsp_3(), and lsf2lsp_for_mode12k2().
#define PITCH_LAG_MIN_MODE_12k2 18 |
Lower bound on decoded lag search in 12.2kbit/s mode.
Definition at line 77 of file amrnbdec.c.
Referenced by decode_pitch_lag_1_6().
#define PRED_FAC_MODE_12k2 0.65 |
Prediction factor for 12.2kbit/s mode.
Definition at line 73 of file amrnbdec.c.
Referenced by lsf2lsp_5().
#define SHARP_MAX 0.79449462890625 |
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.)
Definition at line 87 of file amrnbdec.c.
Referenced by decode_frame(), pitch_sharpening(), and synthesis().
static int amrnb_decode_frame | ( | AVCodecContext * | avctx, | |
void * | data, | |||
int * | data_size, | |||
AVPacket * | avpkt | |||
) | [static] |
Definition at line 950 of file amrnbdec.c.
static av_cold int amrnb_decode_init | ( | AVCodecContext * | avctx | ) | [static] |
Definition at line 151 of file amrnbdec.c.
static enum Mode unpack_bitstream | ( | AMRContext * | p, | |
const uint8_t * | buf, | |||
int | buf_size | |||
) | [static] |
Unpack an RFC4867 speech frame into the AMR frame mode and parameters.
The order of speech bits is specified by 3GPP TS 26.101.
p | the context | |
buf | pointer to the input buffer | |
buf_size | size of the input buffer |
Definition at line 184 of file amrnbdec.c.
Referenced by amrnb_decode_frame().
static void weighted_vector_sumd | ( | double * | out, | |
const double * | in_a, | |||
const double * | in_b, | |||
double | weight_coeff_a, | |||
double | weight_coeff_b, | |||
int | length | |||
) | [static] |
Double version of ff_weighted_vector_sumf().
Definition at line 140 of file amrnbdec.c.
Referenced by lsf2lsp_5().
Initial value:
{ .name = "amrnb", .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}, }
Definition at line 1067 of file amrnbdec.c.