40 #define AMR_USE_16BIT_TABLES
66 float prediction_error[4];
80 float hpf_31_mem[2], hpf_400_mem[2];
112 for (i = 0; i < 4; i++)
147 for (i = 0; i < 9; i++)
148 isf_q[i] =
dico1_isf[ind[0]][i] * (1.0f / (1 << 15));
150 for (i = 0; i < 7; i++)
151 isf_q[i + 9] =
dico2_isf[ind[1]][i] * (1.0f / (1 << 15));
153 for (i = 0; i < 5; i++)
156 for (i = 0; i < 4; i++)
159 for (i = 0; i < 7; i++)
174 for (i = 0; i < 9; i++)
175 isf_q[i] =
dico1_isf[ind[0]][i] * (1.0f / (1 << 15));
177 for (i = 0; i < 7; i++)
178 isf_q[i + 9] =
dico2_isf[ind[1]][i] * (1.0f / (1 << 15));
180 for (i = 0; i < 3; i++)
181 isf_q[i] +=
dico21_isf[ind[2]][i] * (1.0f / (1 << 15));
183 for (i = 0; i < 3; i++)
184 isf_q[i + 3] +=
dico22_isf[ind[3]][i] * (1.0f / (1 << 15));
186 for (i = 0; i < 3; i++)
187 isf_q[i + 6] +=
dico23_isf[ind[4]][i] * (1.0f / (1 << 15));
189 for (i = 0; i < 3; i++)
190 isf_q[i + 9] +=
dico24_isf[ind[5]][i] * (1.0f / (1 << 15));
192 for (i = 0; i < 4; i++)
193 isf_q[i + 12] +=
dico25_isf[ind[6]][i] * (1.0f / (1 << 15));
211 isf_q[i] +=
isf_mean[i] * (1.0f / (1 << 15));
228 for (k = 0; k < 3; k++) {
231 isp_q[k][i] = (1.0 - c) * isp4_past[i] + c * isp_q[3][i];
247 uint8_t *base_lag_int,
int subframe)
249 if (subframe == 0 || subframe == 2) {
250 if (pitch_index < 376) {
251 *lag_int = (pitch_index + 137) >> 2;
252 *lag_frac = pitch_index - (*lag_int << 2) + 136;
253 }
else if (pitch_index < 440) {
254 *lag_int = (pitch_index + 257 - 376) >> 1;
255 *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) << 1;
258 *lag_int = pitch_index - 280;
262 *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0),
268 *lag_int = (pitch_index + 1) >> 2;
269 *lag_frac = pitch_index - (*lag_int << 2);
270 *lag_int += *base_lag_int;
280 uint8_t *base_lag_int,
int subframe,
enum Mode mode)
282 if (subframe == 0 || (subframe == 2 && mode !=
MODE_6k60)) {
283 if (pitch_index < 116) {
284 *lag_int = (pitch_index + 69) >> 1;
285 *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1;
287 *lag_int = pitch_index - 24;
291 *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0),
294 *lag_int = (pitch_index + 1) >> 1;
295 *lag_frac = (pitch_index - (*lag_int << 1)) << 1;
296 *lag_int += *base_lag_int;
312 int pitch_lag_int, pitch_lag_frac;
325 pitch_lag_int += pitch_lag_frac > 0;
331 pitch_lag_frac + (pitch_lag_frac > 0 ? 0 : 4),
336 if (amr_subframe->
ltp) {
340 ctx->
pitch_vector[i] = 0.18 * exc[i - 1] + 0.64 * exc[i] +
342 memcpy(exc, ctx->
pitch_vector, AMRWB_SFR_SIZE *
sizeof(
float));
347 #define BIT_STR(x,lsb,len) (((x) >> (lsb)) & ((1 << (len)) - 1))
350 #define BIT_POS(x, p) (((x) >> (p)) & 1)
369 out[0] =
BIT_POS(code, m) ? -pos : pos;
377 out[0] =
BIT_POS(code, 2*m) ? -pos0 : pos0;
378 out[1] =
BIT_POS(code, 2*m) ? -pos1 : pos1;
379 out[1] = pos0 > pos1 ? -out[1] : out[1];
384 int half_2p =
BIT_POS(code, 2*m - 1) << (m - 1);
387 m - 1, off + half_2p);
393 int half_4p, subhalf_2p;
394 int b_offset = 1 << (m - 1);
396 switch (
BIT_STR(code, 4*m - 2, 2)) {
398 half_4p =
BIT_POS(code, 4*m - 3) << (m - 1);
399 subhalf_2p =
BIT_POS(code, 2*m - 3) << (m - 2);
402 m - 2, off + half_4p + subhalf_2p);
404 m - 1, off + half_4p);
410 m - 1, off + b_offset);
416 m - 1, off + b_offset);
422 m - 1, off + b_offset);
429 int half_3p =
BIT_POS(code, 5*m - 1) << (m - 1);
432 m - 1, off + half_3p);
439 int b_offset = 1 << (m - 1);
441 int half_more =
BIT_POS(code, 6*m - 5) << (m - 1);
442 int half_other = b_offset - half_more;
444 switch (
BIT_STR(code, 6*m - 4, 2)) {
447 m - 1, off + half_more);
449 m - 1, off + half_more);
453 m - 1, off + half_other);
455 m - 1, off + half_more);
459 m - 1, off + half_other);
461 m - 1, off + half_more);
467 m - 1, off + b_offset);
482 const uint16_t *pulse_lo,
const enum Mode mode)
487 int spacing = (mode ==
MODE_6k60) ? 2 : 4;
492 for (i = 0; i < 2; i++)
496 for (i = 0; i < 4; i++)
500 for (i = 0; i < 4; i++)
504 for (i = 0; i < 2; i++)
506 for (i = 2; i < 4; i++)
510 for (i = 0; i < 4; i++)
514 for (i = 0; i < 4; i++)
516 ((int) pulse_hi[i] << 14), 4, 1);
519 for (i = 0; i < 2; i++)
521 ((int) pulse_hi[i] << 10), 4, 1);
522 for (i = 2; i < 4; i++)
524 ((int) pulse_hi[i] << 14), 4, 1);
528 for (i = 0; i < 4; i++)
530 ((int) pulse_hi[i] << 11), 4, 1);
536 for (i = 0; i < 4; i++)
538 int pos = (
FFABS(sig_pos[i][j]) - 1) * spacing + i;
540 fixed_vector[pos] += sig_pos[i][j] < 0 ? -1.0 : 1.0;
553 float *fixed_gain_factor,
float *pitch_gain)
558 *pitch_gain = gains[0] * (1.0f / (1 << 14));
559 *fixed_gain_factor = gains[1] * (1.0f / (1 << 11));
576 fixed_vector[i] -= fixed_vector[i - 1] * ctx->
tilt_coef;
580 fixed_vector[i] += fixed_vector[i - ctx->
pitch_lag_int] * 0.85;
592 float *f_vector,
float f_gain)
601 return (p_ener - f_ener) / (p_ener + f_ener);
615 float *fixed_vector,
float *buf)
631 if (ir_filter_nr < 2)
636 for (i = 0; i < 6; i++)
652 if (ir_filter_nr < 2) {
684 acc += (isf[i] - isf_past[i]) * (isf[i] - isf_past[i]);
688 return FFMAX(0.0, 1.25 - acc * 0.8 * 512);
703 float voice_fac,
float stab_fac)
705 float sm_fac = 0.5 * (1 - voice_fac) * stab_fac;
711 if (fixed_gain < *prev_tr_gain) {
712 g0 =
FFMIN(*prev_tr_gain, fixed_gain + fixed_gain *
713 (6226 * (1.0f / (1 << 15))));
715 g0 =
FFMAX(*prev_tr_gain, fixed_gain *
716 (27536 * (1.0f / (1 << 15))));
720 return sm_fac * g0 + (1 - sm_fac) * fixed_gain;
732 float cpe = 0.125 * (1 + voice_fac);
733 float last = fixed_vector[0];
735 fixed_vector[0] -= cpe * fixed_vector[1];
738 float cur = fixed_vector[i];
740 fixed_vector[i] -= cpe * (last + fixed_vector[i + 1]);
744 fixed_vector[AMRWB_SFR_SIZE - 1] -= cpe * last;
758 float fixed_gain,
const float *fixed_vector,
778 energy, AMRWB_SFR_SIZE);
798 out[0] = in[0] + m * mem[0];
801 out[i] = in[i] + out[i - 1] * m;
803 mem[0] = out[AMRWB_SFR_SIZE - 1];
818 int int_part = 0, frac_part;
821 for (j = 0; j < o_size / 5; j++) {
822 out[i] = in[int_part];
826 for (k = 1; k < 5; k++) {
859 return av_clipf((1.0 -
FFMAX(0.0, tilt)) * (1.25 - 0.25 * wsp), 0.1, 1.0);
872 const float *synth_exc,
float hb_gain)
883 energy * hb_gain * hb_gain,
895 for (i = 7; i <
LP_ORDER - 2; i++) {
896 float prod = (diff_isf[i] - mean) * (diff_isf[i - lag] - mean);
911 float diff_isf[
LP_ORDER - 2], diff_mean;
914 int i, j, i_max_corr;
916 isf[LP_ORDER_16k - 1] = isf[
LP_ORDER - 1];
920 diff_isf[i] = isf[i + 1] - isf[i];
923 for (i = 2; i < LP_ORDER - 2; i++)
924 diff_mean += diff_isf[i] * (1.0f / (LP_ORDER - 4));
928 for (i = 0; i < 3; i++) {
931 if (corr_lag[i] > corr_lag[i_max_corr])
936 for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
937 isf[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
938 - isf[i - 2 - i_max_corr];
941 est = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0;
942 scale = 0.5 * (
FFMIN(est, 7600) - isf[LP_ORDER - 2]) /
943 (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]);
945 for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++)
946 diff_isf[j] = scale * (isf[i] - isf[i - 1]);
949 for (i = 1; i < LP_ORDER_16k -
LP_ORDER; i++)
950 if (diff_isf[i] + diff_isf[i - 1] < 5.0) {
951 if (diff_isf[i] > diff_isf[i - 1]) {
952 diff_isf[i - 1] = 5.0 - diff_isf[i];
954 diff_isf[i] = 5.0 - diff_isf[i - 1];
957 for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++)
958 isf[i] = isf[i - 1] + diff_isf[j] * (1.0f / (1 << 15));
961 for (i = 0; i < LP_ORDER_16k - 1; i++)
979 for (i = 0; i <
size; i++) {
980 out[i] = lpc[i] * fac;
997 const float *exc,
const float *isf,
const float *isf_past)
1041 memcpy(data, mem, HB_FIR_SIZE *
sizeof(
float));
1047 out[i] += data[i + j] * fir_coef[j];
1050 memcpy(mem, data + AMRWB_SFR_SIZE_16k, HB_FIR_SIZE *
sizeof(
float));
1073 int *got_frame_ptr,
AVPacket *avpkt)
1079 int buf_size = avpkt->
size;
1080 int expected_fr_size, header_size;
1083 float fixed_gain_factor;
1084 float *synth_fixed_vector;
1085 float synth_fixed_gain;
1086 float voice_fac, stab_fac;
1099 buf_out = (
float *)frame->
data[0];
1109 if (buf_size < expected_fr_size) {
1111 "Frame too small (%d bytes). Truncated file?\n", buf_size);
1149 for (sub = 0; sub < 4; sub++)
1152 for (sub = 0; sub < 4; sub++) {
1179 ctx->
tilt_coef = voice_fac * 0.25 + 0.25;
1190 voice_fac, stab_fac);
1209 AMRWB_SFR_SIZE_16k);
1234 sub_buf[i] = (sub_buf[i] + hb_samples[i]) * (1.0f / (1 << 15));
1246 return expected_fr_size;
AMRWBSubFrame subframe[4]
data for subframes
AMRWBFrame frame
AMRWB parameters decoded from bitstream.
static const int16_t dico2_isf[256][7]
float samples_up[UPS_MEM_SIZE+AMRWB_SFR_SIZE]
low-band samples and memory processed for upsampling
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
AVLFG prng
random number generator for white noise excitation
static const uint8_t pulses_nb_per_mode_tr[][4]
[i][j] is the number of pulses present in track j at mode i
This structure describes decoded (raw) audio or video data.
static const int16_t qua_gain_6b[64][2]
Tables for decoding quantized gains { pitch (Q14), fixed factor (Q11) }.
static const float lpf_7_coef[31]
float * excitation
points to current excitation in excitation_buf[]
void ff_acelp_apply_order_2_transfer_function(float *out, const float *in, const float zero_coeffs[2], const float pole_coeffs[2], float gain, float mem[2], int n)
Apply an order 2 rational transfer function in-place.
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.
float fixed_gain[2]
quantified fixed gains for the current and previous subframes
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 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.
float pitch_vector[AMRWB_SFR_SIZE]
adaptive codebook (pitch) vector for current subframe
float prev_tr_gain
previous initial gain used by noise enhancer for threshold
#define UPS_FIR_SIZE
upsampling filter size
static void decode_5p_track(int *out, int code, int m, int off)
code: 5m bits
#define AMRWB_P_DELAY_MAX
maximum pitch delay value
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 decode_6p_track(int *out, int code, int m, int off)
code: 6m-2 bits
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 const int16_t dico24_isf[32][3]
static const int16_t dico23_isf[128][3]
static void isf_add_mean_and_past(float *isf_q, float *isf_past)
Apply mean and past ISF values using the prediction factor.
float isf_past_final[LP_ORDER]
final processed ISF vector of the previous frame
static const int16_t dico22_isf[128][3]
enum Mode fr_cur_mode
mode index of current frame
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) ...
uint8_t first_frame
flag active during decoding of the first frame
static void pitch_enhancer(float *fixed_vector, float voice_fac)
Filter the fixed_vector to emphasize the higher frequencies.
float tilt_coef
{beta_1} related to the voicing of the previous subframe
static const int16_t dico23_isf_36b[64][7]
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...
uint16_t vq_gain
VQ adaptive and innovative gains.
float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
Return the scalar product of two vectors.
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
enum AVSampleFormat sample_fmt
audio sample format
float lpf_7_mem[HB_FIR_SIZE]
previous values in the high-band low pass filter
static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order)
LSP to LP conversion (5.2.4 of AMR-WB)
static const int16_t isf_mean[LP_ORDER]
Means of ISF vectors in Q15.
Mode
Frame type (Table 1a in 3GPP TS 26.101)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static const float energy_pred_fac[4]
4-tap moving average prediction coefficients in reverse order
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint16_t isp_id[7]
index of ISP subvectors
#define MIN_ISF_SPACING
minimum isf gap
static const float hpf_31_gain
static const float hpf_zeros[2]
High-pass filters coefficients for 31 Hz and 400 Hz cutoff.
static const float ac_inter[65]
Coefficients for FIR interpolation of excitation vector at pitch lag resulting the adaptive codebook ...
float bpf_6_7_mem[HB_FIR_SIZE]
previous values in the high-band band pass filter
static const float bpf_6_7_coef[31]
High-band post-processing FIR filters coefficients from Q15.
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...
float isf_cur[LP_ORDER]
working ISF vector from current frame
static void decode_3p_track(int *out, int code, int m, int off)
code: 3m+1 bits
static const float hpf_31_poles[2]
uint8_t prev_ir_filter_nr
previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none
static const float isfp_inter[4]
ISF/ISP interpolation coefficients for each subframe.
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 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)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
#define AMRWB_SFR_SIZE
samples per subframe at 12.8 kHz
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...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static float voice_factor(float *p_vector, float p_gain, float *f_vector, float f_gain)
Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced).
float prev_sparse_fixed_gain
previous fixed gain; used by anti-sparseness to determine "onset"
float isf_q_past[LP_ORDER]
quantized ISF vector of the previous frame
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
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 const int16_t dico21_isf_36b[128][5]
uint64_t channel_layout
Audio channel layout.
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_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...
audio channel layout utility functions
#define MIN_ENERGY
Initial energy in dB.
float demph_mem[1]
previous value in the de-emphasis filter
double isp_sub4_past[LP_ORDER]
ISP vector for the 4th subframe of the previous frame.
static const int16_t dico21_isf[64][3]
static const float * ir_filters_lookup[2]
uint16_t pul_il[4]
LSBs part of codebook index.
static av_always_inline av_const float truncf(float x)
static const int16_t dico25_isf[32][4]
float samples_az[LP_ORDER+AMRWB_SFR_SIZE]
low-band samples and memory from synthesis at 12.8kHz
float prediction_error[4]
quantified prediction errors {20log10(^gamma_gc)} for previous four subframes
static void upsample_5_4(float *out, const float *in, int o_size)
Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using a FIR interpolation filter.
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 void decode_2p_track(int *out, int code, int m, int off)
code: 2m+1 bits
float lp_coef[4][LP_ORDER]
Linear Prediction Coefficients from ISP vector.
float pitch_gain[6]
quantified pitch gains for the current and previous five subframes
#define LP_ORDER
linear predictive coding filter order
static const uint16_t * amr_bit_orderings_by_mode[]
Reordering array addresses for each mode.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
uint16_t pul_ih[4]
MSBs part of codebook index (high modes only)
static void decode_isf_indices_46b(uint16_t *ind, float *isf_q)
Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode).
uint16_t vad
voice activity detection flag
Libavcodec external API header.
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.
#define LP_ORDER_16k
lpc filter order at 16kHz
uint16_t adap
adaptive codebook index
int sample_rate
samples per second
main external API structure.
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...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
float excitation_buf[AMRWB_P_DELAY_MAX+LP_ORDER+2+AMRWB_SFR_SIZE]
current excitation and all necessary excitation history
static const float hpf_400_poles[2]
static av_cold int amrwb_decode_init(AVCodecContext *avctx)
static const int16_t qua_gain_7b[128][2]
static const float hpf_400_gain
void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order)
Floating point version of ff_acelp_lsf2lsp()
uint8_t pitch_lag_int
integer part of pitch lag of the previous subframe
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...
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static float auto_correlation(float *diff_isf, float mean, int lag)
Calculate the auto-correlation for the ISF difference vector.
static void update_sub_state(AMRWBContext *ctx)
Update context state before the next subframe.
#define AMRWB_SFR_SIZE_16k
samples per subframe at 16 kHz
static const uint16_t cf_sizes_wb[]
Core frame sizes in each mode.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t fr_quality
frame quality index (FQI)
static const uint16_t scale[4]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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 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...
float samples_hb[LP_ORDER_16k+AMRWB_SFR_SIZE_16k]
high-band samples and memory from synthesis at 16kHz
static const float upsample_fir[4][24]
Interpolation coefficients for 5/4 signal upsampling Table from the reference source was reordered fo...
uint8_t base_pitch_lag
integer part of pitch lag for the next relative subframe
static int decode_mime_header(AMRWBContext *ctx, const uint8_t *buf)
Decode the frame header in the "MIME/storage" format.
common internal api header.
common internal and external API header
#define HB_FIR_SIZE
amount of past data needed by HB filters
uint16_t hb_gain
high-band energy index (mode 23k85 only)
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.
#define BIT_STR(x, lsb, len)
Get x bits in the index interval [lsb,lsb+len-1] inclusive.
AVSampleFormat
Audio Sample Formats.
static const int16_t dico1_isf[256][9]
Indexed tables for retrieval of quantized ISF vectors in Q15.
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 av_cold int init(AVCodecParserContext *s)
float fixed_vector[AMRWB_SFR_SIZE]
algebraic codebook (fixed) vector for current subframe
#define ENERGY_MEAN
mean innovation energy (dB) in all modes
#define PREEMPH_FAC
factor used to de-emphasize synthesis
static const int16_t dico22_isf_36b[128][4]
int channels
number of audio channels
AMR wideband data and definitions.
void ff_acelp_interpolatef(float *out, const float *in, const float *filter_coeffs, int precision, int frac_pos, int filter_length, int length)
Floating point version of ff_acelp_interpolate()
float hpf_400_mem[2]
previous values in the high pass filters
static void pitch_sharpening(AMRWBContext *ctx, float *fixed_vector)
Apply pitch sharpening filters to the fixed codebook vector.
static const int16_t isf_init[LP_ORDER]
Initialization tables for the processed ISF vector in Q15.
#define BIT_POS(x, p)
Get the bit at specified position.
static void decode_isf_indices_36b(uint16_t *ind, float *isf_q)
Decode quantized ISF vectors using 36-bit indexes (6K60 mode only).
static const uint16_t qua_hb_gain[16]
High band quantized gains for 23k85 in Q14.
#define AV_CH_LAYOUT_MONO
static void decode_4p_track(int *out, int code, int m, int off)
code: 4m bits
This structure stores compressed data.
uint16_t ltp
ltp-filtering flag
int nb_samples
number of audio samples (per channel) described by this frame
double isp[4][LP_ORDER]
ISP vectors from current frame.
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)
#define AMRWB_P_DELAY_MIN