Mercurial > libavcodec.hg
comparison ra288.c @ 7788:ffd4b1364b62 libavcodec
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
author | vitor |
---|---|
date | Thu, 04 Sep 2008 11:03:14 +0000 |
parents | 2c22852d1998 |
children | 58f33e404d6a |
comparison
equal
deleted
inserted
replaced
7787:681a05d9b04f | 7788:ffd4b1364b62 |
---|---|
21 | 21 |
22 #include "avcodec.h" | 22 #include "avcodec.h" |
23 #define ALT_BITSTREAM_READER_LE | 23 #define ALT_BITSTREAM_READER_LE |
24 #include "bitstream.h" | 24 #include "bitstream.h" |
25 #include "ra288.h" | 25 #include "ra288.h" |
26 #include "lpc.h" | |
26 | 27 |
27 typedef struct { | 28 typedef struct { |
28 float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A) | 29 float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A) |
29 float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB) | 30 float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB) |
30 | 31 |
109 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j]; | 110 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j]; |
110 | 111 |
111 /* output */ | 112 /* output */ |
112 for (i=0; i < 5; i++) | 113 for (i=0; i < 5; i++) |
113 block[i] = av_clipf(block[i] + buffer[i], -4095, 4095); | 114 block[i] = av_clipf(block[i] + buffer[i], -4095, 4095); |
114 } | |
115 | |
116 /** | |
117 * Converts autocorrelation coefficients to LPC coefficients using the | |
118 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification. | |
119 * | |
120 * @return 0 if success, -1 if fail | |
121 */ | |
122 static int eval_lpc_coeffs(const float *in, float *tgt, int n) | |
123 { | |
124 int i, j; | |
125 double f0, f1, f2; | |
126 | |
127 if (in[n] == 0) | |
128 return -1; | |
129 | |
130 if ((f0 = *in) <= 0) | |
131 return -1; | |
132 | |
133 in--; // To avoid a -1 subtraction in the inner loop | |
134 | |
135 for (i=1; i <= n; i++) { | |
136 f1 = in[i+1]; | |
137 | |
138 for (j=0; j < i - 1; j++) | |
139 f1 += in[i-j]*tgt[j]; | |
140 | |
141 tgt[i-1] = f2 = -f1/f0; | |
142 for (j=0; j < i >> 1; j++) { | |
143 float temp = tgt[j] + tgt[i-j-2]*f2; | |
144 tgt[i-j-2] += tgt[j]*f2; | |
145 tgt[j] = temp; | |
146 } | |
147 if ((f0 += f1*f2) < 0) | |
148 return -1; | |
149 } | |
150 | |
151 return 0; | |
152 } | 115 } |
153 | 116 |
154 static void convolve(float *tgt, const float *src, int len, int n) | 117 static void convolve(float *tgt, const float *src, int len, int n) |
155 { | 118 { |
156 for (; n >= 0; n--) | 119 for (; n >= 0; n--) |
208 float temp2[11]; // GPTPMP in the spec | 171 float temp2[11]; // GPTPMP in the spec |
209 | 172 |
210 do_hybrid_window(36, 40, 35, ractx->sp_block+1, temp1, ractx->sp_hist, | 173 do_hybrid_window(36, 40, 35, ractx->sp_block+1, temp1, ractx->sp_hist, |
211 ractx->sp_rec, syn_window); | 174 ractx->sp_rec, syn_window); |
212 | 175 |
213 if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36)) | 176 if (!compute_lpc_coefs(temp1, 36, ractx->sp_lpc, 0, 1, 1)) |
214 colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); | 177 colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); |
215 | 178 |
216 do_hybrid_window(10, 8, 20, ractx->gain_block+2, temp2, ractx->gain_hist, | 179 do_hybrid_window(10, 8, 20, ractx->gain_block+2, temp2, ractx->gain_hist, |
217 ractx->gain_rec, gain_window); | 180 ractx->gain_rec, gain_window); |
218 | 181 |
219 if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10)) | 182 if (!compute_lpc_coefs(temp2, 10, ractx->gain_lpc, 0, 1, 1)) |
220 colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); | 183 colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); |
221 } | 184 } |
222 | 185 |
223 static int ra288_decode_frame(AVCodecContext * avctx, void *data, | 186 static int ra288_decode_frame(AVCodecContext * avctx, void *data, |
224 int *data_size, const uint8_t * buf, | 187 int *data_size, const uint8_t * buf, |