39#define MIN_LSP_SEP (0.05 / (2.0 * M_PI))
43#define SUBFRAME_SIZE 54
44#define FILTER_ORDER 10
201 "Claimed bitrate and buffer size mismatch.\n");
207 "Buffer is too small for the claimed bitrate.\n");
214 "Bitrate byte is missing, guessing the bitrate from packet size.\n");
237 float denom = 2.0 / (2.0 * 8.0 + 1.0);
259 for (
i = 0;
i < 8;
i++) {
260 float tt = ((
float)
i - 8.0 / 2.0) / 8.0;
262 for (n = -8; n <= 8; n++, idx++) {
263 float arg1 =
M_PI * 0.9 * (tt - n);
264 float arg2 =
M_PI * (tt - n);
295 for (j = 0; j < row_size; j++)
320 const float *prev,
int index)
322 static const float lsp_interpolation_factors[] = { 0.1667, 0.5, 0.8333 };
324 1.0 - lsp_interpolation_factors[
index],
335 static const float d_interpolation_factors[] = { 0, 0.3313, 0.6625, 1, 1 };
336 dst[0] = (1.0 - d_interpolation_factors[
index ]) * prev
338 dst[1] = (1.0 - d_interpolation_factors[
index + 1]) * prev
340 dst[2] = (1.0 - d_interpolation_factors[
index + 2]) * prev
363 a[0] = k < 2 ? 0.25 : 0;
364 b[0] = k < 2 ? k < 1 ? 0.25 : -0.25 : 0;
368 b[
i + 1] =
b[
i] - 2 * lsp[
i * 2 + 1] *
b1[
i] +
b2[
i];
388 t = (
offset - delay + 0.5) * 8.0 + 0.5;
396 coef_idx = t * (2 * 8 + 1);
399 for (
i = 0;
i < 2 * 8 + 1;
i++)
409 const float delay[3],
int length)
411 float denom, locdelay, dpr, invl;
414 invl = 1.0 / ((
float) length);
418 denom = (delay[1] - delay[0]) * invl;
419 for (
i = 0;
i < dpr;
i++) {
420 locdelay = delay[0] +
i * denom;
424 denom = (delay[2] - delay[1]) * invl;
426 for (
i = dpr;
i < dpr + 10;
i++) {
427 locdelay = delay[1] + (
i - dpr) * denom;
431 for (
i = 0;
i < length;
i++)
432 excitation[
i] *= gain;
439 offset = (fixed_index[3] >> 9) & 3;
441 for (
i = 0;
i < 3;
i++) {
442 pos1 = ((fixed_index[
i] & 0x7f) / 11) * 5 + ((
i +
offset) % 5);
443 pos2 = ((fixed_index[
i] & 0x7f) % 11) * 5 + ((
i +
offset) % 5);
445 cod[pos1] = (fixed_index[
i] & 0x80) ? -1.0 : 1.0;
448 cod[pos2] = -cod[pos1];
450 cod[pos2] += cod[pos1];
453 pos1 = ((fixed_index[3] & 0x7f) / 11) * 5 + ((3 +
offset) % 5);
454 pos2 = ((fixed_index[3] & 0x7f) % 11) * 5 + ((4 +
offset) % 5);
456 cod[pos1] = (fixed_index[3] & 0x100) ? -1.0 : 1.0;
457 cod[pos2] = (fixed_index[3] & 0x80 ) ? -1.0 : 1.0;
465 sign = (fixed_index & 0x200) ? -1.0 : 1.0;
467 pos = ((fixed_index & 0x7) * 7) + 4;
469 pos = (((fixed_index >> 3) & 0x7) * 7) + 2;
471 pos = (((fixed_index >> 6) & 0x7) * 7);
481 float *excitation,
float pitch_gain,
482 int pitch_lag,
int subframe_size)
491 pitch_gain =
av_clipf(pitch_gain, 0.2, 0.9);
493 for (
i = pitch_lag;
i < subframe_size;
i++)
494 excitation[
i] += pitch_gain * excitation[
i - pitch_lag];
509 float *memory,
int buffer_length,
float *samples)
513 for (
i = 0;
i < buffer_length;
i++) {
516 samples[
i] -= filter_coeffs[j] * memory[j];
517 memory[j] = memory[j - 1];
519 samples[
i] -= filter_coeffs[0] * memory[0];
520 memory[0] = samples[
i];
536 const float *coef,
float *memory,
int length)
541 for (
i = 0;
i < length;
i++) {
545 sum += coef[j] * memory[j];
546 memory[j] = memory[j - 1];
548 sum += coef[0] * memory[0];
549 memory[0] = input[
i];
563 { 0.0 , 0.0 , 0.0 , 0.0 },
564 { 0.0 , 0.0 , 0.57, 0.57 },
565 { 0.0 , 0.0 , 0.0 , 0.0 },
566 { 0.35, 0.50, 0.50, 0.75 },
567 { 0.20, 0.50, 0.57, 0.75 },
576 float *
out,
int idx,
const struct PfCoeff *pfc,
582 float sum1 = 0.0,
sum2 = 0.0, gamma, gain;
583 float tilt = pfc->
tilt;
590 for (
i = 0;
i < length - 1;
i++)
591 sum2 += in[
i] * in[
i + 1];
595 for (
i = 0;
i < length;
i++) {
596 scratch[
i] = in[
i] - tilt * e->
last;
626 gamma =
FFMIN(gamma, 1.0);
628 for (
i = 0;
i < length;
i++) {
635 memcpy(scratch,
temp, length *
sizeof(
float));
640 for (
i = 0, sum1 = 0,
sum2 = 0;
i < length;
i++) {
641 sum1 += in[
i] * in[
i];
642 sum2 += scratch[
i] * scratch[
i];
644 gain =
sum2 ? sqrt(sum1 /
sum2) : 1.0;
646 for (
i = 0;
i < length;
i++)
683 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
712 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
718 for (j = 0; j < subframe_size; j++)
722 for (j = 0; j < subframe_size; j++)
730 for (j = 0; j < subframe_size; j++)
733 for (j = 0; j < subframe_size; j++)
742 samples += subframe_size;
747 int *got_frame_ptr,
AVPacket *avpkt)
749 const uint8_t *buf = avpkt->
data;
751 int buf_size = avpkt->
size;
754 int i, j, ret, error_flag = 0;
756 frame->nb_samples = 160;
759 samples = (
float *)
frame->data[0];
778 uint8_t *p = (uint8_t *) &e->
frame;
785 }
else if (e->
frame.
lsp[0] == 0xf &&
836 idelay[0] = idelay[1] = idelay[2] =
MIN_DELAY;
854 pitch_lag =
lrintf((idelay[1] + idelay[0]) / 2.0);
871 acb_sum, idelay, subframe_size);
873 acb_sum, pitch_lag, subframe_size);
876 for (j = 0; j < subframe_size; j++)
880 for (j = 0; j < subframe_size; j++)
893 samples += subframe_size;
910 samples = (
float *)
frame->data[0];
911 for (
i = 0;
i < 160;
i++)
919#define OFFSET(x) offsetof(EVRCContext, x)
920#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
928 .class_name =
"evrc",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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 FFCodec ff_evrc_decoder
static void postfilter(AMRContext *p, float *lpc, float *buf_out)
Perform adaptive post-filtering to enhance the quality of the speech.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
static const unsigned codebook[256][2]
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
static __device__ float fabs(float a)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Data tables for the EVRC decoder.
static const float pitch_gain_vq[]
static const float *const *const evrc_lspq_codebooks[]
static const uint8_t *const evrc_lspq_codebooks_row_sizes[]
static const uint8_t evrc_lspq_nb_codebooks[]
static const float evrc_energy_quant[][3]
Rate 1/8 frame energy quantization.
static const uint8_t subframe_sizes[]
static const float estimation_delay[]
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.
static void synthesis_filter(const float *in, const float *filter_coeffs, float *memory, int buffer_length, float *samples)
Synthesis of the decoder output signal.
static void frame_erasure(EVRCContext *e, float *samples)
static evrc_packet_rate buf_size2bitrate(const int buf_size)
static void acb_excitation(EVRCContext *e, float *excitation, float gain, const float delay[3], int length)
static void warn_insufficient_frame_quality(AVCodecContext *avctx, const char *message)
static void decode_predictor_coeffs(const float *ilspf, float *ilpc)
static void unpack_frame(EVRCContext *e)
Frame unpacking for RATE_FULL, RATE_HALF and RATE_QUANT.
static void decode_8_pulses_35bits(const uint16_t *fixed_index, float *cod)
static int decode_lspf(EVRCContext *e)
Decode the 10 vector quantized line spectral pair frequencies from the LSP transmission codes of any ...
static void bandwidth_expansion(float *coeff, const float *inbuf, float gamma)
static void residual_filter(float *output, const float *input, const float *coef, float *memory, int length)
static void interpolate_lsp(float *ilsp, const float *lsp, const float *prev, int index)
static int evrc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static void interpolate_delay(float *dst, float current, float prev, int index)
static const struct PfCoeff postfilter_coeffs[5]
static void decode_3_pulses_10bits(uint16_t fixed_index, float *cod)
static void fcb_excitation(EVRCContext *e, const uint16_t *codebook, float *excitation, float pitch_gain, int pitch_lag, int subframe_size)
static const AVClass evrcdec_class
static void bl_intrp(EVRCContext *e, float *ex, float delay)
static av_cold int evrc_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
static void postfilter(EVRCContext *e, float *in, const float *coeff, float *out, int idx, const struct PfCoeff *pfc, int length)
static struct @111144215057303131116103221376075045141373005341 current
bitstream reader API header.
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CHANNEL_LAYOUT_MONO
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_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp().
static void RENAME sum2(void *out_, const void *in1_, const void *in2_, const void *coeffp_, integer index1, integer index2, integer len)
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int64_t frame_num
Frame counter, set by libavcodec.
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
EVRC-A unpacked data frame.
uint8_t lpc_flag
spectral change indicator
uint8_t pitch_delay
pitch delay for entire frame
uint16_t lsp[4]
index into LSP codebook
uint8_t tty
tty baud rate bit
uint8_t acb_gain[3]
adaptive codebook gain
uint8_t fcb_gain[3]
fixed codebook gain index
uint8_t energy_gain
frame energy gain index
uint16_t fcb_shape[3][4]
fixed codebook shape
uint8_t delay_diff
delay difference for entire frame
float postfilter_fir[FILTER_ORDER]
float synthesis[FILTER_ORDER]
evrc_packet_rate last_valid_bitrate
float pitch[ACB_SIZE+FILTER_ORDER+SUBFRAME_SIZE]
float prev_lspf[FILTER_ORDER]
float interpolation_coeffs[136]
float postfilter_iir[FILTER_ORDER]
uint8_t warned_buf_mismatch_bitrate
float energy_vector[NB_SUBFRAMES]
float postfilter_residual[ACB_SIZE+SUBFRAME_SIZE]
float pitch_back[ACB_SIZE]
float avg_fcb_gain
average fixed codebook gain
float avg_acb_gain
average adaptive codebook gain
static const double coeff[2][5]
static double b1(void *priv, double x, double y)
static double b2(void *priv, double x, double y)
static double a2(void *priv, double x, double y)
static double a1(void *priv, double x, double y)
static const uint8_t codebooks[]