65 float predictor_lspf[10];
66 float pitch_synthesis_filter_mem[303];
67 float pitch_pre_filter_mem[303];
68 float rnd_fir_filter_mem[180];
69 float formant_mem[170];
79 float postfilter_synth_mem[10];
96 for (i = 0; i < 10; i++)
119 float tmp_lspf, smooth, erasure_coeff;
120 const float *predictors;
130 for (i = 0; i < 10; i++) {
146 for (i = 0; i < 10; i++) {
148 lspf[i] = (i + 1) * (1 - erasure_coeff) / 11 +
149 erasure_coeff * predictors[i];
156 for (i = 1; i < 10; i++)
160 for (i = 9; i > 0; i--)
169 for (i = 0; i < 5; i++) {
176 if (lspf[9] <= .70 || lspf[9] >= .97)
178 for (i = 3; i < 10; i++)
179 if (fabs(lspf[i] - lspf[i - 2]) < .08)
182 if (lspf[9] <= .66 || lspf[9] >= .985)
184 for (i = 4; i < 10; i++)
185 if (fabs(lspf[i] - lspf[i - 4]) < .0931)
202 int i, subframes_count, g1[16];
207 case RATE_FULL: subframes_count = 16;
break;
208 case RATE_HALF: subframes_count = 4;
break;
209 default: subframes_count = 5;
211 for (i = 0; i < subframes_count; i++) {
214 g1[i] += av_clip((g1[i - 1] + g1[i - 2] + g1[i - 3]) / 3 - 6, 0, 32);
232 gain[6] = 0.4 * gain[3] + 0.6 * gain[4];
234 gain[4] = 0.8 * gain[2] + 0.2 * gain[3];
235 gain[3] = 0.2 * gain[1] + 0.8 * gain[2];
237 gain[1] = 0.6 * gain[0] + 0.4 * gain[1];
250 case 2 : g1[0] -= 1;
break;
251 case 3 : g1[0] -= 2;
break;
260 for (i = 1; i <= subframes_count; i++)
280 int i, diff, prev_diff = 0;
282 for (i = 1; i < 5; i++) {
283 diff = cbgain[i] - cbgain[i-1];
284 if (
FFABS(diff) > 10)
286 else if (
FFABS(diff - prev_diff) > 12)
318 uint16_t cbseed, cindex;
319 float *rnd, tmp_gain, fir_filter_value;
323 for (i = 0; i < 16; i++) {
326 for (j = 0; j < 10; j++)
331 for (i = 0; i < 4; i++) {
334 for (j = 0; j < 40; j++)
339 cbseed = (0x0003 & q->
frame.
lspv[4]) << 14 |
345 for (i = 0; i < 8; i++) {
347 for (k = 0; k < 20; k++) {
348 cbseed = 521 * cbseed + 259;
349 *rnd = (int16_t) cbseed;
352 fir_filter_value = 0.0;
353 for (j = 0; j < 10; j++)
355 (rnd[-j] + rnd[-20+j]);
358 *cdn_vector++ = tmp_gain * fir_filter_value;
367 for (i = 0; i < 8; i++) {
369 for (j = 0; j < 20; j++) {
370 cbseed = 521 * cbseed + 259;
371 *cdn_vector++ = tmp_gain * (int16_t) cbseed;
377 for (i = 0; i < 4; i++) {
379 for (j = 0; j < 40; j++)
384 memset(cdn_vector, 0, 160 *
sizeof(
float));
402 for (i = 0; i < 160; i += 40)
427 const float gain[4],
const uint8_t *lag,
428 const uint8_t pfrac[4])
431 float *v_lag, *v_out;
434 v_out = memory + 143;
436 for (i = 0; i < 4; i++) {
438 v_lag = memory + 143 + 40 * i - lag[i];
439 for (v_len = v_in + 40; v_in < v_len; v_in++) {
441 for (j = 0, *v_out = 0.; j < 4; j++)
446 *v_out = *v_in + gain[i] * *v_out;
452 memcpy(v_out, v_in, 40 *
sizeof(
float));
458 memmove(memory, memory + 160, 143 *
sizeof(
float));
472 const float *v_synthesis_filtered, *v_pre_filtered;
479 for (i = 0; i < 4; i++) {
485 float max_pitch_gain;
491 max_pitch_gain = 0.0;
494 max_pitch_gain = 1.0;
496 for (i = 0; i < 4; i++)
508 for (i = 0; i < 4; i++)
512 v_synthesis_filtered,
537 static void lspf2lpc(
const float *lspf,
float *lpc)
543 for (i = 0; i < 10; i++)
544 lsp[i] = cos(
M_PI * lspf[i]);
548 for (i = 0; i < 10; i++) {
549 lpc[i] *= bandwidth_expansion_coeff;
566 float *lpc,
const int subframe_num)
568 float interpolated_lspf[10];
572 weight = 0.25 * (subframe_num + 1);
580 weight, 1.0 - weight, 10);
621 if (bitrate > **buf) {
625 "Claimed bitrate and buffer size mismatch.\n");
629 }
else if (bitrate < **buf) {
631 "Buffer is too small for the claimed bitrate.\n");
637 "Bitrate byte is missing, guessing the bitrate from packet size.\n");
657 static const float pow_0_775[10] = {
658 0.775000, 0.600625, 0.465484, 0.360750, 0.279582,
659 0.216676, 0.167924, 0.130141, 0.100859, 0.078166
661 0.625000, 0.390625, 0.244141, 0.152588, 0.095367,
662 0.059605, 0.037253, 0.023283, 0.014552, 0.009095
664 float lpc_s[10], lpc_p[10], pole_out[170], zero_out[160];
667 for (n = 0; n < 10; n++) {
668 lpc_s[n] = lpc[n] * pow_0_625[n];
669 lpc_p[n] = lpc[n] * pow_0_775[n];
687 int *got_frame_ptr,
AVPacket *avpkt)
689 const uint8_t *buf = avpkt->
data;
690 int buf_size = avpkt->
size;
694 float quantized_lspf[10], lpc[10];
721 uint8_t *unpacked_data = (uint8_t *)&q->
frame;
727 for (; bitmaps < bitmaps_end; bitmaps++)
742 for (i = 0; i < 4; i++) {
773 for (i = 0; i < 4; i++) {
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
float ff_dot_productf(const float *a, const float *b, int length)
Return the dot product.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
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.
AVFrame * coded_frame
the picture in the bitstream
#define AV_LOG_WARNING
Something somehow does not look correct.
static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.
uint8_t pfrac[4]
fractional pitch lag for each pitch subframe
#define QCELP_RATE_FULL_CODEBOOK_RATIO
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
static qcelp_packet_rate buf_size2bitrate(const int buf_size)
static const int8_t qcelp_rate_half_codebook[128]
circular codebook for rate 1/2 frames in x*2 form
static const float qcelp_hammsinc_table[4]
pre-calculated table for hammsinc function Only half of the table is needed because of symmetry...
static int decode_lspf(QCELPContext *q, float *lspf)
Decode the 10 quantized LSP frequencies from the LSPV/LSP transmission codes of any bitrate and check...
uint8_t index
index into the QCELPContext structure
insufficient frame quality
uint8_t warned_buf_mismatch_bitrate
uint8_t octave_count
count the consecutive RATE_OCTAVE frames
QCELP unpacked data frame.
uint8_t cindex[16]
codebook index for each codebook subframe
static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain)
If the received packet is Rate 1/4 a further sanity check is made of the codebook gain...
enum AVSampleFormat sample_fmt
audio sample format
static const qcelp_vector *const qcelp_lspvq[5]
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.
uint8_t plag[4]
pitch lag for each pitch subframe
uint8_t cbsign[16]
sign of the codebook gain for each codebook subframe
#define QCELP_LSP_OCTAVE_PREDICTOR
predictor coefficient for the conversion of LSP codes to LSP frequencies for 1/8 and I_F_Q ...
uint8_t lspv[10]
line spectral pair frequencies (LSP) for RATE_OCTAVE, line spectral pair frequencies grouped into fiv...
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_size, const uint8_t **buf)
Determine the bitrate from the frame size and/or the first byte of the frame.
static void interpolate_lpc(QCELPContext *q, const float *curr_lspf, float *lpc, const int subframe_num)
Interpolate LSP frequencies and compute LPC coefficients for a given bitrate & pitch subframe...
static void decode_gain_and_index(QCELPContext *q, float *gain)
Convert codebook transmission codes to GAIN and INDEX.
float pitch_pre_filter_mem[303]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static const int16_t qcelp_rate_full_codebook[128]
circular codebook for rate 1 frames in x*100 form
void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in, float sum_of_squares, const int n)
Set the sum of squares of a signal by scaling.
static void compute_svector(QCELPContext *q, const float *gain, float *cdn_vector)
Compute the scaled codebook vector Cdn From INDEX and GAIN for all rates.
#define QCELP_SQRT1887
sqrt(1.887) is the maximum of the pseudorandom white sequence used to generate the scaled codebook ve...
static void postfilter(QCELPContext *q, float *samples, float *lpc)
static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
uint8_t pgain[4]
pitch gain for each pitch subframe
static av_cold int qcelp_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
QCELPFrame frame
unpacked data frame
#define QCELP_LSP_SPREAD_FACTOR
This spread factor is used, for bitrate 1/8 and I_F_Q, to force the LSP frequencies to be at least 80...
#define QCELP_BANDWIDTH_EXPANSION_COEFF
initial coefficient to perform bandwidth expansion on LPC
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
Apply tilt compensation filter, 1 - tilt * z-1.
void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order)
Reconstruct LPC coefficients from the line spectral pair frequencies.
float predictor_lspf[10]
LSP predictor for RATE_OCTAVE and I_F_Q.
Data tables for the QCELP decoder.
uint8_t bitpos
position of the lowest bit in the value's byte
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
main external API structure.
float pitch_synthesis_filter_mem[303]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t qcelp_unpacking_bitmaps_lengths[5]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
uint8_t bitlen
number of bits to read
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.
#define QCELP_RATE_HALF_CODEBOOK_RATIO
static const QCELPBitmap *const qcelp_unpacking_bitmaps_per_rate[5]
position of the bitmapping data for each packet type in the QCELPContext
uint8_t reserved
reserved bits only present in bitrate 1, 1/4 and 1/8 packets
float rnd_fir_filter_mem[180]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void lspf2lpc(const float *lspf, float *lpc)
Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion...
common internal api header.
float postfilter_synth_mem[10]
static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in)
Apply generic gain control.
qcelp_packet_rate bitrate
static const double qcelp_rnd_fir_coefs[11]
table for impulse response of BPF used to filter the white excitation for bitrate 1/4 synthesis ...
static const float * do_pitchfilter(float memory[303], const float v_in[160], const float gain[4], const uint8_t *lag, const uint8_t pfrac[4])
Apply filter in pitch-subframe steps.
int frame_number
audio or video frame number
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
float postfilter_tilt_mem
uint8_t cbgain[16]
unsigned codebook gain for each codebook subframe
static const float qcelp_g12ga[61]
table for computing Ga (decoded linear codebook gain magnitude)
int nb_samples
number of audio samples (per channel) described by this frame