Mercurial > libavcodec.hg
annotate acelp_pitch_delay.c @ 11458:bf6d274fef39 libavcodec
sparc: fix a few pages of cast warnings
author | mru |
---|---|
date | Wed, 10 Mar 2010 22:24:46 +0000 |
parents | dd2b69794909 |
children |
rev | line source |
---|---|
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
1 /* |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
2 * gain code, gain pitch and pitch delay decoding |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
3 * |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
4 * Copyright (c) 2008 Vladimir Voroshilov |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
5 * |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
6 * This file is part of FFmpeg. |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
7 * |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
12 * |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
17 * |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
21 */ |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
22 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
23 #include "avcodec.h" |
8505
c8743c33eeef
Remove duplicated dot product code. Use dsputil's
reynaldo
parents:
8048
diff
changeset
|
24 #include "dsputil.h" |
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
25 #include "acelp_pitch_delay.h" |
8048
ecb1962c12f3
Rename acelp_math.[ch] to celp_math.[ch] to prepare for QCELP decoder merge.
diego
parents:
7186
diff
changeset
|
26 #include "celp_math.h" |
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
27 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
28 int ff_acelp_decode_8bit_to_1st_delay3(int ac_index) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
29 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
30 ac_index += 58; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
31 if(ac_index > 254) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
32 ac_index = 3 * ac_index - 510; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
33 return ac_index; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
34 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
35 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
36 int ff_acelp_decode_4bit_to_2nd_delay3( |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
37 int ac_index, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
38 int pitch_delay_min) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
39 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
40 if(ac_index < 4) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
41 return 3 * (ac_index + pitch_delay_min); |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
42 else if(ac_index < 12) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
43 return 3 * pitch_delay_min + ac_index + 6; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
44 else |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
45 return 3 * (ac_index + pitch_delay_min) - 18; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
46 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
47 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
48 int ff_acelp_decode_5_6_bit_to_2nd_delay3( |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
49 int ac_index, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
50 int pitch_delay_min) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
51 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
52 return 3 * pitch_delay_min + ac_index - 2; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
53 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
54 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
55 int ff_acelp_decode_9bit_to_1st_delay6(int ac_index) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
56 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
57 if(ac_index < 463) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
58 return ac_index + 105; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
59 else |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
60 return 6 * (ac_index - 368); |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
61 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
62 int ff_acelp_decode_6bit_to_2nd_delay6( |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
63 int ac_index, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
64 int pitch_delay_min) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
65 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
66 return 6 * pitch_delay_min + ac_index - 3; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
67 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
68 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
69 void ff_acelp_update_past_gain( |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
70 int16_t* quant_energy, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
71 int gain_corr_factor, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
72 int log2_ma_pred_order, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
73 int erasure) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
74 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
75 int i; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
76 int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
77 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
78 for(i=(1 << log2_ma_pred_order) - 1; i>0; i--) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
79 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
80 avg_gain += quant_energy[i-1]; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
81 quant_energy[i] = quant_energy[i-1]; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
82 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
83 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
84 if(erasure) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
85 quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
86 else |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
87 quant_energy[0] = (6165 * ((ff_log2(gain_corr_factor) >> 2) - (13 << 13))) >> 13; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
88 } |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
89 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
90 int16_t ff_acelp_decode_gain_code( |
8505
c8743c33eeef
Remove duplicated dot product code. Use dsputil's
reynaldo
parents:
8048
diff
changeset
|
91 DSPContext *dsp, |
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
92 int gain_corr_factor, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
93 const int16_t* fc_v, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
94 int mr_energy, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
95 const int16_t* quant_energy, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
96 const int16_t* ma_prediction_coeff, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
97 int subframe_size, |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
98 int ma_pred_order) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
99 { |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
100 int i; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
101 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
102 mr_energy <<= 10; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
103 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
104 for(i=0; i<ma_pred_order; i++) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
105 mr_energy += quant_energy[i] * ma_prediction_coeff[i]; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
106 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
107 #ifdef G729_BITEXACT |
8505
c8743c33eeef
Remove duplicated dot product code. Use dsputil's
reynaldo
parents:
8048
diff
changeset
|
108 mr_energy += (((-6165LL * ff_log2(dsp->scalarproduct_int16(fc_v, fc_v, subframe_size, 0))) >> 3) & ~0x3ff); |
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
109 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
110 mr_energy = (5439 * (mr_energy >> 15)) >> 8; // (0.15) = (0.15) * (7.23) |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
111 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
112 return bidir_sal( |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
113 ((ff_exp2(mr_energy & 0x7fff) + 16) >> 5) * (gain_corr_factor >> 1), |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
114 (mr_energy >> 15) - 25 |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
115 ); |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
116 #else |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
117 mr_energy = gain_corr_factor * exp(M_LN10 / (20 << 23) * mr_energy) / |
8505
c8743c33eeef
Remove duplicated dot product code. Use dsputil's
reynaldo
parents:
8048
diff
changeset
|
118 sqrt(dsp->scalarproduct_int16(fc_v, fc_v, subframe_size, 0)); |
7170
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
119 return mr_energy >> 12; |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
120 #endif |
04da42c2b7b4
gain code, gain pitch and pitch delay decoding for ACELP based codecs
voroshil
parents:
diff
changeset
|
121 } |
10483
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
122 |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
123 float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
124 float *prediction_error, float energy_mean, |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
125 const float *pred_table) |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
126 { |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
127 // Equations 66-69: |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
128 // ^g_c = ^gamma_gc * 100.05 (predicted dB + mean dB - dB of fixed vector) |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
129 // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)). |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
130 float val = fixed_gain_factor * |
11224 | 131 exp2f(M_LOG2_10 * 0.05 * |
10483
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
132 (ff_dot_productf(pred_table, prediction_error, 4) + |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
133 energy_mean)) / |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
134 sqrtf(fixed_mean_energy); |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
135 |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
136 // update quantified prediction error energy history |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
137 memmove(&prediction_error[0], &prediction_error[1], |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
138 3 * sizeof(prediction_error[0])); |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
139 prediction_error[3] = 20.0 * log10f(fixed_gain_factor); |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
140 |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
141 return val; |
afad312b9989
Implement AMR gain function that is used by both AMR and SIPR.
vitor
parents:
8505
diff
changeset
|
142 } |
10532
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
143 |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
144 void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index, |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
145 const int prev_lag_int, const int subframe, |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
146 int third_as_first, int resolution) |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
147 { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
148 /* Note n * 10923 >> 15 is floor(x/3) for 0 <= n <= 32767 */ |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
149 if (subframe == 0 || (subframe == 2 && third_as_first)) { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
150 |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
151 if (pitch_index < 197) |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
152 pitch_index += 59; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
153 else |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
154 pitch_index = 3 * pitch_index - 335; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
155 |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
156 } else { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
157 if (resolution == 4) { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
158 int search_range_min = av_clip(prev_lag_int - 5, PITCH_DELAY_MIN, |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
159 PITCH_DELAY_MAX - 9); |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
160 |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
161 // decoding with 4-bit resolution |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
162 if (pitch_index < 4) { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
163 // integer only precision for [search_range_min, search_range_min+3] |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
164 pitch_index = 3 * (pitch_index + search_range_min) + 1; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
165 } else if (pitch_index < 12) { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
166 // 1/3 fractional precision for [search_range_min+3 1/3, search_range_min+5 2/3] |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
167 pitch_index += 3 * search_range_min + 7; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
168 } else { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
169 // integer only precision for [search_range_min+6, search_range_min+9] |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
170 pitch_index = 3 * (pitch_index + search_range_min - 6) + 1; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
171 } |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
172 } else { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
173 // decoding with 5 or 6 bit resolution, 1/3 fractional precision |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
174 pitch_index--; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
175 |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
176 if (resolution == 5) { |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
177 pitch_index += 3 * av_clip(prev_lag_int - 10, PITCH_DELAY_MIN, |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
178 PITCH_DELAY_MAX - 19); |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
179 } else |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
180 pitch_index += 3 * av_clip(prev_lag_int - 5, PITCH_DELAY_MIN, |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
181 PITCH_DELAY_MAX - 9); |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
182 } |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
183 } |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
184 *lag_int = pitch_index * 10923 >> 15; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
185 *lag_frac = pitch_index - 3 * *lag_int - 1; |
ca88470521db
Implement ff_decode_pitch_lag() that is used by both AMR and SIPR.
vitor
parents:
10483
diff
changeset
|
186 } |