45#define AMR_USE_16BIT_TABLES
61#define CN_HF_GAIN_FAC 0.25f
181 ctx->first_frame = 1;
186 for (
i = 0;
i < 4;
i++)
191 ctx->sid_period_inv = 0.25f;
197 ctx->dec_ana_elapsed = 32767;
228 ctx->fr_cur_mode = buf[0] >> 3 & 0x0F;
229 ctx->fr_quality = (buf[0] & 0x4) == 0x4;
244 for (
i = 0;
i < 9;
i++)
245 isf_q[
i] =
dico1_isf[ind[0]][
i] * (1.0f / (1 << 15));
247 for (
i = 0;
i < 7;
i++)
248 isf_q[
i + 9] =
dico2_isf[ind[1]][
i] * (1.0f / (1 << 15));
250 for (
i = 0;
i < 5;
i++)
253 for (
i = 0;
i < 4;
i++)
256 for (
i = 0;
i < 7;
i++)
270 for (
i = 0;
i < 9;
i++)
271 isf_q[
i] =
dico1_isf[ind[0]][
i] * (1.0f / (1 << 15));
273 for (
i = 0;
i < 7;
i++)
274 isf_q[
i + 9] =
dico2_isf[ind[1]][
i] * (1.0f / (1 << 15));
276 for (
i = 0;
i < 3;
i++)
279 for (
i = 0;
i < 3;
i++)
280 isf_q[
i + 3] +=
dico22_isf[ind[3]][
i] * (1.0f / (1 << 15));
282 for (
i = 0;
i < 3;
i++)
283 isf_q[
i + 6] +=
dico23_isf[ind[4]][
i] * (1.0f / (1 << 15));
285 for (
i = 0;
i < 3;
i++)
286 isf_q[
i + 9] +=
dico24_isf[ind[5]][
i] * (1.0f / (1 << 15));
288 for (
i = 0;
i < 4;
i++)
289 isf_q[
i + 12] +=
dico25_isf[ind[6]][
i] * (1.0f / (1 << 15));
323 for (k = 0; k < 3; k++) {
326 isp_q[k][
i] = (1.0 -
c) * isp4_past[
i] +
c * isp_q[3][
i];
342 uint8_t *base_lag_int,
int subframe)
344 if (subframe == 0 || subframe == 2) {
345 if (pitch_index < 376) {
346 *lag_int = (pitch_index + 137) >> 2;
347 *lag_frac = pitch_index - (*lag_int << 2) + 136;
348 }
else if (pitch_index < 440) {
349 *lag_int = (pitch_index + 257 - 376) >> 1;
350 *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) * 2;
353 *lag_int = pitch_index - 280;
357 *base_lag_int =
av_clip(*lag_int - 8 - (*lag_frac < 0),
363 *lag_int = (pitch_index + 1) >> 2;
364 *lag_frac = pitch_index - (*lag_int << 2);
365 *lag_int += *base_lag_int;
375 uint8_t *base_lag_int,
int subframe,
enum Mode mode)
378 if (pitch_index < 116) {
379 *lag_int = (pitch_index + 69) >> 1;
380 *lag_frac = (pitch_index - (*lag_int << 1) + 68) * 2;
382 *lag_int = pitch_index - 24;
386 *base_lag_int =
av_clip(*lag_int - 8 - (*lag_frac < 0),
389 *lag_int = (pitch_index + 1) >> 1;
390 *lag_frac = (pitch_index - (*lag_int << 1)) * 2;
391 *lag_int += *base_lag_int;
407 int pitch_lag_int, pitch_lag_frac;
409 float *exc =
ctx->excitation;
414 &
ctx->base_pitch_lag, subframe,
mode);
417 &
ctx->base_pitch_lag, subframe);
419 ctx->pitch_lag_int = pitch_lag_int;
420 pitch_lag_int += pitch_lag_frac > 0;
424 ctx->acelpf_ctx.acelp_interpolatef(exc,
425 exc + 1 - pitch_lag_int,
427 pitch_lag_frac + (pitch_lag_frac > 0 ? 0 : 4),
432 if (amr_subframe->
ltp) {
436 ctx->pitch_vector[
i] = 0.18 * exc[
i - 1] + 0.64 * exc[
i] +
443#define BIT_STR(x,lsb,len) av_zero_extend((x) >> (lsb), (len))
446#define BIT_POS(x, p) (((x) >> (p)) & 1)
483 m - 1, off + half_2p);
489 int half_4p, subhalf_2p;
490 int b_offset = 1 << (m - 1);
498 m - 2, off + half_4p + subhalf_2p);
500 m - 1, off + half_4p);
506 m - 1, off + b_offset);
512 m - 1, off + b_offset);
518 m - 1, off + b_offset);
528 m - 1, off + half_3p);
535 int b_offset = 1 << (m - 1);
538 int half_other = b_offset - half_more;
543 m - 1, off + half_more);
545 m - 1, off + half_more);
549 m - 1, off + half_other);
551 m - 1, off + half_more);
555 m - 1, off + half_other);
557 m - 1, off + half_more);
563 m - 1, off + b_offset);
578 const uint16_t *pulse_lo,
const enum Mode mode)
588 for (
i = 0;
i < 2;
i++)
592 for (
i = 0;
i < 4;
i++)
596 for (
i = 0;
i < 4;
i++)
600 for (
i = 0;
i < 2;
i++)
602 for (
i = 2;
i < 4;
i++)
606 for (
i = 0;
i < 4;
i++)
610 for (
i = 0;
i < 4;
i++)
612 ((
int) pulse_hi[
i] << 14), 4, 1);
615 for (
i = 0;
i < 2;
i++)
617 ((
int) pulse_hi[
i] << 10), 4, 1);
618 for (
i = 2;
i < 4;
i++)
620 ((
int) pulse_hi[
i] << 14), 4, 1);
624 for (
i = 0;
i < 4;
i++)
626 ((
int) pulse_hi[
i] << 11), 4, 1);
629 av_unreachable(
"SID and the unused frame types are handled before this "
630 "function, so only speech modes reach it");
635 for (
i = 0;
i < 4;
i++)
637 int pos = (
FFABS(sig_pos[
i][j]) - 1) * spacing +
i;
639 fixed_vector[
pos] += sig_pos[
i][j] < 0 ? -1.0 : 1.0;
652 float *fixed_gain_factor,
float *pitch_gain)
657 *pitch_gain = gains[0] * (1.0f / (1 << 14));
658 *fixed_gain_factor = gains[1] * (1.0f / (1 << 11));
675 fixed_vector[
i] -= fixed_vector[
i - 1] *
ctx->tilt_coef;
679 fixed_vector[
i] += fixed_vector[
i -
ctx->pitch_lag_int] * 0.85;
692 float *f_vector,
float f_gain,
695 double p_ener = (
double)
ctx->dot_productf(p_vector, p_vector,
698 double f_ener = (
double)
ctx->dot_productf(f_vector, f_vector,
702 return (p_ener - f_ener) / (p_ener + f_ener + 0.01);
716 float *fixed_vector,
float *buf)
723 if (
ctx->pitch_gain[0] < 0.6) {
725 }
else if (
ctx->pitch_gain[0] < 0.9) {
731 if (
ctx->fixed_gain[0] > 3.0 *
ctx->fixed_gain[1]) {
732 if (ir_filter_nr < 2)
737 for (
i = 0;
i < 6;
i++)
738 if (
ctx->pitch_gain[
i] < 0.6)
744 if (ir_filter_nr >
ctx->prev_ir_filter_nr + 1)
749 ctx->prev_ir_filter_nr = ir_filter_nr;
753 if (ir_filter_nr < 2) {
785 acc += (isf[
i] - isf_past[
i]) * (isf[
i] - isf_past[
i]);
789 return FFMAX(0.0, 1.25 - acc * 0.8 * 512);
804 float voice_fac,
float stab_fac)
806 float sm_fac = 0.5 * (1 - voice_fac) * stab_fac;
812 if (fixed_gain < *prev_tr_gain) {
813 g0 =
FFMIN(*prev_tr_gain, fixed_gain + fixed_gain *
814 (6226 * (1.0f / (1 << 15))));
816 g0 =
FFMAX(*prev_tr_gain, fixed_gain *
817 (27536 * (1.0f / (1 << 15))));
821 return sm_fac * g0 + (1 - sm_fac) * fixed_gain;
833 float cpe = 0.125 * (1 + voice_fac);
834 float last = fixed_vector[0];
836 fixed_vector[0] -= cpe * fixed_vector[1];
839 float cur = fixed_vector[
i];
841 fixed_vector[
i] -= cpe * (last + fixed_vector[
i + 1]);
859 float fixed_gain,
const float *fixed_vector,
862 ctx->acelpv_ctx.weighted_vector_sumf(excitation,
ctx->pitch_vector, fixed_vector,
868 float energy =
ctx->celpm_ctx.dot_productf(excitation, excitation,
873 float pitch_factor = 0.25 *
ctx->pitch_gain[0] *
ctx->pitch_gain[0];
876 excitation[
i] += pitch_factor *
ctx->pitch_vector[
i];
882 ctx->celpf_ctx.celp_lp_synthesis_filterf(samples, lpc, excitation,
899 out[0] = in[0] + m * mem[0];
920 int int_part = 0, frac_part;
923 for (j = 0; j < o_size / 5; j++) {
924 out[
i] = in[int_part];
928 for (k = 1; k < 5; k++) {
929 out[
i] =
ctx->dot_productf(in0 + int_part,
949 uint16_t hb_idx, uint8_t vad)
966 return av_clipf((1.0 - tilt) * (1.25 - 0.25 * wsp), 0.1, 1.0);
979 const float *synth_exc,
float hb_gain)
982 float energy =
ctx->celpm_ctx.dot_productf(synth_exc, synth_exc,
990 energy * hb_gain * hb_gain,
1003 float prod = (diff_isf[
i] -
mean) * (diff_isf[
i - lag] -
mean);
1018 float diff_isf[
LP_ORDER - 2], diff_mean;
1021 int i, j, i_max_corr;
1027 diff_isf[
i] = isf[
i + 1] - isf[
i];
1031 diff_mean += diff_isf[
i] * (1.0f / (
LP_ORDER - 4));
1035 for (
i = 0;
i < 3;
i++) {
1038 if (corr_lag[
i] > corr_lag[i_max_corr])
1044 isf[
i] = isf[
i - 1] + isf[
i - 1 - i_max_corr]
1045 - isf[
i - 2 - i_max_corr];
1048 est = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0;
1053 diff_isf[j] =
scale * (isf[
i] - isf[
i - 1]);
1057 if (diff_isf[
i] + diff_isf[
i - 1] < 5.0) {
1058 if (diff_isf[
i] > diff_isf[
i - 1]) {
1059 diff_isf[
i - 1] = 5.0 - diff_isf[
i];
1061 diff_isf[
i] = 5.0 - diff_isf[
i - 1];
1065 isf[
i] = isf[
i - 1] + diff_isf[j] * (1.0f / (1 << 15));
1087 out[
i] = lpc[
i] * fac;
1104 const float *exc,
const float *isf,
const float *isf_past)
1113 ctx->acelpv_ctx.weighted_vector_sumf(e_isf, isf_past, isf,
isfp_inter[subframe],
1143#ifndef hb_fir_filter
1171 memmove(&
ctx->pitch_gain[1], &
ctx->pitch_gain[0], 5 *
sizeof(
float));
1172 memmove(&
ctx->fixed_gain[1], &
ctx->fixed_gain[0], 1 *
sizeof(
float));
1218 int *ind,
int *en_idx)
1221 int dith, sid_update;
1238 ctx->cn_dith = dith;
1256 for (
i = 0;
i < 3;
i++) {
1261 for (
i = 0;
i < 4;
i++) {
1326 memcpy(
ctx->isf_hist[
ctx->hist_ptr], isf,
LP_ORDER *
sizeof(*isf));
1342 const int *ind,
int en_idx)
1344 float *isf =
ctx->isf_cur;
1345 float log_en, int_fac;
1350 if (
ctx->hangover_added &&
ctx->sid_frame) {
1353 memcpy(
ctx->isf_hist[ptr],
ctx->isf_hist[
ctx->hist_ptr],
1354 sizeof(
ctx->isf_hist[0]));
1355 ctx->log_en_hist[ptr] =
ctx->log_en_hist[
ctx->hist_ptr];
1357 ctx->cn_log_en = 0.0f;
1359 ctx->cn_log_en +=
ctx->log_en_hist[
i];
1369 acc +=
ctx->isf_hist[
i][j];
1374 if (
ctx->sid_frame) {
1376 ctx->cn_log_en_old =
ctx->cn_log_en;
1378 if (
ctx->valid_data) {
1379 period =
FFMIN(
ctx->since_last_sid, 32);
1380 ctx->sid_period_inv = period >= 2 ? 1.0f / period : 0.5f;
1383 ctx->cn_log_en = en_idx * (1.0f / 2.625f);
1387 memcpy(
ctx->cn_isf_old,
ctx->cn_isf,
1389 ctx->cn_log_en_old =
ctx->cn_log_en;
1397 if (
ctx->sid_frame &&
ctx->valid_data)
1398 ctx->since_last_sid = 0;
1401 int_fac =
FFMIN(
ctx->since_last_sid *
ctx->sid_period_inv, 1.0f);
1403 log_en = int_fac *
ctx->cn_log_en + (1.0f - int_fac) *
ctx->cn_log_en_old;
1405 isf[j] = int_fac *
ctx->cn_isf[j] + (1.0f - int_fac) *
ctx->cn_isf_old[j];
1417 exp2f(log_en - 2.0f),
1422 period =
ctx->since_last_sid;
1427 ctx->sid_period_inv = 1.0f / period;
1428 ctx->since_last_sid = 0;
1429 ctx->cn_log_en_old =
ctx->cn_log_en;
1433 if (
ctx->sid_frame &&
1434 (
ctx->valid_data || (!
ctx->valid_data &&
ctx->hangover_added))) {
1435 ctx->since_last_sid = 0;
1436 ctx->data_updated = 1;
1450 int new_state, enc_state;
1465 ctx->since_last_sid =
FFMIN(
ctx->since_last_sid + 1, 32767);
1473 ctx->since_last_sid = 0;
1477 ctx->dec_ana_elapsed = 0;
1479 ctx->dec_ana_elapsed =
FFMIN(
ctx->dec_ana_elapsed + 1, 32767);
1480 ctx->hangover_added = 0;
1493 ctx->hangover_added = 1;
1494 ctx->dec_ana_elapsed = 0;
1495 ctx->hangover_count = 0;
1496 }
else if (!
ctx->hangover_count) {
1497 ctx->dec_ana_elapsed = 0;
1499 ctx->hangover_count--;
1504 ctx->valid_data = 0;
1510 ctx->valid_data = 1;
1513 ctx->hangover_added = 0;
1525 memset(
ctx->excitation_buf, 0,
sizeof(
ctx->excitation_buf));
1526 memset(
ctx->isf_q_past, 0,
sizeof(
ctx->isf_q_past));
1528 ctx->first_frame = 1;
1529 ctx->prev_tr_gain = 0.0f;
1530 ctx->prev_ir_filter_nr = 0;
1531 ctx->tilt_coef = 0.0f;
1535 memset(
ctx->pitch_gain, 0,
sizeof(
ctx->pitch_gain));
1536 memset(
ctx->fixed_gain, 0,
sizeof(
ctx->fixed_gain));
1537 ctx->prev_sparse_fixed_gain = 0.0f;
1553 const float *synth_exc,
int sub, uint16_t hb_idx,
1554 uint8_t vad,
float hf_gain)
1565 ctx->acelpf_ctx.acelp_apply_order_2_transfer_function(&
ctx->samples_up[
UPS_MEM_SIZE],
1573 ctx->acelpf_ctx.acelp_apply_order_2_transfer_function(hb_samples,
1582 hb_exc,
ctx->isf_cur,
ctx->isf_past_final);
1594 sub_buf[
i] = (sub_buf[
i] + hb_samples[
i]) * (1.0f / (1 << 15));
1610 int en_idx,
float *buf_out)
1616 dtx_dec(
ctx, cn_exc, new_state, ind, en_idx);
1623 for (sub = 1; sub < 4; sub++)
1624 memcpy(
ctx->lp_coef[sub],
ctx->lp_coef[0],
sizeof(
ctx->lp_coef[0]));
1628 ctx->pitch_gain[0] = 0.0f;
1630 for (sub = 0; sub < 4; sub++) {
1647 ctx->dtx_state = new_state;
1651 int *got_frame_ptr,
AVPacket *avpkt)
1654 const uint8_t *buf = avpkt->
data;
1655 int buf_size = avpkt->
size;
1666 int expected_fr_size, header_size, rx_type, new_state;
1668 float fixed_gain_factor;
1669 float *synth_fixed_vector;
1670 float synth_fixed_gain;
1671 float voice_fac, stab_fac;
1673 int sid_ind[5] = { 0 };
1675 float frame_exc_energy = 0.0f;
1676 float *buf_out = (
float *)
frame->extended_data[ch];
1679 expected_fr_size = ((
cf_sizes_wb[
ctx->fr_cur_mode] + 7) >> 3) + 1;
1681 if (!
ctx->fr_quality)
1684 if (buf_size < expected_fr_size) {
1686 "Frame too small (%d bytes). Truncated file?\n", buf_size);
1692 if (
ctx->fr_quality) {
1707 }
else if (!
ctx->fr_quality) {
1717 (
float *)
frame->extended_data[ch]);
1718 buf += expected_fr_size;
1719 buf_size -= expected_fr_size;
1730 buf += expected_fr_size;
1731 buf_size -= expected_fr_size;
1753 if (
ctx->first_frame) {
1754 ctx->first_frame = 0;
1755 memcpy(
ctx->isp_sub4_past,
ctx->isp[3],
LP_ORDER *
sizeof(
double));
1759 for (sub = 0; sub < 4; sub++)
1762 for (sub = 0; sub < 4; sub++) {
1770 cur_subframe->
pul_il,
ctx->fr_cur_mode);
1775 &fixed_gain_factor, &
ctx->pitch_gain[0]);
1777 ctx->fixed_gain[0] =
1779 ctx->celpm_ctx.dot_productf(
ctx->fixed_vector,
1783 ctx->prediction_error,
1788 ctx->fixed_vector,
ctx->fixed_gain[0],
1790 ctx->tilt_coef = voice_fac * 0.25 + 0.25;
1794 ctx->excitation[
i] *=
ctx->pitch_gain[0];
1795 ctx->excitation[
i] +=
ctx->fixed_gain[0] *
ctx->fixed_vector[
i];
1801 frame_exc_energy +=
ctx->celpm_ctx.dot_productf(
ctx->excitation,
1806 voice_fac, stab_fac);
1822 memcpy(
ctx->isf_past_final,
ctx->isf_cur,
LP_ORDER *
sizeof(
float));
1828 if (
ctx->fr_quality) {
1830 }
else if (
ctx->vad_hist > 0)
1832 ctx->dtx_state = new_state;
1833 buf += expected_fr_size;
1834 buf_size -= expected_fr_size;
1839 return buf - avpkt->
data;
av_cold void ff_acelp_filter_init(ACELPFContext *c)
Initialize ACELPFContext.
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)
av_cold void ff_acelp_vectors_init(ACELPVContext *c)
Initialize ACELPVContext.
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.
const FFCodec ff_amrwb_decoder
static const float *const ir_filters_lookup[2]
#define DTX_MAX_EMPTY_THRESH
Mode
Frame type (Table 1a in 3GPP TS 26.101)
#define DTX_ELAPSED_FRAMES_THRESH
static const float energy_pred_fac[4]
4-tap moving average prediction coefficients in reverse order
RXFrameType
Received frame types used by the comfort noise (DTX) state machine.
#define MIN_ENERGY
Initial energy in dB.
DTXState
States of the comfort noise (DTX) state machine.
AMR wideband data and definitions.
static const int16_t dico24_isf[32][3]
static const int16_t mean_isf_noise[16]
Means of ISF vectors for background noise in Q15.
static const int16_t qua_gain_7b[128][2]
static const int16_t dico5_isf_noise[32][4]
#define CN_LOG_EN_HIST_INIT
initial value of the energy history
static const uint16_t qua_hb_gain[16]
High band quantized gains for 23k85 in Q14.
#define MIN_ISF_SPACING
minimum isf gap
static const float hpf_zeros[2]
High-pass filters coefficients for 31 Hz and 400 Hz cutoff.
static const float lpf_7_coef[31]
static const int16_t dico1_isf[256][9]
Indexed tables for retrieval of quantized ISF vectors in Q15.
#define HB_FIR_SIZE
amount of past data needed by HB filters
static const uint16_t *const amr_bit_orderings_by_mode[]
Reordering array addresses for each mode.
static const int16_t isf_mean[LP_ORDER]
Means of ISF vectors in Q15.
static const float hpf_31_poles[2]
@ MODE_SID
comfort noise frame
static const int16_t dico25_isf[32][4]
#define AMRWB_P_DELAY_MIN
static const int16_t qua_gain_6b[64][2]
Tables for decoding quantized gains { pitch (Q14), fixed factor (Q11) }.
static const int16_t dico4_isf_noise[32][4]
#define AMRWB_P_DELAY_MAX
maximum pitch delay value
static const float hpf_400_gain
#define CN_DITH_GAIN_FAC
energy dithering factor
static const int16_t dico21_isf[64][3]
static const int16_t isf_init[LP_ORDER]
Initialization tables for the processed ISF vector in Q15.
#define UPS_FIR_SIZE
upsampling filter size
static const float hpf_31_gain
static const int16_t dico23_isf_36b[64][7]
static const int16_t dico2_isf[256][7]
static const uint16_t cf_sizes_wb[]
Core frame sizes in each mode.
#define ISF_DITH_FAC_STEP
ISF dithering factor increment.
static const float ac_inter[65]
Coefficients for FIR interpolation of excitation vector at pitch lag resulting the adaptive codebook ...
static const float hpf_400_poles[2]
static const float bpf_6_7_coef[31]
High-band post-processing FIR filters coefficients from Q15.
#define LP_ORDER
linear predictive coding filter order
#define CN_LOG_EN_MUTE_STEP
log2 energy decrease per muted frame (-3/8 dB)
#define CN_NOISE_SEED_INIT
initial seed of the comfort noise generator
#define PREEMPH_FAC
factor used to de-emphasize synthesis
static const float upsample_fir[4][24]
Interpolation coefficients for 5/4 signal upsampling Table from the reference source was reordered fo...
#define CN_LOG_EN_INIT
initial comfort noise log2 energy
#define ENERGY_MEAN
mean innovation energy (dB) in all modes
#define ISF_DITH_GAP
minimum ISF gap used by comfort noise dithering
static const int16_t dico21_isf_36b[128][5]
static const int16_t dico1_isf_noise[64][2]
Indexed tables for retrieval of quantized background noise ISF vectors in Q15 (split-by-5 VQ: 2+3+3+4...
static const int16_t dico2_isf_noise[64][3]
#define AMRWB_SFR_SIZE_16k
samples per subframe at 16 kHz
static const int16_t dico3_isf_noise[64][3]
static const int16_t dico22_isf[128][3]
static const int16_t dico23_isf[128][3]
static const float isfp_inter[4]
ISF/ISP interpolation coefficients for each subframe.
#define ISF_DITH_FAC_LOW
lowest ISF dithering factor
#define LP_ORDER_16k
lpc filter order at 16kHz
static const int16_t dico22_isf_36b[128][4]
static const uint8_t pulses_nb_per_mode_tr[][4]
[i][j] is the number of pulses present in track j at mode i
#define AMRWB_SFR_SIZE
samples per subframe at 12.8 kHz
static int decode_sid_frame(AMRWBContext *ctx, const uint8_t *buf, int *ind, int *en_idx)
Decode the comfort noise parameters of a SID frame.
static void decode_gains(const uint8_t vq_gain, const enum Mode mode, float *fixed_gain_factor, float *pitch_gain)
Decode pitch gain and fixed gain correction factor.
static void dtx_dec(AMRWBContext *ctx, float *cn_exc, int new_state, const int *ind, int en_idx)
Update the comfort noise state and generate the excitation of the comfort noise for this frame.
static void extrapolate_isf(float isf[LP_ORDER_16k])
Extrapolate a ISF vector to the 16kHz range (20th order LP) used at mode 6k60 LP filter for the high ...
static void update_sub_state(AMRWBContext *ctx)
Update context state before the next subframe.
#define CN_HF_GAIN_FAC
High band gain of the comfort noise relative to the low band one.
static void decode_6p_track(int *out, int code, int m, int off)
code: 6m-2 bits
@ RX_SPEECH_PROBABLY_DEGRADED
static void decode_pitch_vector(AMRWBContext *ctx, const AMRWBSubFrame *amr_subframe, const int subframe)
Find the pitch vector by interpolating the past excitation at the pitch delay, which is obtained in t...
static void decode_1p_track(int *out, int code, int m, int off)
The next six functions decode_[i]p_track decode exactly i pulses positions and amplitudes (-1 or 1) i...
static void isf_add_mean_and_past(float *isf_q, float *isf_past)
Apply mean and past ISF values using the prediction factor.
static void upsample_5_4(float *out, const float *in, int o_size, CELPMContext *ctx)
Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using a FIR interpolation filter.
static void scaled_hb_excitation(AMRWBContext *ctx, float *hb_exc, const float *synth_exc, float hb_gain)
Generate the high-band excitation with the same energy from the lower one and scaled by the given gai...
static void cn_frame(AMRWBContext *ctx, int new_state, const int *ind, int en_idx, float *buf_out)
Decode one frame of comfort noise into the output buffer.
static void cn_reset_speech_state(AMRWBContext *ctx)
Reset the speech decoder state, it is not used during a silent period.
static float stability_factor(const float *isf, const float *isf_past)
Calculate a stability factor {teta} based on distance between current and past isf.
static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index, uint8_t *base_lag_int, int subframe, enum Mode mode)
Decode an adaptive codebook index into pitch lag for 8k85 and 6k60 modes.
static void cn_dithering(AMRWBContext *ctx, float *isf, float *log_en)
Insert comfort noise dithering, used when the background noise is not stationary.
static float voice_factor(float *p_vector, float p_gain, float *f_vector, float f_gain, CELPMContext *ctx)
Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced).
static void decode_isf_indices_36b(uint16_t *ind, float *isf_q)
Decode quantized ISF vectors using 36-bit indexes (6K60 mode only).
static void pitch_enhancer(float *fixed_vector, float voice_fac)
Filter the fixed_vector to emphasize the higher frequencies.
static void decode_fixed_vector(float *fixed_vector, const uint16_t *pulse_hi, const uint16_t *pulse_lo, const enum Mode mode)
Decode the algebraic codebook index to pulse positions and signs, then construct the algebraic codebo...
static int16_t noise_gen_amrwb(int16_t *seed)
Comfort noise (DTX) generation, see 3GPP TS 26.192.
static void interpolate_isp(double isp_q[4][LP_ORDER], const double *isp4_past)
Interpolate the fourth ISP vector from current and past frames to obtain an ISP vector for each subfr...
static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index, uint8_t *base_lag_int, int subframe)
Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes).
static float cn_dither_noise(AMRWBContext *ctx)
Draw a dithering value in [-1, 1] from the comfort noise generator.
static int dtx_handler(AMRWBContext *ctx, int frame_type)
Update the comfort noise state machine for a received frame.
static void hb_synthesis(AMRWBContext *ctx, int subframe, float *samples, const float *exc, const float *isf, const float *isf_past)
Conduct 20th order linear predictive coding synthesis for the high frequency band excitation at 16kHz...
static av_cold int amrwb_decode_init(AVCodecContext *avctx)
static float noise_enhancer(float fixed_gain, float *prev_tr_gain, float voice_fac, float stab_fac)
Apply a non-linear fixed gain smoothing in order to reduce fluctuation in the energy of excitation.
#define BIT_POS(x, p)
Get the bit at specified position.
#define BIT_STR(x, lsb, len)
Get x bits in the index interval [lsb,lsb+len-1] inclusive.
static int decode_mime_header(AMRWBContext *ctx, const uint8_t *buf)
Decode the frame header in the "MIME/storage" format.
static void subframe_output(AMRWBContext *ctx, float *sub_buf, const float *synth_exc, int sub, uint16_t hb_idx, uint8_t vad, float hf_gain)
Post-process one synthesized subframe, generate the high frequency band and store the result at 16 kH...
static void decode_isf_noise(const int *ind, float *isf_q)
Decode the quantized background noise ISF vector of a SID frame.
static void decode_4p_track(int *out, int code, int m, int off)
code: 4m bits
static int amrwb_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static void hb_fir_filter(float *out, const float fir_coef[HB_FIR_SIZE+1], float mem[HB_FIR_SIZE], const float *in)
Apply a 15th order filter to high-band samples.
static float auto_correlation(float *diff_isf, float mean, int lag)
Calculate the auto-correlation for the ISF difference vector.
static void lpc_weighting(float *out, const float *lpc, float gamma, int size)
Spectral expand the LP coefficients using the equation: y[i] = x[i] * (gamma ** i)
static void decode_isf_indices_46b(uint16_t *ind, float *isf_q)
Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode).
static float * anti_sparseness(AMRWBContext *ctx, float *fixed_vector, float *buf)
Reduce fixed vector sparseness by smoothing with one of three IR filters, also known as "adaptive pha...
static void de_emphasis(float *out, float *in, float m, float mem[1])
Apply to synthesis a de-emphasis filter of the form: H(z) = 1 / (1 - m * z^-1)
static void synthesis(AMRWBContext *ctx, float *lpc, float *excitation, float fixed_gain, const float *fixed_vector, float *samples)
Conduct 16th order linear predictive coding synthesis from excitation.
static void decode_5p_track(int *out, int code, int m, int off)
code: 5m bits
static float find_hb_gain(AMRWBContext *ctx, const float *synth, uint16_t hb_idx, uint8_t vad)
Calculate the high-band gain based on encoded index (23k85 mode) or on the low-band speech signal and...
static void pitch_sharpening(AMRWBContext *ctx, float *fixed_vector)
Apply pitch sharpening filters to the fixed codebook vector.
static void decode_3p_track(int *out, int code, int m, int off)
code: 3m+1 bits
static void decode_2p_track(int *out, int code, int m, int off)
code: 2m+1 bits
static void dtx_activity_update(AMRWBContext *ctx, const float *isf, float exc_energy)
Store the ISF vector and the excitation energy of a speech frame so that the first SID frame of a sil...
Reference: libavcodec/amrwbdec.c.
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
void ff_celp_circ_addf(float *out, const float *in, const float *lagged, int lag, float fac, int n)
Add an array to a rotated array.
void av_cold ff_celp_filter_init(CELPFContext *c)
Initialize CELPFContext.
av_cold void ff_celp_math_init(CELPMContext *c)
Initialize CELPMContext.
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
common internal and external API header
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static __device__ float truncf(float a)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
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.
#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 AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_FLTP
float, planar
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static void ff_amr_bit_reorder(uint16_t *out, int size, const uint8_t *data, const R_TABLE_TYPE *ord_table)
Fill the frame structure variables from bitstream by parsing the given reordering table that uses the...
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp()
void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order)
LSP to LP conversion (5.2.4 of AMR-WB)
CELPMContext celpm_ctx
context for fixed point math operations
int since_last_sid
frames since the last SID update
float cn_isf[LP_ORDER]
comfort noise ISF vector of the last SID
uint8_t base_pitch_lag
integer part of pitch lag for the next relative subframe
int cn_dith
comfort noise dithering flag from the last SID
int valid_data
the CN parameters of this frame may be used
int vad_hist
consecutive frames without voice activity
uint8_t first_frame
flag active during decoding of the first frame
int hist_ptr
next position to write in the DTX history
float prev_sparse_fixed_gain
previous fixed gain; used by anti-sparseness to determine "onset"
int16_t cn_dither_seed
comfort noise dithering seed
CELPFContext celpf_ctx
context for filters for CELP-based codecs
float isf_past_final[LP_ORDER]
final processed ISF vector of the previous frame
int dtx_state
current DTX state (SPEECH, DTX or DTX_MUTE)
float cn_isf_old[LP_ORDER]
comfort noise ISF vector before the last SID
ACELPFContext acelpf_ctx
context for filters for ACELP-based codecs
AMRWBFrame frame
AMRWB parameters decoded from bitstream.
float log_en_hist[DTX_HIST_SIZE]
energy history used when a SID frame starts DTX
float samples_az[LP_ORDER+AMRWB_SFR_SIZE]
low-band samples and memory from synthesis at 12.8kHz
float pitch_gain[6]
quantified pitch gains for the current and previous five subframes
int hangover_count
remaining DTX hangover frames
float cn_log_en_old
comfort noise log2 energy before the last SID
float isf_q_past[LP_ORDER]
quantized ISF vector of the previous frame
ACELPVContext acelpv_ctx
context for vector operations for ACELP-based codecs
float excitation_buf[AMRWB_P_DELAY_MAX+LP_ORDER+2+AMRWB_SFR_SIZE]
current excitation and all necessary excitation history
float sid_period_inv
inverse of the SID update period
float fixed_vector[AMRWB_SFR_SIZE]
algebraic codebook (fixed) vector for current subframe
float hpf_400_mem[2]
previous values in the high pass filters
int dec_ana_elapsed
frames since the last DTX hangover
int hangover_added
a DTX hangover was assumed for this frame
float cn_log_en
comfort noise log2 energy of the last SID
float bpf_6_7_mem[HB_FIR_SIZE]
previous values in the high-band band pass filter
AVLFG prng
random number generator for white noise excitation
int sid_frame
the current frame carries CN parameters
float lpf_7_mem[HB_FIR_SIZE]
previous values in the high-band low pass filter
float * excitation
points to current excitation in excitation_buf[]
float prev_tr_gain
previous initial gain used by noise enhancer for threshold
uint8_t fr_quality
frame quality index (FQI)
float samples_hb[LP_ORDER_16k+AMRWB_SFR_SIZE_16k]
high-band samples and memory from synthesis at 16kHz
double isp[4][LP_ORDER]
ISP vectors from current frame.
uint8_t pitch_lag_int
integer part of pitch lag of the previous subframe
uint8_t prev_ir_filter_nr
previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none
enum Mode fr_cur_mode
mode index of current frame
float isf_hist[DTX_HIST_SIZE][LP_ORDER]
ISF history used when a SID frame starts DTX.
float prediction_error[4]
quantified prediction errors {20log10(^gamma_gc)} for previous four subframes
float tilt_coef
{beta_1} related to the voicing of the previous subframe
int16_t cn_seed
comfort noise generator seed
double isp_sub4_past[LP_ORDER]
ISP vector for the 4th subframe of the previous frame.
float pitch_vector[AMRWB_SFR_SIZE]
adaptive codebook (pitch) vector for current subframe
float lp_coef[4][LP_ORDER]
Linear Prediction Coefficients from ISP vector.
float demph_mem[1]
previous value in the de-emphasis filter
int data_updated
CN parameters have been renewed at least once.
float fixed_gain[2]
quantified fixed gains for the current and previous subframes
float isf_cur[LP_ORDER]
working ISF vector from current frame
float samples_up[UPS_MEM_SIZE+AMRWB_SFR_SIZE]
low-band samples and memory processed for upsampling
uint16_t isp_id[7]
index of ISP subvectors
uint16_t vad
voice activity detection flag
AMRWBSubFrame subframe[4]
data for subframes
uint16_t adap
adaptive codebook index
uint16_t vq_gain
VQ adaptive and innovative gains.
uint16_t hb_gain
high-band energy index (mode 23k85 only)
uint16_t ltp
ltp-filtering flag
uint16_t pul_il[4]
LSBs part of codebook index.
uint16_t pul_ih[4]
MSBs part of codebook index (high modes only)
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.
static float mean(const float *input, int size)