#include "libavutil/lfg.h"
#include "avcodec.h"
#include "lsp.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "acelp_pitch_delay.h"
#include "amr.h"
#include "amrwbdata.h"
Go to the source code of this file.
Data Structures | |
struct | AMRWBContext |
Defines | |
#define | AMR_USE_16BIT_TABLES |
#define | BIT_STR(x, lsb, len) (((x) >> (lsb)) & ((1 << (len)) - 1)) |
Get x bits in the index interval [lsb,lsb+len-1] inclusive. | |
#define | BIT_POS(x, p) (((x) >> (p)) & 1) |
Get the bit at specified position. | |
Functions | |
static av_cold int | amrwb_decode_init (AVCodecContext *avctx) |
static int | decode_mime_header (AMRWBContext *ctx, const uint8_t *buf) |
Decode the frame header in the "MIME/storage" format. | |
static void | decode_isf_indices_36b (uint16_t *ind, float *isf_q) |
Decode quantized ISF vectors using 36-bit indexes (6K60 mode only). | |
static void | decode_isf_indices_46b (uint16_t *ind, float *isf_q) |
Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode). | |
static void | isf_add_mean_and_past (float *isf_q, float *isf_past) |
Apply mean and past ISF values using the prediction factor. | |
static void | interpolate_isp (double isp_q[4][LP_ORDER], const double *isp4_past) |
Interpolate the fourth ISP vector from current and past frames to obtain an ISP vector for each subframe. | |
static void | decode_pitch_lag_high (int *lag_int, int *lag_frac, int pitch_index, uint8_t *base_lag_int, int subframe) |
Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes). | |
static void | decode_pitch_lag_low (int *lag_int, int *lag_frac, int pitch_index, uint8_t *base_lag_int, int subframe, enum Mode mode) |
Decode an adaptive codebook index into pitch lag for 8k85 and 6k60 modes. | |
static void | decode_pitch_vector (AMRWBContext *ctx, const AMRWBSubFrame *amr_subframe, const int subframe) |
Find the pitch vector by interpolating the past excitation at the pitch delay, which is obtained in this function. | |
static void | decode_1p_track (int *out, int code, int m, int off) |
The next six functions decode_[i]p_track decode exactly i pulses positions and amplitudes (-1 or 1) in a subframe track using an encoded pulse indexing (TS 26.190 section 5.8.2). | |
static void | decode_2p_track (int *out, int code, int m, int off) |
code: 2m+1 bits | |
static void | decode_3p_track (int *out, int code, int m, int off) |
code: 3m+1 bits | |
static void | decode_4p_track (int *out, int code, int m, int off) |
code: 4m bits | |
static void | decode_5p_track (int *out, int code, int m, int off) |
code: 5m bits | |
static void | decode_6p_track (int *out, int code, int m, int off) |
code: 6m-2 bits | |
static void | decode_fixed_vector (float *fixed_vector, const uint16_t *pulse_hi, const uint16_t *pulse_lo, const enum Mode mode) |
Decode the algebraic codebook index to pulse positions and signs, then construct the algebraic codebook vector. | |
static void | decode_gains (const uint8_t vq_gain, const enum Mode mode, float *fixed_gain_factor, float *pitch_gain) |
Decode pitch gain and fixed gain correction factor. | |
static void | pitch_sharpening (AMRWBContext *ctx, float *fixed_vector) |
Apply pitch sharpening filters to the fixed codebook vector. | |
static float | voice_factor (float *p_vector, float p_gain, float *f_vector, float f_gain) |
Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced). | |
static float * | anti_sparseness (AMRWBContext *ctx, float *fixed_vector, float *buf) |
Reduce fixed vector sparseness by smoothing with one of three IR filters, also known as "adaptive phase dispersion". | |
static float | stability_factor (const float *isf, const float *isf_past) |
Calculate a stability factor {teta} based on distance between current and past isf. | |
static float | noise_enhancer (float fixed_gain, float *prev_tr_gain, float voice_fac, float stab_fac) |
Apply a non-linear fixed gain smoothing in order to reduce fluctuation in the energy of excitation. | |
static void | pitch_enhancer (float *fixed_vector, float voice_fac) |
Filter the fixed_vector to emphasize the higher frequencies. | |
static void | synthesis (AMRWBContext *ctx, float *lpc, float *excitation, float fixed_gain, const float *fixed_vector, float *samples) |
Conduct 16th order linear predictive coding synthesis from excitation. | |
static void | de_emphasis (float *out, float *in, float m, float mem[1]) |
Apply to synthesis a de-emphasis filter of the form: H(z) = 1 / (1 - m * z^-1). | |
static void | upsample_5_4 (float *out, const float *in, int o_size) |
Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using a FIR interpolation filter. | |
static float | find_hb_gain (AMRWBContext *ctx, const float *synth, uint16_t hb_idx, uint8_t vad) |
Calculate the high-band gain based on encoded index (23k85 mode) or on the low-band speech signal and the Voice Activity Detection flag. | |
static void | scaled_hb_excitation (AMRWBContext *ctx, float *hb_exc, const float *synth_exc, float hb_gain) |
Generate the high-band excitation with the same energy from the lower one and scaled by the given gain. | |
static float | auto_correlation (float *diff_isf, float mean, int lag) |
Calculate the auto-correlation for the ISF difference vector. | |
static void | extrapolate_isf (float isf[LP_ORDER_16k]) |
Extrapolate a ISF vector to the 16kHz range (20th order LP) used at mode 6k60 LP filter for the high frequency band. | |
static void | lpc_weighting (float *out, const float *lpc, float gamma, int size) |
Spectral expand the LP coefficients using the equation: y[i] = x[i] * (gamma ** i). | |
static void | hb_synthesis (AMRWBContext *ctx, int subframe, float *samples, const float *exc, const float *isf, const float *isf_past) |
Conduct 20th order linear predictive coding synthesis for the high frequency band excitation at 16kHz. | |
static void | hb_fir_filter (float *out, const float fir_coef[HB_FIR_SIZE+1], float mem[HB_FIR_SIZE], const float *in) |
Apply a 15th order filter to high-band samples. | |
static void | update_sub_state (AMRWBContext *ctx) |
Update context state before the next subframe. | |
static int | amrwb_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) |
Variables | |
AVCodec | ff_amrwb_decoder |
Definition in file amrwbdec.c.
#define AMR_USE_16BIT_TABLES |
Definition at line 37 of file amrwbdec.c.
#define BIT_POS | ( | x, | |||
p | ) | (((x) >> (p)) & 1) |
Get the bit at specified position.
Definition at line 343 of file amrwbdec.c.
Referenced by decode_1p_track(), decode_2p_track(), decode_3p_track(), decode_4p_track(), decode_5p_track(), and decode_6p_track().
Get x bits in the index interval [lsb,lsb+len-1] inclusive.
Definition at line 340 of file amrwbdec.c.
Referenced by decode_1p_track(), decode_2p_track(), decode_3p_track(), decode_4p_track(), decode_5p_track(), and decode_6p_track().
static int amrwb_decode_frame | ( | AVCodecContext * | avctx, | |
void * | data, | |||
int * | got_frame_ptr, | |||
AVPacket * | avpkt | |||
) | [static] |
Definition at line 1062 of file amrwbdec.c.
static av_cold int amrwb_decode_init | ( | AVCodecContext * | avctx | ) | [static] |
Definition at line 87 of file amrwbdec.c.
static float* anti_sparseness | ( | AMRWBContext * | ctx, | |
float * | fixed_vector, | |||
float * | buf | |||
) | [static] |
Reduce fixed vector sparseness by smoothing with one of three IR filters, also known as "adaptive phase dispersion".
[in] | ctx | The context |
[in,out] | fixed_vector | Unfiltered fixed vector |
[out] | buf | Space for modified vector if necessary |
Definition at line 605 of file amrwbdec.c.
static float auto_correlation | ( | float * | diff_isf, | |
float | mean, | |||
int | lag | |||
) | [static] |
Calculate the auto-correlation for the ISF difference vector.
Definition at line 879 of file amrwbdec.c.
Referenced by extrapolate_isf().
static void de_emphasis | ( | float * | out, | |
float * | in, | |||
float | m, | |||
float | mem[1] | |||
) | [static] |
Apply to synthesis a de-emphasis filter of the form: H(z) = 1 / (1 - m * z^-1).
[out] | out | Output buffer |
[in] | in | Input samples array with in[-1] |
[in] | m | Filter coefficient |
[in,out] | mem | State from last filtering |
Definition at line 785 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void decode_1p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [inline, static] |
The next six functions decode_[i]p_track decode exactly i pulses positions and amplitudes (-1 or 1) in a subframe track using an encoded pulse indexing (TS 26.190 section 5.8.2).
The results are given in out[], in which a negative number means amplitude -1 and vice versa (i.e., ampl(x) = x / abs(x) ).
[out] | out | Output buffer (writes i elements) |
[in] | code | Pulse index (no. of bits varies, see below) |
[in] | m | (log2) Number of potential positions |
[in] | off | Offset for decoded positions |
code: m+1 bits
Definition at line 358 of file amrwbdec.c.
Referenced by decode_3p_track(), decode_4p_track(), decode_6p_track(), and decode_fixed_vector().
static void decode_2p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [inline, static] |
code: 2m+1 bits
Definition at line 365 of file amrwbdec.c.
Referenced by decode_3p_track(), decode_4p_track(), decode_5p_track(), decode_6p_track(), and decode_fixed_vector().
static void decode_3p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [static] |
code: 3m+1 bits
Definition at line 375 of file amrwbdec.c.
Referenced by decode_4p_track(), decode_5p_track(), decode_6p_track(), and decode_fixed_vector().
static void decode_4p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [static] |
code: 4m bits
Definition at line 384 of file amrwbdec.c.
Referenced by decode_6p_track(), and decode_fixed_vector().
static void decode_5p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [static] |
code: 5m bits
Definition at line 420 of file amrwbdec.c.
Referenced by decode_6p_track(), and decode_fixed_vector().
static void decode_6p_track | ( | int * | out, | |
int | code, | |||
int | m, | |||
int | off | |||
) | [static] |
static void decode_fixed_vector | ( | float * | fixed_vector, | |
const uint16_t * | pulse_hi, | |||
const uint16_t * | pulse_lo, | |||
const enum Mode | mode | |||
) | [static] |
Decode the algebraic codebook index to pulse positions and signs, then construct the algebraic codebook vector.
[out] | fixed_vector | Buffer for the fixed codebook excitation |
[in] | pulse_hi | MSBs part of the pulse index array (higher modes only) |
[in] | pulse_lo | LSBs part of the pulse index array |
[in] | mode | Mode of the current frame |
Definition at line 474 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void decode_gains | ( | const uint8_t | vq_gain, | |
const enum Mode | mode, | |||
float * | fixed_gain_factor, | |||
float * | pitch_gain | |||
) | [static] |
Decode pitch gain and fixed gain correction factor.
[in] | vq_gain | Vector-quantized index for gains |
[in] | mode | Mode of the current frame |
[out] | fixed_gain_factor | Decoded fixed gain correction factor |
[out] | pitch_gain | Decoded pitch gain |
Definition at line 545 of file amrwbdec.c.
static void decode_isf_indices_36b | ( | uint16_t * | ind, | |
float * | isf_q | |||
) | [static] |
Decode quantized ISF vectors using 36-bit indexes (6K60 mode only).
[in] | ind | Array of 5 indexes |
[out] | isf_q | Buffer for isf_q[LP_ORDER] |
Definition at line 136 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void decode_isf_indices_46b | ( | uint16_t * | ind, | |
float * | isf_q | |||
) | [static] |
Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode).
[in] | ind | Array of 7 indexes |
[out] | isf_q | Buffer for isf_q[LP_ORDER] |
Definition at line 163 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static int decode_mime_header | ( | AMRWBContext * | ctx, | |
const uint8_t * | buf | |||
) | [static] |
Decode the frame header in the "MIME/storage" format.
This format is simpler and does not carry the auxiliary frame information.
[in] | ctx | The Context |
[in] | buf | Pointer to the input buffer |
Definition at line 120 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void decode_pitch_lag_high | ( | int * | lag_int, | |
int * | lag_frac, | |||
int | pitch_index, | |||
uint8_t * | base_lag_int, | |||
int | subframe | |||
) | [static] |
Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes).
Calculate integer lag and fractional lag always using 1/4 resolution. In 1st and 3rd subframes the index is relative to last subframe integer lag.
[out] | lag_int | Decoded integer pitch lag |
[out] | lag_frac | Decoded fractional pitch lag |
[in] | pitch_index | Adaptive codebook pitch index |
[in,out] | base_lag_int | Base integer lag used in relative subframes |
[in] | subframe | Current subframe index (0 to 3) |
Definition at line 239 of file amrwbdec.c.
Referenced by decode_pitch_vector().
static void decode_pitch_lag_low | ( | int * | lag_int, | |
int * | lag_frac, | |||
int | pitch_index, | |||
uint8_t * | base_lag_int, | |||
int | subframe, | |||
enum Mode | mode | |||
) | [static] |
Decode an adaptive codebook index into pitch lag for 8k85 and 6k60 modes.
The description is analogous to decode_pitch_lag_high, but in 6k60 the relative index is used for all subframes except the first.
Definition at line 272 of file amrwbdec.c.
Referenced by decode_pitch_vector().
static void decode_pitch_vector | ( | AMRWBContext * | ctx, | |
const AMRWBSubFrame * | amr_subframe, | |||
const int | subframe | |||
) | [static] |
Find the pitch vector by interpolating the past excitation at the pitch delay, which is obtained in this function.
[in,out] | ctx | The context |
[in] | amr_subframe | Current subframe data |
[in] | subframe | Current subframe index (0 to 3) |
Definition at line 301 of file amrwbdec.c.
static void extrapolate_isf | ( | float | isf[LP_ORDER_16k] | ) | [static] |
Extrapolate a ISF vector to the 16kHz range (20th order LP) used at mode 6k60 LP filter for the high frequency band.
[out] | isf | Buffer for extrapolated isf; contains LP_ORDER values on input |
Definition at line 898 of file amrwbdec.c.
Referenced by hb_synthesis().
static float find_hb_gain | ( | AMRWBContext * | ctx, | |
const float * | synth, | |||
uint16_t | hb_idx, | |||
uint8_t | vad | |||
) | [static] |
Calculate the high-band gain based on encoded index (23k85 mode) or on the low-band speech signal and the Voice Activity Detection flag.
[in] | ctx | The context |
[in] | synth | LB speech synthesis at 12.8k |
[in] | hb_idx | Gain index for mode 23k85 only |
[in] | vad | VAD flag for the frame |
Definition at line 836 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void hb_fir_filter | ( | float * | out, | |
const float | fir_coef[HB_FIR_SIZE+1], | |||
float | mem[HB_FIR_SIZE], | |||
const float * | in | |||
) | [static] |
Apply a 15th order filter to high-band samples.
The filter characteristic depends on the given coefficients.
[out] | out | Buffer for filtered output |
[in] | fir_coef | Filter coefficients |
[in,out] | mem | State from last filtering (updated) |
[in] | in | Input speech data (high-band) |
Definition at line 1025 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void hb_synthesis | ( | AMRWBContext * | ctx, | |
int | subframe, | |||
float * | samples, | |||
const float * | exc, | |||
const float * | isf, | |||
const float * | isf_past | |||
) | [static] |
Conduct 20th order linear predictive coding synthesis for the high frequency band excitation at 16kHz.
[in] | ctx | The context |
[in] | subframe | Current subframe index (0 to 3) |
[in,out] | samples | Pointer to the output speech samples |
[in] | exc | Generated white-noise scaled excitation |
[in] | isf | Current frame isf vector |
[in] | isf_past | Past frame final isf vector |
Definition at line 986 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void interpolate_isp | ( | double | isp_q[4][LP_ORDER], | |
const double * | isp4_past | |||
) | [static] |
Interpolate the fourth ISP vector from current and past frames to obtain an ISP vector for each subframe.
[in,out] | isp_q | ISPs for each subframe |
[in] | isp4_past | Past ISP for subframe 4 |
Definition at line 217 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void isf_add_mean_and_past | ( | float * | isf_q, | |
float * | isf_past | |||
) | [static] |
Apply mean and past ISF values using the prediction factor.
Updates past ISF vector.
[in,out] | isf_q | Current quantized ISF |
[in,out] | isf_past | Past quantized ISF |
Definition at line 197 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void lpc_weighting | ( | float * | out, | |
const float * | lpc, | |||
float | gamma, | |||
int | size | |||
) | [static] |
Spectral expand the LP coefficients using the equation: y[i] = x[i] * (gamma ** i).
[out] | out | Output buffer (may use input array) |
[in] | lpc | LP coefficients array |
[in] | gamma | Weighting factor |
[in] | size | LP array size |
Definition at line 964 of file amrwbdec.c.
Referenced by hb_synthesis().
static float noise_enhancer | ( | float | fixed_gain, | |
float * | prev_tr_gain, | |||
float | voice_fac, | |||
float | stab_fac | |||
) | [static] |
Apply a non-linear fixed gain smoothing in order to reduce fluctuation in the energy of excitation.
[in] | fixed_gain | Unsmoothed fixed gain |
[in,out] | prev_tr_gain | Previous threshold gain (updated) |
[in] | voice_fac | Frame voicing factor |
[in] | stab_fac | Frame stability factor |
Definition at line 693 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void pitch_enhancer | ( | float * | fixed_vector, | |
float | voice_fac | |||
) | [static] |
Filter the fixed_vector to emphasize the higher frequencies.
[in,out] | fixed_vector | Fixed codebook vector |
[in] | voice_fac | Frame voicing factor |
Definition at line 720 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void pitch_sharpening | ( | AMRWBContext * | ctx, | |
float * | fixed_vector | |||
) | [static] |
Apply pitch sharpening filters to the fixed codebook vector.
[in] | ctx | The context |
[in,out] | fixed_vector | Fixed codebook excitation |
Definition at line 563 of file amrwbdec.c.
static void scaled_hb_excitation | ( | AMRWBContext * | ctx, | |
float * | hb_exc, | |||
const float * | synth_exc, | |||
float | hb_gain | |||
) | [static] |
Generate the high-band excitation with the same energy from the lower one and scaled by the given gain.
[in] | ctx | The context |
[out] | hb_exc | Buffer for the excitation |
[in] | synth_exc | Low-band excitation used for synthesis |
[in] | hb_gain | Wanted excitation gain |
Definition at line 861 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static float stability_factor | ( | const float * | isf, | |
const float * | isf_past | |||
) | [static] |
Calculate a stability factor {teta} based on distance between current and past isf.
A value of 1 shows maximum signal stability.
Definition at line 669 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void synthesis | ( | AMRWBContext * | ctx, | |
float * | lpc, | |||
float * | excitation, | |||
float | fixed_gain, | |||
const float * | fixed_vector, | |||
float * | samples | |||
) | [static] |
Conduct 16th order linear predictive coding synthesis from excitation.
[in] | ctx | Pointer to the AMRWBContext |
[in] | lpc | Pointer to the LPC coefficients |
[out] | excitation | Buffer for synthesis final excitation |
[in] | fixed_gain | Fixed codebook gain for synthesis |
[in] | fixed_vector | Algebraic codebook vector |
[in,out] | samples | Pointer to the output samples and memory |
Definition at line 748 of file amrwbdec.c.
static void update_sub_state | ( | AMRWBContext * | ctx | ) | [static] |
Update context state before the next subframe.
Definition at line 1046 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static void upsample_5_4 | ( | float * | out, | |
const float * | in, | |||
int | o_size | |||
) | [static] |
Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using a FIR interpolation filter.
Uses past data from before *in address.
[out] | out | Buffer for interpolated signal |
[in] | in | Current signal data (length 0.8*o_size) |
[in] | o_size | Output signal length |
Definition at line 805 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
static float voice_factor | ( | float * | p_vector, | |
float | p_gain, | |||
float * | f_vector, | |||
float | f_gain | |||
) | [static] |
Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced).
[in] | p_vector,f_vector | Pitch and fixed excitation vectors |
[in] | p_gain,f_gain | Pitch and fixed gains |
Definition at line 584 of file amrwbdec.c.
Referenced by amrwb_decode_frame().
Initial value:
{ .name = "amrwb", .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_AMR_WB, .priv_data_size = sizeof(AMRWBContext), .init = amrwb_decode_init, .decode = amrwb_decode_frame, .capabilities = CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate WideBand"), .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }, }
Definition at line 1237 of file amrwbdec.c.