summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libwmapro/wma.c368
-rw-r--r--apps/codecs/libwmapro/wma.h3
2 files changed, 0 insertions, 371 deletions
diff --git a/apps/codecs/libwmapro/wma.c b/apps/codecs/libwmapro/wma.c
index 80f1907fd8..a23cf38fd9 100644
--- a/apps/codecs/libwmapro/wma.c
+++ b/apps/codecs/libwmapro/wma.c
@@ -19,53 +19,7 @@
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22//#include "avcodec.h"
23#include "wma.h" 22#include "wma.h"
24//#include "wmadata.h"
25
26//#undef NDEBUG
27//#include <assert.h>
28#if 0
29/* XXX: use same run/length optimization as mpeg decoders */
30//FIXME maybe split decode / encode or pass flag
31static void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
32 float **plevel_table, uint16_t **pint_table,
33 const CoefVLCTable *vlc_table)
34{
35 int n = vlc_table->n;
36 const uint8_t *table_bits = vlc_table->huffbits;
37 const uint32_t *table_codes = vlc_table->huffcodes;
38 const uint16_t *levels_table = vlc_table->levels;
39 uint16_t *run_table, *level_table, *int_table;
40 float *flevel_table;
41 int i, l, j, k, level;
42
43 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
44
45 run_table = av_malloc(n * sizeof(uint16_t));
46 level_table = av_malloc(n * sizeof(uint16_t));
47 flevel_table= av_malloc(n * sizeof(*flevel_table));
48 int_table = av_malloc(n * sizeof(uint16_t));
49 i = 2;
50 level = 1;
51 k = 0;
52 while (i < n) {
53 int_table[k] = i;
54 l = levels_table[k++];
55 for (j = 0; j < l; j++) {
56 run_table[i] = j;
57 level_table[i] = level;
58 flevel_table[i]= level;
59 i++;
60 }
61 level++;
62 }
63 *prun_table = run_table;
64 *plevel_table = flevel_table;
65 *pint_table = int_table;
66 av_free(level_table);
67}
68#endif /* 0 */
69 23
70/** 24/**
71 *@brief Get the samples per frame for this stream. 25 *@brief Get the samples per frame for this stream.
@@ -107,328 +61,6 @@ int ff_wma_get_frame_len_bits(int sample_rate, int version,
107 return frame_len_bits; 61 return frame_len_bits;
108} 62}
109 63
110#if 0
111int ff_wma_init(AVCodecContext *avctx, int flags2)
112{
113 WMACodecContext *s = avctx->priv_data;
114 int i;
115 float bps1, high_freq;
116 volatile float bps;
117 int sample_rate1;
118 int coef_vlc_table;
119
120 if ( avctx->sample_rate <= 0 || avctx->sample_rate > 50000
121 || avctx->channels <= 0 || avctx->channels > 8
122 || avctx->bit_rate <= 0)
123 return -1;
124
125 s->sample_rate = avctx->sample_rate;
126 s->nb_channels = avctx->channels;
127 s->bit_rate = avctx->bit_rate;
128 s->block_align = avctx->block_align;
129
130 dsputil_init(&s->dsp, avctx);
131
132 if (avctx->codec->id == CODEC_ID_WMAV1) {
133 s->version = 1;
134 } else {
135 s->version = 2;
136 }
137
138 /* compute MDCT block size */
139 s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0);
140
141 s->frame_len = 1 << s->frame_len_bits;
142 if (s->use_variable_block_len) {
143 int nb_max, nb;
144 nb = ((flags2 >> 3) & 3) + 1;
145 if ((s->bit_rate / s->nb_channels) >= 32000)
146 nb += 2;
147 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
148 if (nb > nb_max)
149 nb = nb_max;
150 s->nb_block_sizes = nb + 1;
151 } else {
152 s->nb_block_sizes = 1;
153 }
154
155 /* init rate dependent parameters */
156 s->use_noise_coding = 1;
157 high_freq = s->sample_rate * 0.5;
158
159 /* if version 2, then the rates are normalized */
160 sample_rate1 = s->sample_rate;
161 if (s->version == 2) {
162 if (sample_rate1 >= 44100) {
163 sample_rate1 = 44100;
164 } else if (sample_rate1 >= 22050) {
165 sample_rate1 = 22050;
166 } else if (sample_rate1 >= 16000) {
167 sample_rate1 = 16000;
168 } else if (sample_rate1 >= 11025) {
169 sample_rate1 = 11025;
170 } else if (sample_rate1 >= 8000) {
171 sample_rate1 = 8000;
172 }
173 }
174
175 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
176 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
177
178 /* compute high frequency value and choose if noise coding should
179 be activated */
180 bps1 = bps;
181 if (s->nb_channels == 2)
182 bps1 = bps * 1.6;
183 if (sample_rate1 == 44100) {
184 if (bps1 >= 0.61) {
185 s->use_noise_coding = 0;
186 } else {
187 high_freq = high_freq * 0.4;
188 }
189 } else if (sample_rate1 == 22050) {
190 if (bps1 >= 1.16) {
191 s->use_noise_coding = 0;
192 } else if (bps1 >= 0.72) {
193 high_freq = high_freq * 0.7;
194 } else {
195 high_freq = high_freq * 0.6;
196 }
197 } else if (sample_rate1 == 16000) {
198 if (bps > 0.5) {
199 high_freq = high_freq * 0.5;
200 } else {
201 high_freq = high_freq * 0.3;
202 }
203 } else if (sample_rate1 == 11025) {
204 high_freq = high_freq * 0.7;
205 } else if (sample_rate1 == 8000) {
206 if (bps <= 0.625) {
207 high_freq = high_freq * 0.5;
208 } else if (bps > 0.75) {
209 s->use_noise_coding = 0;
210 } else {
211 high_freq = high_freq * 0.65;
212 }
213 } else {
214 if (bps >= 0.8) {
215 high_freq = high_freq * 0.75;
216 } else if (bps >= 0.6) {
217 high_freq = high_freq * 0.6;
218 } else {
219 high_freq = high_freq * 0.5;
220 }
221 }
222 dprintf(s->avctx, "flags2=0x%x\n", flags2);
223 dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
224 s->version, s->nb_channels, s->sample_rate, s->bit_rate,
225 s->block_align);
226 dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
227 bps, bps1, high_freq, s->byte_offset_bits);
228 dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
229 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
230
231 /* compute the scale factor band sizes for each MDCT block size */
232 {
233 int a, b, pos, lpos, k, block_len, i, j, n;
234 const uint8_t *table;
235
236 if (s->version == 1) {
237 s->coefs_start = 3;
238 } else {
239 s->coefs_start = 0;
240 }
241 for (k = 0; k < s->nb_block_sizes; k++) {
242 block_len = s->frame_len >> k;
243
244 if (s->version == 1) {
245 lpos = 0;
246 for (i = 0; i < 25; i++) {
247 a = ff_wma_critical_freqs[i];
248 b = s->sample_rate;
249 pos = ((block_len * 2 * a) + (b >> 1)) / b;
250 if (pos > block_len)
251 pos = block_len;
252 s->exponent_bands[0][i] = pos - lpos;
253 if (pos >= block_len) {
254 i++;
255 break;
256 }
257 lpos = pos;
258 }
259 s->exponent_sizes[0] = i;
260 } else {
261 /* hardcoded tables */
262 table = NULL;
263 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
264 if (a < 3) {
265 if (s->sample_rate >= 44100) {
266 table = exponent_band_44100[a];
267 } else if (s->sample_rate >= 32000) {
268 table = exponent_band_32000[a];
269 } else if (s->sample_rate >= 22050) {
270 table = exponent_band_22050[a];
271 }
272 }
273 if (table) {
274 n = *table++;
275 for (i = 0; i < n; i++)
276 s->exponent_bands[k][i] = table[i];
277 s->exponent_sizes[k] = n;
278 } else {
279 j = 0;
280 lpos = 0;
281 for (i = 0; i < 25; i++) {
282 a = ff_wma_critical_freqs[i];
283 b = s->sample_rate;
284 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
285 pos <<= 2;
286 if (pos > block_len)
287 pos = block_len;
288 if (pos > lpos)
289 s->exponent_bands[k][j++] = pos - lpos;
290 if (pos >= block_len)
291 break;
292 lpos = pos;
293 }
294 s->exponent_sizes[k] = j;
295 }
296 }
297
298 /* max number of coefs */
299 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
300 /* high freq computation */
301 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
302 s->sample_rate + 0.5);
303 n = s->exponent_sizes[k];
304 j = 0;
305 pos = 0;
306 for (i = 0; i < n; i++) {
307 int start, end;
308 start = pos;
309 pos += s->exponent_bands[k][i];
310 end = pos;
311 if (start < s->high_band_start[k])
312 start = s->high_band_start[k];
313 if (end > s->coefs_end[k])
314 end = s->coefs_end[k];
315 if (end > start)
316 s->exponent_high_bands[k][j++] = end - start;
317 }
318 s->exponent_high_sizes[k] = j;
319#if 0
320 tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
321 s->frame_len >> k,
322 s->coefs_end[k],
323 s->high_band_start[k],
324 s->exponent_high_sizes[k]);
325 for (j = 0; j < s->exponent_high_sizes[k]; j++)
326 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
327 tprintf(s->avctx, "\n");
328#endif
329 }
330 }
331
332#ifdef TRACE
333 {
334 int i, j;
335 for (i = 0; i < s->nb_block_sizes; i++) {
336 tprintf(s->avctx, "%5d: n=%2d:",
337 s->frame_len >> i,
338 s->exponent_sizes[i]);
339 for (j = 0; j < s->exponent_sizes[i]; j++)
340 tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
341 tprintf(s->avctx, "\n");
342 }
343 }
344#endif
345
346 /* init MDCT windows : simple sinus window */
347 for (i = 0; i < s->nb_block_sizes; i++) {
348 ff_init_ff_sine_windows(s->frame_len_bits - i);
349 s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
350 }
351
352 s->reset_block_lengths = 1;
353
354 if (s->use_noise_coding) {
355
356 /* init the noise generator */
357 if (s->use_exp_vlc) {
358 s->noise_mult = 0.02;
359 } else {
360 s->noise_mult = 0.04;
361 }
362
363#ifdef TRACE
364 for (i = 0; i < NOISE_TAB_SIZE; i++)
365 s->noise_table[i] = 1.0 * s->noise_mult;
366#else
367 {
368 unsigned int seed;
369 float norm;
370 seed = 1;
371 norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
372 for (i = 0; i < NOISE_TAB_SIZE; i++) {
373 seed = seed * 314159 + 1;
374 s->noise_table[i] = (float)((int)seed) * norm;
375 }
376 }
377#endif
378 }
379
380 /* choose the VLC tables for the coefficients */
381 coef_vlc_table = 2;
382 if (s->sample_rate >= 32000) {
383 if (bps1 < 0.72) {
384 coef_vlc_table = 0;
385 } else if (bps1 < 1.16) {
386 coef_vlc_table = 1;
387 }
388 }
389 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
390 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
391 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
392 s->coef_vlcs[0]);
393 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
394 s->coef_vlcs[1]);
395
396 return 0;
397}
398
399int ff_wma_total_gain_to_bits(int total_gain)
400{
401 if (total_gain < 15) return 13;
402 else if (total_gain < 32) return 12;
403 else if (total_gain < 40) return 11;
404 else if (total_gain < 45) return 10;
405 else return 9;
406}
407
408int ff_wma_end(AVCodecContext *avctx)
409{
410 WMACodecContext *s = avctx->priv_data;
411 int i;
412
413 for (i = 0; i < s->nb_block_sizes; i++)
414 ff_mdct_end(&s->mdct_ctx[i]);
415
416 if (s->use_exp_vlc) {
417 free_vlc(&s->exp_vlc);
418 }
419 if (s->use_noise_coding) {
420 free_vlc(&s->hgain_vlc);
421 }
422 for (i = 0; i < 2; i++) {
423 free_vlc(&s->coef_vlc[i]);
424 av_free(s->run_table[i]);
425 av_free(s->level_table[i]);
426 av_free(s->int_table[i]);
427 }
428
429 return 0;
430}
431#endif /* 0 */
432/** 64/**
433 * Decode an uncompressed coefficient. 65 * Decode an uncompressed coefficient.
434 * @param s codec context 66 * @param s codec context
diff --git a/apps/codecs/libwmapro/wma.h b/apps/codecs/libwmapro/wma.h
index 40ca6e1303..3a0948e51e 100644
--- a/apps/codecs/libwmapro/wma.h
+++ b/apps/codecs/libwmapro/wma.h
@@ -50,8 +50,6 @@
50#define VLCBITS 9 50#define VLCBITS 9
51#define VLCMAX ((22+VLCBITS-1)/VLCBITS) 51#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
52 52
53typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
54
55typedef struct CoefVLCTable { 53typedef struct CoefVLCTable {
56 int n; ///< total number of codes 54 int n; ///< total number of codes
57 int max_level; 55 int max_level;
@@ -63,7 +61,6 @@ typedef struct CoefVLCTable {
63 61
64int ff_wma_get_frame_len_bits(int sample_rate, int version, 62int ff_wma_get_frame_len_bits(int sample_rate, int version,
65 unsigned int decode_flags); 63 unsigned int decode_flags);
66int ff_wma_total_gain_to_bits(int total_gain);
67unsigned int ff_wma_get_large_val(GetBitContext* gb); 64unsigned int ff_wma_get_large_val(GetBitContext* gb);
68int ff_wma_run_level_decode(GetBitContext* gb, 65int ff_wma_run_level_decode(GetBitContext* gb,
69 VLC *vlc, 66 VLC *vlc,