Go to the documentation of this file.
95 for (
i = 0;
i < 10;
i++)
115 float tmp_lspf,
smooth, erasure_coeff;
116 const float *predictors;
126 for (
i = 0;
i < 10;
i++) {
142 for (
i = 0;
i < 10;
i++) {
144 lspf[
i] = (
i + 1) * (1 - erasure_coeff) / 11 +
145 erasure_coeff * predictors[
i];
152 for (
i = 1;
i < 10;
i++)
156 for (
i = 9;
i > 0;
i--)
165 for (
i = 0;
i < 5;
i++) {
172 if (lspf[9] <= .70 || lspf[9] >= .97)
174 for (
i = 3;
i < 10;
i++)
175 if (
fabs(lspf[
i] - lspf[
i - 2]) < .08)
178 if (lspf[9] <= .66 || lspf[9] >= .985)
180 for (
i = 4;
i < 10;
i++)
181 if (
fabs(lspf[
i] - lspf[
i - 4]) < .0931)
198 int i, subframes_count, g1[16];
203 case RATE_FULL: subframes_count = 16;
break;
204 case RATE_HALF: subframes_count = 4;
break;
205 default: subframes_count = 5;
207 for (
i = 0;
i < subframes_count;
i++) {
210 g1[
i] +=
av_clip((g1[
i - 1] + g1[
i - 2] + g1[
i - 3]) / 3 - 6, 0, 32);
228 gain[6] = 0.4 * gain[3] + 0.6 * gain[4];
230 gain[4] = 0.8 * gain[2] + 0.2 * gain[3];
231 gain[3] = 0.2 * gain[1] + 0.8 * gain[2];
233 gain[1] = 0.6 * gain[0] + 0.4 * gain[1];
246 case 2 : g1[0] -= 1;
break;
247 case 3 : g1[0] -= 2;
break;
256 for (
i = 1;
i <= subframes_count;
i++)
276 int i,
diff, prev_diff = 0;
278 for (
i = 1;
i < 5;
i++) {
279 diff = cbgain[
i] - cbgain[
i-1];
314 uint16_t cbseed, cindex;
315 float *
rnd, tmp_gain, fir_filter_value;
319 for (
i = 0;
i < 16;
i++) {
322 for (j = 0; j < 10; j++)
323 *cdn_vector++ = tmp_gain *
328 for (
i = 0;
i < 4;
i++) {
331 for (j = 0; j < 40; j++)
332 *cdn_vector++ = tmp_gain *
337 cbseed = (0x0003 & q->
frame.
lspv[4]) << 14 |
343 for (
i = 0;
i < 8;
i++) {
345 for (k = 0; k < 20; k++) {
346 cbseed = 521 * cbseed + 259;
347 *
rnd = (int16_t) cbseed;
350 fir_filter_value = 0.0;
351 for (j = 0; j < 10; j++)
356 *cdn_vector++ = tmp_gain * fir_filter_value;
365 for (
i = 0;
i < 8;
i++) {
367 for (j = 0; j < 20; j++) {
368 cbseed = 521 * cbseed + 259;
369 *cdn_vector++ = tmp_gain * (int16_t) cbseed;
375 for (
i = 0;
i < 4;
i++) {
377 for (j = 0; j < 40; j++)
378 *cdn_vector++ = tmp_gain *
383 memset(cdn_vector, 0, 160 *
sizeof(
float));
401 for (
i = 0;
i < 160;
i += 40) {
425 const float gain[4],
const uint8_t *lag,
426 const uint8_t pfrac[4])
429 float *v_lag, *v_out;
432 v_out = memory + 143;
434 for (
i = 0;
i < 4;
i++) {
436 v_lag = memory + 143 + 40 *
i - lag[
i];
437 for (v_len = v_in + 40; v_in < v_len; v_in++) {
439 for (j = 0, *v_out = 0.0; j < 4; j++)
441 (v_lag[j - 4] + v_lag[3 - j]);
445 *v_out = *v_in + gain[
i] * *v_out;
451 memcpy(v_out, v_in, 40 *
sizeof(
float));
457 memmove(memory, memory + 160, 143 *
sizeof(
float));
471 const float *v_synthesis_filtered, *v_pre_filtered;
478 for (
i = 0;
i < 4;
i++) {
484 float max_pitch_gain;
490 max_pitch_gain = 0.0;
493 max_pitch_gain = 1.0;
495 for (
i = 0;
i < 4;
i++)
507 for (
i = 0;
i < 4;
i++)
511 v_synthesis_filtered,
518 cdn_vector + 17, 143 *
sizeof(
float));
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);
625 "Claimed bitrate and buffer size mismatch.\n");
631 "Buffer is too small for the claimed bitrate.\n");
637 "Bitrate byte missing, guessing 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];
688 int *got_frame_ptr,
AVPacket *avpkt)
690 const uint8_t *buf = avpkt->
data;
691 int buf_size = avpkt->
size;
695 float quantized_lspf[10], lpc[10];
700 frame->nb_samples = 160;
703 outbuffer = (
float *)
frame->data[0];
720 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++) {
776 outbuffer +
i * 40, 40, 10);
#define AV_LOG_WARNING
Something somehow does not look correct.
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.
static const qcelp_vector *const qcelp_lspvq[5]
static const QCELPBitmap *const qcelp_unpacking_bitmaps_per_rate[5]
Bitmapping data position for each packet type in the QCELPContext.
uint8_t cindex[16]
codebook index for each codebook subframe
static const int16_t qcelp_rate_full_codebook[128]
Circular codebook for rate 1 frames in x*100 form.
#define QCELP_LSP_OCTAVE_PREDICTOR
Predictor coefficient for the conversion of LSP codes to LSP frequencies for 1/8 and I_F_Q.
static av_cold int qcelp_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
This structure describes decoded (raw) audio or video data.
static int qcelp_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
#define AV_CHANNEL_LAYOUT_MONO
float postfilter_synth_mem[10]
uint8_t lspv[10]
line spectral pair frequencies (LSP) for RATE_OCTAVE, line spectral pair frequencies grouped into fiv...
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
#define QCELP_SQRT1887
sqrt(1.887) is the maximum of the pseudorandom white sequence used to generate the scaled codebook ve...
AVChannelLayout ch_layout
Audio channel layout.
uint8_t index
index into the QCELPContext structure
uint8_t plag[4]
pitch lag for each pitch subframe
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)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define QCELP_LSP_SPREAD_FACTOR
This spread factor is used, for bitrate 1/8 and I_F_Q, to force LSP frequencies to be at least 80 Hz ...
#define FF_CODEC_DECODE_CB(func)
static qcelp_packet_rate buf_size2bitrate(const int buf_size)
static const uint16_t qcelp_unpacking_bitmaps_lengths[5]
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.
@ I_F_Q
insufficient frame quality
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
float rnd_fir_filter_mem[180]
static __device__ float fabs(float a)
static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.
uint8_t cbsign[16]
sign of the codebook gain for each codebook subframe
float predictor_lspf[10]
LSP predictor for RATE_OCTAVE and I_F_Q.
uint8_t warned_buf_mismatch_bitrate
static void lspf2lpc(const float *lspf, float *lpc)
Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion.
static int weight(int i, int blen, int offset)
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
uint8_t pgain[4]
pitch gain for each pitch subframe
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
qcelp_packet_rate bitrate
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
enum AVSampleFormat sample_fmt
audio sample format
uint8_t bitlen
number of bits to read
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.
QCELP unpacked data frame.
void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
Apply tilt compensation filter, 1 - tilt * z-1.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in)
Apply generic gain control.
uint8_t bitpos
position of the lowest bit in the value's byte
uint8_t octave_count
count the consecutive RATE_OCTAVE frames
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...
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.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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 const float qcelp_g12ga[61]
Table for computing Ga (decoded linear codebook gain magnitude)
const char * name
Name of the codec implementation.
float pitch_pre_filter_mem[303]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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 void compute_svector(QCELPContext *q, const float *gain, float *cdn_vector)
Compute the scaled codebook vector Cdn From INDEX and GAIN for all rates.
float postfilter_tilt_mem
main external API structure.
static void decode_gain_and_index(QCELPContext *q, float *gain)
Convert codebook transmission codes to GAIN and INDEX.
#define QCELP_BANDWIDTH_EXPANSION_COEFF
Initial coefficient to perform bandwidth expansion on LPC.
Filter the word “frame” indicates either a video frame or a group of audio samples
float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors.
int frame_number
Frame counter, set by libavcodec.
#define avpriv_request_sample(...)
QCELPFrame frame
unpacked data frame
#define QCELP_RATE_HALF_CODEBOOK_RATIO
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static float smooth(DeshakeOpenCLContext *deshake_ctx, float *gauss_kernel, int length, float max_val, AVFifo *values)
This structure stores compressed data.
const FFCodec ff_qcelp_decoder
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.
uint8_t reserved
reserved bits only present in bitrate 1, 1/4 and 1/8 packets
void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order)
Reconstruct LPC coefficients from the line spectral pair frequencies.
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.
uint8_t pfrac[4]
fractional pitch lag for each pitch subframe
uint8_t cbgain[16]
unsigned codebook gain for each codebook subframe
#define QCELP_RATE_FULL_CODEBOOK_RATIO
static void postfilter(QCELPContext *q, float *samples, float *lpc)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
float pitch_synthesis_filter_mem[303]