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/avassert.h"
00026 #include "libavutil/common.h"
00027 #include "avcodec.h"
00028 #include "acelp_filters.h"
00029
00030 const int16_t ff_acelp_interp_filter[61] = {
00031 29443, 28346, 25207, 20449, 14701, 8693,
00032 3143, -1352, -4402, -5865, -5850, -4673,
00033 -2783, -672, 1211, 2536, 3130, 2991,
00034 2259, 1170, 0, -1001, -1652, -1868,
00035 -1666, -1147, -464, 218, 756, 1060,
00036 1099, 904, 550, 135, -245, -514,
00037 -634, -602, -451, -231, 0, 191,
00038 308, 340, 296, 198, 78, -36,
00039 -120, -163, -165, -132, -79, -19,
00040 34, 73, 91, 89, 70, 38,
00041 0,
00042 };
00043
00044 void ff_acelp_interpolate(int16_t* out, const int16_t* in,
00045 const int16_t* filter_coeffs, int precision,
00046 int frac_pos, int filter_length, int length)
00047 {
00048 int n, i;
00049
00050 av_assert1(frac_pos >= 0 && frac_pos < precision);
00051
00052 for (n = 0; n < length; n++) {
00053 int idx = 0;
00054 int v = 0x4000;
00055
00056 for (i = 0; i < filter_length;) {
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 v += in[n + i] * filter_coeffs[idx + frac_pos];
00068 idx += precision;
00069 i++;
00070 v += in[n - i] * filter_coeffs[idx - frac_pos];
00071 }
00072 if (av_clip_int16(v >> 15) != (v >> 15))
00073 av_log(NULL, AV_LOG_WARNING, "overflow that would need cliping in ff_acelp_interpolate()\n");
00074 out[n] = v >> 15;
00075 }
00076 }
00077
00078 void ff_acelp_interpolatef(float *out, const float *in,
00079 const float *filter_coeffs, int precision,
00080 int frac_pos, int filter_length, int length)
00081 {
00082 int n, i;
00083
00084 for (n = 0; n < length; n++) {
00085 int idx = 0;
00086 float v = 0;
00087
00088 for (i = 0; i < filter_length;) {
00089 v += in[n + i] * filter_coeffs[idx + frac_pos];
00090 idx += precision;
00091 i++;
00092 v += in[n - i] * filter_coeffs[idx - frac_pos];
00093 }
00094 out[n] = v;
00095 }
00096 }
00097
00098
00099 void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2],
00100 const int16_t* in, int length)
00101 {
00102 int i;
00103 int tmp;
00104
00105 for (i = 0; i < length; i++) {
00106 tmp = (hpf_f[0]* 15836LL) >> 13;
00107 tmp += (hpf_f[1]* -7667LL) >> 13;
00108 tmp += 7699 * (in[i] - 2*in[i-1] + in[i-2]);
00109
00110
00111
00112 out[i] = av_clip_int16((tmp + 0x800) >> 12);
00113
00114 hpf_f[1] = hpf_f[0];
00115 hpf_f[0] = tmp;
00116 }
00117 }
00118
00119 void ff_acelp_apply_order_2_transfer_function(float *out, const float *in,
00120 const float zero_coeffs[2],
00121 const float pole_coeffs[2],
00122 float gain, float mem[2], int n)
00123 {
00124 int i;
00125 float tmp;
00126
00127 for (i = 0; i < n; i++) {
00128 tmp = gain * in[i] - pole_coeffs[0] * mem[0] - pole_coeffs[1] * mem[1];
00129 out[i] = tmp + zero_coeffs[0] * mem[0] + zero_coeffs[1] * mem[1];
00130
00131 mem[1] = mem[0];
00132 mem[0] = tmp;
00133 }
00134 }
00135
00136 void ff_tilt_compensation(float *mem, float tilt, float *samples, int size)
00137 {
00138 float new_tilt_mem = samples[size - 1];
00139 int i;
00140
00141 for (i = size - 1; i > 0; i--)
00142 samples[i] -= tilt * samples[i - 1];
00143
00144 samples[0] -= tilt * *mem;
00145 *mem = new_tilt_mem;
00146 }
00147
00148 void ff_acelp_filter_init(ACELPFContext *c)
00149 {
00150 c->acelp_interpolatef = ff_acelp_interpolatef;
00151 c->acelp_apply_order_2_transfer_function = ff_acelp_apply_order_2_transfer_function;
00152
00153 if(HAVE_MIPSFPU)
00154 ff_acelp_filter_init_mips(c);
00155 }