00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <inttypes.h>
00024
00025 #include "libavutil/common.h"
00026 #include "avcodec.h"
00027 #include "dsputil.h"
00028 #include "acelp_vectors.h"
00029
00030 const uint8_t ff_fc_2pulses_9bits_track1[16] =
00031 {
00032 1, 3,
00033 6, 8,
00034 11, 13,
00035 16, 18,
00036 21, 23,
00037 26, 28,
00038 31, 33,
00039 36, 38
00040 };
00041 const uint8_t ff_fc_2pulses_9bits_track1_gray[16] =
00042 {
00043 1, 3,
00044 8, 6,
00045 18, 16,
00046 11, 13,
00047 38, 36,
00048 31, 33,
00049 21, 23,
00050 28, 26,
00051 };
00052
00053 const uint8_t ff_fc_2pulses_9bits_track2_gray[32] =
00054 {
00055 0, 2,
00056 5, 4,
00057 12, 10,
00058 7, 9,
00059 25, 24,
00060 20, 22,
00061 14, 15,
00062 19, 17,
00063 36, 31,
00064 21, 26,
00065 1, 6,
00066 16, 11,
00067 27, 29,
00068 32, 30,
00069 39, 37,
00070 34, 35,
00071 };
00072
00073 const uint8_t ff_fc_4pulses_8bits_tracks_13[16] =
00074 {
00075 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
00076 };
00077
00078 const uint8_t ff_fc_4pulses_8bits_track_4[32] =
00079 {
00080 3, 4,
00081 8, 9,
00082 13, 14,
00083 18, 19,
00084 23, 24,
00085 28, 29,
00086 33, 34,
00087 38, 39,
00088 43, 44,
00089 48, 49,
00090 53, 54,
00091 58, 59,
00092 63, 64,
00093 68, 69,
00094 73, 74,
00095 78, 79,
00096 };
00097
00098 const float ff_pow_0_7[10] = {
00099 0.700000, 0.490000, 0.343000, 0.240100, 0.168070,
00100 0.117649, 0.082354, 0.057648, 0.040354, 0.028248
00101 };
00102
00103 const float ff_pow_0_75[10] = {
00104 0.750000, 0.562500, 0.421875, 0.316406, 0.237305,
00105 0.177979, 0.133484, 0.100113, 0.075085, 0.056314
00106 };
00107
00108 const float ff_pow_0_55[10] = {
00109 0.550000, 0.302500, 0.166375, 0.091506, 0.050328,
00110 0.027681, 0.015224, 0.008373, 0.004605, 0.002533
00111 };
00112
00113 const float ff_b60_sinc[61] = {
00114 0.898529 , 0.865051 , 0.769257 , 0.624054 , 0.448639 , 0.265289 ,
00115 0.0959167 , -0.0412598 , -0.134338 , -0.178986 , -0.178528 , -0.142609 ,
00116 -0.0849304 , -0.0205078 , 0.0369568 , 0.0773926 , 0.0955200 , 0.0912781 ,
00117 0.0689392 , 0.0357056 , 0. , -0.0305481 , -0.0504150 , -0.0570068 ,
00118 -0.0508423 , -0.0350037 , -0.0141602 , 0.00665283, 0.0230713 , 0.0323486 ,
00119 0.0335388 , 0.0275879 , 0.0167847 , 0.00411987, -0.00747681, -0.0156860 ,
00120 -0.0193481 , -0.0183716 , -0.0137634 , -0.00704956, 0. , 0.00582886 ,
00121 0.00939941, 0.0103760 , 0.00903320, 0.00604248, 0.00238037, -0.00109863 ,
00122 -0.00366211, -0.00497437, -0.00503540, -0.00402832, -0.00241089, -0.000579834,
00123 0.00103760, 0.00222778, 0.00277710, 0.00271606, 0.00213623, 0.00115967 ,
00124 0.
00125 };
00126
00127 void ff_acelp_fc_pulse_per_track(
00128 int16_t* fc_v,
00129 const uint8_t *tab1,
00130 const uint8_t *tab2,
00131 int pulse_indexes,
00132 int pulse_signs,
00133 int pulse_count,
00134 int bits)
00135 {
00136 int mask = (1 << bits) - 1;
00137 int i;
00138
00139 for(i=0; i<pulse_count; i++)
00140 {
00141 fc_v[i + tab1[pulse_indexes & mask]] +=
00142 (pulse_signs & 1) ? 8191 : -8192;
00143
00144 pulse_indexes >>= bits;
00145 pulse_signs >>= 1;
00146 }
00147
00148 fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192;
00149 }
00150
00151 void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
00152 AMRFixed *fixed_sparse,
00153 const uint8_t *gray_decode,
00154 int half_pulse_count, int bits)
00155 {
00156 int i;
00157 int mask = (1 << bits) - 1;
00158
00159 fixed_sparse->no_repeat_mask = 0;
00160 fixed_sparse->n = 2 * half_pulse_count;
00161 for (i = 0; i < half_pulse_count; i++) {
00162 const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i;
00163 const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i;
00164 const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
00165 fixed_sparse->x[2*i+1] = pos1;
00166 fixed_sparse->x[2*i ] = pos2;
00167 fixed_sparse->y[2*i+1] = sign;
00168 fixed_sparse->y[2*i ] = pos2 < pos1 ? -sign : sign;
00169 }
00170 }
00171
00172 void ff_acelp_weighted_vector_sum(
00173 int16_t* out,
00174 const int16_t *in_a,
00175 const int16_t *in_b,
00176 int16_t weight_coeff_a,
00177 int16_t weight_coeff_b,
00178 int16_t rounder,
00179 int shift,
00180 int length)
00181 {
00182 int i;
00183
00184
00185 for(i=0; i<length; i++)
00186 out[i] = av_clip_int16((
00187 in_a[i] * weight_coeff_a +
00188 in_b[i] * weight_coeff_b +
00189 rounder) >> shift);
00190 }
00191
00192 void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
00193 float weight_coeff_a, float weight_coeff_b, int length)
00194 {
00195 int i;
00196
00197 for(i=0; i<length; i++)
00198 out[i] = weight_coeff_a * in_a[i]
00199 + weight_coeff_b * in_b[i];
00200 }
00201
00202 void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
00203 int size, float alpha, float *gain_mem)
00204 {
00205 int i;
00206 float postfilter_energ = ff_scalarproduct_float_c(in, in, size);
00207 float gain_scale_factor = 1.0;
00208 float mem = *gain_mem;
00209
00210 if (postfilter_energ)
00211 gain_scale_factor = sqrt(speech_energ / postfilter_energ);
00212
00213 gain_scale_factor *= 1.0 - alpha;
00214
00215 for (i = 0; i < size; i++) {
00216 mem = alpha * mem + gain_scale_factor;
00217 out[i] = in[i] * mem;
00218 }
00219
00220 *gain_mem = mem;
00221 }
00222
00223 void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
00224 float sum_of_squares, const int n)
00225 {
00226 int i;
00227 float scalefactor = ff_scalarproduct_float_c(in, in, n);
00228 if (scalefactor)
00229 scalefactor = sqrt(sum_of_squares / scalefactor);
00230 for (i = 0; i < n; i++)
00231 out[i] = in[i] * scalefactor;
00232 }
00233
00234 void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size)
00235 {
00236 int i;
00237
00238 for (i=0; i < in->n; i++) {
00239 int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
00240 float y = in->y[i] * scale;
00241
00242 if (in->pitch_lag > 0)
00243 do {
00244 out[x] += y;
00245 y *= in->pitch_fac;
00246 x += in->pitch_lag;
00247 } while (x < size && repeats);
00248 }
00249 }
00250
00251 void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size)
00252 {
00253 int i;
00254
00255 for (i=0; i < in->n; i++) {
00256 int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
00257
00258 if (in->pitch_lag > 0)
00259 do {
00260 out[x] = 0.0;
00261 x += in->pitch_lag;
00262 } while (x < size && repeats);
00263 }
00264 }
00265
00266 void ff_acelp_vectors_init(ACELPVContext *c)
00267 {
00268 c->weighted_vector_sumf = ff_weighted_vector_sumf;
00269
00270 if(HAVE_MIPSFPU)
00271 ff_acelp_vectors_init_mips(c);
00272 }