Go to the documentation of this file.
37 #define MIN_LSP_SEP (0.05 / (2.0 * M_PI))
40 #define NB_SUBFRAMES 3
41 #define SUBFRAME_SIZE 54
42 #define FILTER_ORDER 10
199 "Claimed bitrate and buffer size mismatch.\n");
205 "Buffer is too small for the claimed bitrate.\n");
212 "Bitrate byte is missing, guessing the bitrate from packet size.\n");
235 float denom = 2.0 / (2.0 * 8.0 + 1.0);
256 float tt = ((float)
i - 8.0 / 2.0) / 8.0;
258 for (n = -8; n <= 8; n++, idx++) {
259 float arg1 =
M_PI * 0.9 * (tt - n);
260 float arg2 =
M_PI * (tt - n);
291 for (j = 0; j < row_size; j++)
316 const float *prev,
int index)
318 static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 };
320 1.0 - lsp_interpolation_factors[
index],
331 static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 };
332 dst[0] = (1.0 - d_interpolation_factors[
index ]) * prev
333 + d_interpolation_factors[
index ] * current;
334 dst[1] = (1.0 - d_interpolation_factors[
index + 1]) * prev
335 + d_interpolation_factors[
index + 1] * current;
336 dst[2] = (1.0 - d_interpolation_factors[
index + 2]) * prev
337 + d_interpolation_factors[
index + 2] * current;
359 a[0] = k < 2 ? 0.25 : 0;
360 b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
364 b[
i + 1] =
b[
i] - 2 * lsp[
i * 2 + 1] *
b1[
i] +
b2[
i];
384 t = (
offset - delay + 0.5) * 8.0 + 0.5;
392 coef_idx = t * (2 * 8 + 1);
395 for (
i = 0;
i < 2 * 8 + 1;
i++)
405 const float delay[3],
int length)
407 float denom, locdelay, dpr, invl;
410 invl = 1.0 / ((float) length);
414 denom = (delay[1] - delay[0]) * invl;
415 for (
i = 0;
i < dpr;
i++) {
416 locdelay = delay[0] +
i * denom;
420 denom = (delay[2] - delay[1]) * invl;
422 for (
i = dpr;
i < dpr + 10;
i++) {
423 locdelay = delay[1] + (
i - dpr) * denom;
427 for (
i = 0;
i < length;
i++)
428 excitation[
i] *= gain;
435 offset = (fixed_index[3] >> 9) & 3;
437 for (
i = 0;
i < 3;
i++) {
438 pos1 = ((fixed_index[
i] & 0x7f) / 11) * 5 + ((
i +
offset) % 5);
439 pos2 = ((fixed_index[
i] & 0x7f) % 11) * 5 + ((
i +
offset) % 5);
441 cod[pos1] = (fixed_index[
i] & 0x80) ? -1.0 : 1.0;
444 cod[pos2] = -cod[pos1];
446 cod[pos2] += cod[pos1];
449 pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 +
offset) % 5);
450 pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 +
offset) % 5);
452 cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0;
453 cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0;
461 sign = (fixed_index & 0x200) ? -1.0 : 1.0;
463 pos = ((fixed_index & 0x7) * 7) + 4;
465 pos = (((fixed_index >> 3) & 0x7) * 7) + 2;
467 pos = (((fixed_index >> 6) & 0x7) * 7);
477 float *excitation,
float pitch_gain,
478 int pitch_lag,
int subframe_size)
487 pitch_gain =
av_clipf(pitch_gain, 0.2, 0.9);
489 for (
i = pitch_lag;
i < subframe_size;
i++)
490 excitation[
i] += pitch_gain * excitation[
i - pitch_lag];
505 float *memory,
int buffer_length,
float *
samples)
509 for (
i = 0;
i < buffer_length;
i++) {
512 samples[
i] -= filter_coeffs[j] * memory[j];
513 memory[j] = memory[j - 1];
515 samples[
i] -= filter_coeffs[0] * memory[0];
532 const float *coef,
float *memory,
int length)
537 for (
i = 0;
i < length;
i++) {
541 sum += coef[j] * memory[j];
542 memory[j] = memory[j - 1];
544 sum += coef[0] * memory[0];
559 { 0.0 , 0.0 , 0.0 , 0.0 },
560 { 0.0 , 0.0 , 0.57, 0.57 },
561 { 0.0 , 0.0 , 0.0 , 0.0 },
562 { 0.35, 0.50, 0.50, 0.75 },
563 { 0.20, 0.50, 0.57, 0.75 },
572 float *
out,
int idx,
const struct PfCoeff *pfc,
578 float sum1 = 0.0, sum2 = 0.0, gamma, gain;
579 float tilt = pfc->
tilt;
586 for (
i = 0;
i < length - 1;
i++)
587 sum2 +=
in[
i] *
in[
i + 1];
591 for (
i = 0;
i < length;
i++) {
592 scratch[
i] =
in[
i] - tilt * e->
last;
622 gamma =
FFMIN(gamma, 1.0);
624 for (
i = 0;
i < length;
i++) {
631 memcpy(scratch,
temp, length *
sizeof(
float));
636 for (
i = 0, sum1 = 0, sum2 = 0;
i < length;
i++) {
638 sum2 += scratch[
i] * scratch[
i];
640 gain = sum2 ? sqrt(sum1 / sum2) : 1.0;
642 for (
i = 0;
i < length;
i++)
679 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
708 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
714 for (j = 0; j < subframe_size; j++)
718 for (j = 0; j < subframe_size; j++)
726 for (j = 0; j < subframe_size; j++)
729 for (j = 0; j < subframe_size; j++)
743 int *got_frame_ptr,
AVPacket *avpkt)
748 int buf_size = avpkt->
size;
751 int i, j,
ret, error_flag = 0;
753 frame->nb_samples = 160;
833 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
851 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
868 acb_sum, idelay, subframe_size);
870 acb_sum, pitch_lag, subframe_size);
873 for (j = 0; j < subframe_size; j++)
877 for (j = 0; j < subframe_size; j++)
916 #define OFFSET(x) offsetof(EVRCContext, x)
917 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
uint16_t lsp[4]
index into LSP codebook
static evrc_packet_rate determine_bitrate(AVCodecContext *avctx, int *buf_size, const uint8_t **buf)
Determine the bitrate from the frame size and/or the first byte of the frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
static void interpolate_delay(float *dst, float current, float prev, int index)
static int decode_lspf(EVRCContext *e)
Decode the 10 vector quantized line spectral pair frequencies from the LSP transmission codes of any ...
uint64_t channel_layout
Audio channel layout.
static void fcb_excitation(EVRCContext *e, const uint16_t *codebook, float *excitation, float pitch_gain, int pitch_lag, int subframe_size)
static evrc_packet_rate buf_size2bitrate(const int buf_size)
static void residual_filter(float *output, const float *input, const float *coef, float *memory, int length)
#define AV_CH_LAYOUT_MONO
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static const float *const *const evrc_lspq_codebooks[]
This structure describes decoded (raw) audio or video data.
float pitch_back[ACB_SIZE]
static const float evrc_energy_quant[][3]
Rate 1/8 frame energy quantization.
float pitch[ACB_SIZE+FILTER_ORDER+SUBFRAME_SIZE]
uint8_t fcb_gain[3]
fixed codebook gain index
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
uint8_t tty
tty baud rate bit
static const struct PfCoeff postfilter_coeffs[5]
static double b1(void *priv, double x, double y)
static const uint8_t subframe_sizes[]
static void unpack_frame(EVRCContext *e)
Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT.
evrc_packet_rate last_valid_bitrate
static void interpolate_lsp(float *ilsp, const float *lsp, const float *prev, int index)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static void acb_excitation(EVRCContext *e, float *excitation, float gain, const float delay[3], int length)
uint16_t fcb_shape[3][4]
fixed codebook shape
uint8_t warned_buf_mismatch_bitrate
static const uint8_t *const evrc_lspq_codebooks_row_sizes[]
void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp()
uint8_t acb_gain[3]
adaptive codebook gain
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
float avg_fcb_gain
average fixed codebook gain
static int evrc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
uint8_t lpc_flag
spectral change indicator
float postfilter_fir[FILTER_ORDER]
static void bl_intrp(EVRCContext *e, float *ex, float delay)
float prev_lspf[FILTER_ORDER]
float postfilter_iir[FILTER_ORDER]
#define LIBAVUTIL_VERSION_INT
uint8_t delay_diff
delay difference for entire frame
static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
uint8_t pitch_delay
pitch delay for entire frame
const char * av_default_item_name(void *ptr)
Return the context name.
static unsigned int get_bits1(GetBitContext *s)
float interpolation_coeffs[136]
static const float estimation_delay[]
static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
EVRC-A unpacked data frame.
enum AVSampleFormat sample_fmt
audio sample format
static double b2(void *priv, double x, double y)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
int channels
number of audio channels
static const AVOption options[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
float postfilter_residual[ACB_SIZE+SUBFRAME_SIZE]
static void synthesis_filter(const float *in, const float *filter_coeffs, float *memory, int buffer_length, float *samples)
Synthesis of the decoder output signal.
#define xf(width, name, var, range_min, range_max, subs,...)
static void postfilter(EVRCContext *e, float *in, const float *coeff, float *out, int idx, const struct PfCoeff *pfc, int length)
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.
const char * name
Name of the codec implementation.
float avg_acb_gain
average adaptive codebook gain
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
float energy_vector[NB_SUBFRAMES]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
main external API structure.
static void frame_erasure(EVRCContext *e, float *samples)
Filter the word “frame” indicates either a video frame or a group of audio samples
uint8_t energy_gain
frame energy gain index
static const uint8_t evrc_lspq_nb_codebooks[]
int frame_number
Frame counter, set by libavcodec.
This structure stores compressed data.
static const double coeff[2][5]
static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
static const float pitch_gain_vq[]
float synthesis[FILTER_ORDER]
static const unsigned codebook[256][2]
static const AVClass evrcdec_class
static av_cold int evrc_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.