52 #define LSFQ_MAX 25681
58 #define LSFQ_DIFF_MIN 321
61 #define INTERPOL_LEN 11
67 #define SHARP_MIN 3277
76 #define SHARP_MAX 13017
81 #define MR_ENERGY 1018156
83 #define DECISION_NOISE 0
84 #define DECISION_INTERMEDIATE 1
85 #define DECISION_VOICE 2
112 int16_t past_quantizer_output_buf[
MA_NP + 1][10];
113 int16_t* past_quantizer_outputs[
MA_NP + 1];
116 int16_t lsp_buf[2][10];
119 int16_t quant_energy[4];
122 int16_t syn_filter_data[10];
135 int16_t past_gain_pitch[6];
138 int16_t past_gain_code[2];
163 .fc_indexes_bits = 13,
172 .fc_indexes_bits = 9,
180 return 31821 * value + 13849;
188 return (0x6996966996696996ULL >> (value >> 2)) & 1;
201 int16_t ma_predictor,
202 int16_t vq_1st, int16_t vq_2nd_low, int16_t vq_2nd_high)
205 static const uint8_t min_distance[2]={10, 5};
206 int16_t* quantizer_output = past_quantizer_outputs[
MA_NP];
208 for (i = 0; i < 5; i++) {
210 quantizer_output[i + 5] =
cb_lsp_1st[vq_1st][i + 5] + cb_lsp_2nd[vq_2nd_high][i + 5];
213 for (j = 0; j < 2; j++) {
214 for (i = 1; i < 10; i++) {
215 int diff = (quantizer_output[i - 1] - quantizer_output[i] + min_distance[j]) >> 1;
217 quantizer_output[i - 1] -=
diff;
218 quantizer_output[i ] +=
diff;
223 for (i = 0; i < 10; i++) {
225 for (j = 0; j <
MA_NP; j++)
226 sum += past_quantizer_outputs[j][i] *
cb_ma_predictor[ma_predictor][j][i];
242 int16_t* past_quantizer_outputs[
MA_NP + 1],
243 int ma_predictor_prev)
245 int16_t* quantizer_output = past_quantizer_outputs[
MA_NP];
248 for (i = 0; i < 10; i++) {
249 int tmp = lsfq[i] << 15;
251 for (k = 0; k <
MA_NP; k++)
252 tmp -= past_quantizer_outputs[k][i] *
cb_ma_predictor[ma_predictor_prev][k][i];
269 const int16_t* fc_cur,
279 for(i=0; i<subframe_size; i++)
282 out[i] -= (gain_code * fc_cur[i] + 0x2000) >> 14;
283 out[i] += (gain_code * fc_new[i] + 0x2000) >> 14;
296 if((past_gain_code[0] >> 1) > past_gain_code[1])
299 return FFMAX(past_onset-1, 0);
312 int i, low_gain_pitch_cnt, voice_decision;
314 if(past_gain_pitch[0] >= 14745)
316 else if (past_gain_pitch[0] <= 9830)
321 for(i=0, low_gain_pitch_cnt=0; i<6; i++)
322 if(past_gain_pitch[i] < 9830)
323 low_gain_pitch_cnt++;
325 if(low_gain_pitch_cnt > 2 && !onset)
328 if(!onset && voice_decision > prev_voice_decision + 1)
334 return voice_decision;
342 res += *v1++ * *v2++;
363 for (k = 0; k <
MA_NP + 1; k++) {
365 for (i = 1; i < 11; i++)
371 memcpy(ctx->
lsp[0],
lsp_init, 10 *
sizeof(int16_t));
394 int buf_size = avpkt->
size;
410 int pitch_delay_int[2];
415 int gain_before, gain_after;
422 out_frame = (int16_t*) frame->
data[0];
424 if (buf_size == 10) {
431 }
else if (buf_size == 8) {
440 for (i=0; i < buf_size; i++)
441 frame_erasure |= buf[i];
457 quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi);
463 MA_NP *
sizeof(int16_t*));
472 for (i = 0; i < 2; i++) {
473 int gain_corr_factor;
507 pitch_delay_int[i] = (pitch_delay_3x + 1) / 3;
523 switch (packet_type) {
527 fc_indexes, pulses_signs, 3, 3);
532 fc_indexes, pulses_signs, 1, 4);
545 fc + pitch_delay_int[i],
549 SUBFRAME_SIZE - pitch_delay_int[i]);
558 gain_corr_factor = 0;
564 cb_gain_2nd_6k4[gc_2nd_index][1];
569 gain_corr_factor =
FFMAX(gain_corr_factor, 1024);
570 #ifndef G729_BITEXACT
571 gain_corr_factor >>= 1;
577 cb_gain_2nd_8k[gc_2nd_index][1];
597 gain_corr_factor >>= 1;
606 ctx->
exc + i * SUBFRAME_SIZE - pitch_delay_3x / 3,
608 (pitch_delay_3x % 3) << 1,
612 ctx->
exc + i * SUBFRAME_SIZE, fc,
615 1 << 13, 14, SUBFRAME_SIZE);
622 ctx->
exc + i * SUBFRAME_SIZE,
654 ctx->
exc + i * SUBFRAME_SIZE,
662 memcpy(ctx->
syn_filter_data, synth+SUBFRAME_SIZE, 10 *
sizeof(int16_t));
667 gain_before +=
FFABS(synth[j+10]);
685 gain_after +=
FFABS(synth[j+10]);
699 memcpy(synth+8, ctx->
hpf_z, 2*
sizeof(int16_t));
701 out_frame + i*SUBFRAME_SIZE,
705 memcpy(ctx->
hpf_z, synth+8+SUBFRAME_SIZE, 2*
sizeof(int16_t));