32 #define BITSTREAM_READER_LE
42 #define MAX_SUBFRAME_COUNT 5
72 .bits_per_frame = 160,
74 .frames_per_packet = 1,
75 .pitch_sharp_factor = 0.00,
77 .number_of_fc_indexes = 10,
78 .ma_predictor_bits = 1,
79 .vq_indexes_bits = {7, 8, 7, 7, 7},
80 .pitch_delay_bits = {9, 6},
82 .fc_index_bits = {4, 5, 4, 5, 4, 5, 4, 5, 4, 5},
88 .bits_per_frame = 152,
90 .frames_per_packet = 1,
91 .pitch_sharp_factor = 0.8,
93 .number_of_fc_indexes = 3,
94 .ma_predictor_bits = 0,
95 .vq_indexes_bits = {6, 7, 7, 7, 5},
96 .pitch_delay_bits = {8, 5, 5},
98 .fc_index_bits = {9, 9, 9},
104 .bits_per_frame = 232,
106 .frames_per_packet = 2,
107 .pitch_sharp_factor = 0.8,
109 .number_of_fc_indexes = 3,
110 .ma_predictor_bits = 0,
111 .vq_indexes_bits = {6, 7, 7, 7, 5},
112 .pitch_delay_bits = {8, 5, 5},
114 .fc_index_bits = {5, 5, 5},
120 .bits_per_frame = 296,
122 .frames_per_packet = 2,
123 .pitch_sharp_factor = 0.85,
125 .number_of_fc_indexes = 1,
126 .ma_predictor_bits = 0,
127 .vq_indexes_bits = {6, 7, 7, 7, 5},
128 .pitch_delay_bits = {8, 5, 8, 5, 5},
130 .fc_index_bits = {10},
136 1.0/(1 << 1), 1.0/(1 << 2), 1.0/(1 << 3), 1.0/(1 << 4),
137 1.0/(1 << 5), 1.0/(1 << 6), 1.0/(1 << 7), 1.0/(1 << 8),
138 1.0/(1 << 9), 1.0/(1 << 10), 1.0/(1 << 11), 1.0/(1 << 12),
139 1.0/(1 << 13), 1.0/(1 << 14), 1.0/(1 << 15), 1.0/(1 << 16)
142 static void dequant(
float *
out,
const int *idx,
const float *
const cbs[])
148 for (i = 0; i < num_vec; i++)
149 memcpy(out + stride*i, cbs[i] + stride*idx[i], stride*
sizeof(
float));
162 lsfnew[i] = lsf_history[i] * 0.33 + lsf_tmp[i] +
mean_lsf[i];
169 lsfnew[9] =
FFMIN(lsfnew[LP_FILTER_ORDER - 1], 1.3 *
M_PI);
171 memcpy(lsf_history, lsf_tmp, LP_FILTER_ORDER *
sizeof(*lsf_history));
173 for (i = 0; i < LP_FILTER_ORDER - 1; i++)
174 lsfnew[i] = cos(lsfnew[i]);
175 lsfnew[LP_FILTER_ORDER - 1] *= 6.153848 /
M_PI;
185 fixed_vector[i] += beta * fixed_vector[i - pitch_lag_int];
201 for (i = 0; i < 5; i++)
221 float t,
t0 = 1.0 / num_subfr;
224 for (i = 0; i < num_subfr; i++) {
226 lsfint[j] = lsfold[j] * (1 - t) + t * lsfnew[j];
237 static void eval_ir(
const float *Az,
int pitch_lag,
float *freq,
238 float pitch_sharp_factor)
248 memset(tmp1 + 11, 0, 37 *
sizeof(
float));
260 const float *shape,
int length)
264 memset(out, 0, length*
sizeof(
float));
265 for (i = 0; i < pulses->
n; i++)
266 for (j = pulses->
x[i]; j < length; j++)
267 out[j] += pulses->
y[i] * shape[j - pulses->
x[i]];
287 LP_FILTER_ORDER*
sizeof(
float));
293 LP_FILTER_ORDER*
sizeof(
float));
298 LP_FILTER_ORDER*
sizeof(*pole_out));
301 LP_FILTER_ORDER*
sizeof(*pole_out));
315 for (i = 0; i < 3; i++) {
316 fixed_sparse->
x[i] = 3 * (pulses[i] & 0xf) + i;
317 fixed_sparse->
y[i] = pulses[i] & 0x10 ? -1 : 1;
322 for (i = 0; i < 3; i++) {
323 fixed_sparse->
x[2*i ] = 3 * ((pulses[i] >> 4) & 0xf) + i;
324 fixed_sparse->
x[2*i + 1] = 3 * ( pulses[i] & 0xf) + i;
326 fixed_sparse->
y[2*i ] = (pulses[i] & 0x100) ? -1.0: 1.0;
328 fixed_sparse->
y[2*i + 1] =
329 (fixed_sparse->
x[2*i + 1] < fixed_sparse->
x[2*i]) ?
330 -fixed_sparse->
y[2*i ] : fixed_sparse->
y[2*i];
338 int offset = (pulses[0] & 0x200) ? 2 : 0;
341 for (i = 0; i < 3; i++) {
342 int index = (val & 0x7) * 6 + 4 - i*2;
344 fixed_sparse->
y[i] = (offset +
index) & 0x3 ? -1 : 1;
345 fixed_sparse->
x[i] =
index;
351 int pulse_subset = (pulses[0] >> 8) & 1;
353 fixed_sparse->
x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
354 fixed_sparse->
x[1] = ( pulses[0] & 15) * 3 + pulse_subset + 1;
356 fixed_sparse->
y[0] = pulses[0] & 0x200 ? -1 : 1;
357 fixed_sparse->
y[1] = -fixed_sparse->
y[0];
380 memset(ir_buf, 0, LP_FILTER_ORDER *
sizeof(
float));
385 memcpy(ctx->
lsp_history, lsf_new, LP_FILTER_ORDER *
sizeof(
float));
389 for (i = 0; i < subframe_count; i++) {
393 float pitch_gain, gain_code, avg_energy;
403 2 * ((2 + T0_frac)%3 + 1), LP_FILTER_ORDER,
427 pitch_gain, gain_code, SUBFR_SIZE);
429 pitch_gain *= 0.5 * pitch_gain;
430 pitch_gain =
FFMIN(pitch_gain, 0.4);
437 fixed_vector[j] = excitation[j] - gain_code * fixed_vector[j];
443 pAz, excitation, SUBFR_SIZE,
448 SUBFR_SIZE, LP_FILTER_ORDER);
453 memcpy(synth - LP_FILTER_ORDER, synth + frame_size - LP_FILTER_ORDER,
454 LP_FILTER_ORDER *
sizeof(
float));
457 for (i = 0; i < subframe_count; i++) {
462 &synth[i * SUBFR_SIZE], energy,
467 LP_FILTER_ORDER*
sizeof(
float));
473 (
const float[2]) {-1.99997 , 1.000000000},
474 (
const float[2]) {-1.93307352, 0.935891986},
496 "Invalid block_align: %d. Mode %s guessed based on bitrate: %"PRId64
"\n",
512 for (i = 0; i < 4; i++)
523 int *got_frame_ptr,
AVPacket *avpkt)
538 "Error processing packet: packet size (%d) too small\n",
548 samples = (
float *)frame->
data[0];
int gp_index[5]
adaptive-codebook gain indexes
void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index, const int prev_lag_int, const int subframe, int third_as_first, int resolution)
Decode the adaptive codebook index to the integer and fractional parts of the pitch lag for one subfr...
const char const char void * val
int pitch_delay[5]
pitch delay
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
This structure describes decoded (raw) audio or video data.
uint8_t vq_indexes_bits[5]
size in bits of the i-th stage vector of quantizer
ptrdiff_t const GLvoid * data
#define SUBFR_SIZE
Subframe size for all modes except 16k.
void ff_acelp_apply_order_2_transfer_function(float *out, const float *in, const float zero_coeffs[2], const float pole_coeffs[2], float gain, float mem[2], int n)
Apply an order 2 rational transfer function in-place.
static av_cold int sipr_decoder_init(AVCodecContext *avctx)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b, float weight_coeff_a, float weight_coeff_b, int length)
float implementation of weighted sum of two vectors.
static av_cold int init(AVCodecContext *avctx)
static void lsf_decode_fp(float *lsfnew, float *lsf_history, const SiprParameters *parm)
static const int8_t pulses[4]
Number of non-zero pulses in the MP-MLQ excitation.
#define SUBFRAME_COUNT_16k
#define LSFQ_DIFF_MIN
minimum LSF distance (3.2.4) 0.0391 in Q13
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static const float *const lsf_codebooks[]
float synth_buf[LP_FILTER_ORDER+5 *SUBFR_SIZE+6]
float postfilter_syn5k0[LP_FILTER_ORDER+SUBFR_SIZE *5]
uint8_t number_of_fc_indexes
float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors.
float lsf_history[LP_FILTER_ORDER_16k]
enum AVSampleFormat sample_fmt
audio sample format
Sparse representation for the algebraic codebook (fixed) vector.
uint8_t fc_index_bits[10]
size in bits of the fixed codebook indexes
void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order)
LSP to LP conversion (5.2.4 of AMR-WB)
static const float gain_cb[128][2]
#define L_INTERPOL
Number of past samples needed for excitation interpolation.
static void eval_ir(const float *Az, int pitch_lag, float *freq, float pitch_sharp_factor)
Evaluate the adaptive impulse response.
float highpass_filt_mem[2]
void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, int size, float alpha, float *gain_mem)
Adaptive gain control (as used in AMR postfiltering)
bitstream reader API header.
#define MAX_SUBFRAME_COUNT
uint8_t ma_predictor_bits
size in bits of the switched MA predictor
float lsp_history[LP_FILTER_ORDER]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t pitch_delay_bits[5]
size in bits of the adaptive-codebook index for every subframe
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const float ff_pow_0_7[10]
Table of pow(0.7,n)
const char * name
Name of the codec implementation.
const float ff_pow_0_75[10]
Table of pow(0.75,n)
#define LP_FILTER_ORDER
linear predictive coding filter order
static const uint8_t offset[127][2]
static void decode_parameters(SiprParameters *parms, GetBitContext *pgb, const SiprModeParam *p)
Extract decoding parameters from the input bitstream.
static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples)
Apply postfilter, very similar to AMR one.
uint64_t channel_layout
Audio channel layout.
audio channel layout utility functions
static void decode_frame(SiprContext *ctx, SiprParameters *params, float *out_data)
int16_t fc_indexes[5][10]
fixed-codebook indexes
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
Apply tilt compensation filter, 1 - tilt * z-1.
static const float pred[4]
Libavcodec external API header.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
void(* decode_frame)(struct SiprContext *ctx, SiprParameters *params, float *out_data)
float postfilter_mem5k0[PITCH_DELAY_MAX+LP_FILTER_ORDER]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP zero synthesis filter.
static const float mean_lsf[10]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
float postfilter_mem[PITCH_DELAY_MAX+LP_FILTER_ORDER]
static int sipr_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
GLint GLenum GLboolean GLsizei stride
common internal api header.
int gc_index[5]
fixed-codebook gain indexes
static void pitch_sharpening(int pitch_lag_int, float beta, float *fixed_vector)
Apply pitch lag to the fixed vector (AMR section 6.1.2).
static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses, SiprMode mode, int low_gain)
float excitation[L_INTERPOL+PITCH_MAX+2 *L_SUBFR_16k]
void ff_set_min_dist_lsf(float *lsf, double min_spacing, int size)
Adjust the quantized LSFs so they are increasing and not too close.
void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params, float *out_data)
void ff_sort_nearly_sorted_floats(float *vals, int len)
Sort values in ascending order.
static const SiprModeParam modes[MODE_COUNT]
uint8_t frames_per_packet
const float ff_b60_sinc[61]
b60 hamming windowed sinc function coefficients
int channels
number of audio channels
void ff_acelp_interpolatef(float *out, const float *in, const float *filter_coeffs, int precision, int frac_pos, int filter_length, int length)
Floating point version of ff_acelp_interpolate()
int ma_pred_switch
switched moving average predictor
#define AV_CH_LAYOUT_MONO
static void convolute_with_sparse(float *out, const AMRFixed *pulses, const float *shape, int length)
Evaluate the convolution of a vector with a sparse vector.
This structure stores compressed data.
uint8_t gc_index_bits
size in bits of the gain codebook indexes
const float ff_pow_0_55[10]
Table of pow(0.55,n)
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static void dequant(float *out, const int *idx, const float *const cbs[])
static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az, int num_subfr)
void ff_sipr_init_16k(SiprContext *ctx)
float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, float *prediction_error, float energy_mean, const float *pred_table)
Calculate fixed gain (part of section 6.1.3 of AMR spec)