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