Mercurial > libavcodec.hg
annotate wma.c @ 9842:32d100ad81a6 libavcodec
Add additional sample rates to the frame len bits calculation code
author | faust3 |
---|---|
date | Fri, 12 Jun 2009 15:38:11 +0000 |
parents | 39bb2646fe00 |
children | 893b27768692 |
rev | line source |
---|---|
4490 | 1 /* |
2 * WMA compatible codec | |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
7682
diff
changeset
|
3 * Copyright (c) 2002-2007 The FFmpeg Project |
4490 | 4 * |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
22 #include "avcodec.h" | |
23 #include "wma.h" | |
24 #include "wmadata.h" | |
25 | |
26 #undef NDEBUG | |
27 #include <assert.h> | |
28 | |
29 /* XXX: use same run/length optimization as mpeg decoders */ | |
30 //FIXME maybe split decode / encode or pass flag | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
31 static void init_coef_vlc(VLC *vlc, uint16_t **prun_table, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
32 uint16_t **plevel_table, uint16_t **pint_table, |
4490 | 33 const CoefVLCTable *vlc_table) |
34 { | |
35 int n = vlc_table->n; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
36 const uint8_t *table_bits = vlc_table->huffbits; |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
37 const uint32_t *table_codes = vlc_table->huffcodes; |
4490 | 38 const uint16_t *levels_table = vlc_table->levels; |
39 uint16_t *run_table, *level_table, *int_table; | |
40 int i, l, j, k, level; | |
41 | |
42 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0); | |
43 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
44 run_table = av_malloc(n * sizeof(uint16_t)); |
4490 | 45 level_table = av_malloc(n * sizeof(uint16_t)); |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
46 int_table = av_malloc(n * sizeof(uint16_t)); |
4490 | 47 i = 2; |
48 level = 1; | |
49 k = 0; | |
50 while (i < n) { | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
51 int_table[k] = i; |
4490 | 52 l = levels_table[k++]; |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
53 for (j = 0; j < l; j++) { |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
54 run_table[i] = j; |
4490 | 55 level_table[i] = level; |
56 i++; | |
57 } | |
58 level++; | |
59 } | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
60 *prun_table = run_table; |
4490 | 61 *plevel_table = level_table; |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
62 *pint_table = int_table; |
4490 | 63 } |
64 | |
9841
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
65 /** |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
66 *@brief Get the samples per frame for this stream. |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
67 *@param sample_rate output sample_rate |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
68 *@param version wma version |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
69 *@param decode_flags codec compression features |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
70 *@return log2 of the number of output samples per frame |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
71 */ |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
72 int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
73 unsigned int decode_flags) |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
74 { |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
75 |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
76 int frame_len_bits; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
77 |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
78 if (sample_rate <= 16000) |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
79 frame_len_bits = 9; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
80 else if (sample_rate <= 22050 || |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
81 (sample_rate <= 32000 && version == 1)) |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
82 frame_len_bits = 10; |
9842
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
83 else if (sample_rate <= 48000) { |
9841
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
84 frame_len_bits = 11; |
9842
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
85 } else if (sample_rate <= 96000) { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
86 frame_len_bits = 12; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
87 } else { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
88 frame_len_bits = 13; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
89 } |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
90 |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
91 if (version == 3) { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
92 int tmp = decode_flags & 0x6; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
93 if (tmp == 0x2) { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
94 ++frame_len_bits; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
95 } else if (tmp == 0x4) { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
96 --frame_len_bits; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
97 } else if (tmp == 0x6) { |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
98 frame_len_bits -= 2; |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
99 } |
32d100ad81a6
Add additional sample rates to the frame len bits calculation code
faust3
parents:
9841
diff
changeset
|
100 } |
9841
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
101 |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
102 return frame_len_bits; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
103 } |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
104 |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
105 int ff_wma_init(AVCodecContext *avctx, int flags2) |
4490 | 106 { |
4601 | 107 WMACodecContext *s = avctx->priv_data; |
4490 | 108 int i; |
109 float bps1, high_freq; | |
110 volatile float bps; | |
111 int sample_rate1; | |
112 int coef_vlc_table; | |
113 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
114 if ( avctx->sample_rate <= 0 || avctx->sample_rate > 50000 |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
115 || avctx->channels <= 0 || avctx->channels > 8 |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
116 || avctx->bit_rate <= 0) |
5086
a10ebd496bd9
sanity checks (should prevent hypothetical div by zero issue)
michael
parents:
4737
diff
changeset
|
117 return -1; |
a10ebd496bd9
sanity checks (should prevent hypothetical div by zero issue)
michael
parents:
4737
diff
changeset
|
118 |
4490 | 119 s->sample_rate = avctx->sample_rate; |
120 s->nb_channels = avctx->channels; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
121 s->bit_rate = avctx->bit_rate; |
4490 | 122 s->block_align = avctx->block_align; |
123 | |
124 dsputil_init(&s->dsp, avctx); | |
125 | |
126 if (avctx->codec->id == CODEC_ID_WMAV1) { | |
127 s->version = 1; | |
128 } else { | |
129 s->version = 2; | |
130 } | |
131 | |
132 /* compute MDCT block size */ | |
9841
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
133 s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0); |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
134 |
4490 | 135 s->frame_len = 1 << s->frame_len_bits; |
136 if (s->use_variable_block_len) { | |
137 int nb_max, nb; | |
138 nb = ((flags2 >> 3) & 3) + 1; | |
139 if ((s->bit_rate / s->nb_channels) >= 32000) | |
140 nb += 2; | |
141 nb_max = s->frame_len_bits - BLOCK_MIN_BITS; | |
142 if (nb > nb_max) | |
143 nb = nb_max; | |
144 s->nb_block_sizes = nb + 1; | |
145 } else { | |
146 s->nb_block_sizes = 1; | |
147 } | |
148 | |
4588
fc155ff94878
cosmetics: Fix another common typo, dependAnt --> dependEnt.
diego
parents:
4490
diff
changeset
|
149 /* init rate dependent parameters */ |
4490 | 150 s->use_noise_coding = 1; |
151 high_freq = s->sample_rate * 0.5; | |
152 | |
153 /* if version 2, then the rates are normalized */ | |
154 sample_rate1 = s->sample_rate; | |
155 if (s->version == 2) { | |
156 if (sample_rate1 >= 44100) | |
157 sample_rate1 = 44100; | |
158 else if (sample_rate1 >= 22050) | |
159 sample_rate1 = 22050; | |
160 else if (sample_rate1 >= 16000) | |
161 sample_rate1 = 16000; | |
162 else if (sample_rate1 >= 11025) | |
163 sample_rate1 = 11025; | |
164 else if (sample_rate1 >= 8000) | |
165 sample_rate1 = 8000; | |
166 } | |
167 | |
168 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate); | |
169 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2; | |
170 | |
171 /* compute high frequency value and choose if noise coding should | |
172 be activated */ | |
173 bps1 = bps; | |
174 if (s->nb_channels == 2) | |
175 bps1 = bps * 1.6; | |
176 if (sample_rate1 == 44100) { | |
177 if (bps1 >= 0.61) | |
178 s->use_noise_coding = 0; | |
179 else | |
180 high_freq = high_freq * 0.4; | |
181 } else if (sample_rate1 == 22050) { | |
182 if (bps1 >= 1.16) | |
183 s->use_noise_coding = 0; | |
184 else if (bps1 >= 0.72) | |
185 high_freq = high_freq * 0.7; | |
186 else | |
187 high_freq = high_freq * 0.6; | |
188 } else if (sample_rate1 == 16000) { | |
189 if (bps > 0.5) | |
190 high_freq = high_freq * 0.5; | |
191 else | |
192 high_freq = high_freq * 0.3; | |
193 } else if (sample_rate1 == 11025) { | |
194 high_freq = high_freq * 0.7; | |
195 } else if (sample_rate1 == 8000) { | |
196 if (bps <= 0.625) { | |
197 high_freq = high_freq * 0.5; | |
198 } else if (bps > 0.75) { | |
199 s->use_noise_coding = 0; | |
200 } else { | |
201 high_freq = high_freq * 0.65; | |
202 } | |
203 } else { | |
204 if (bps >= 0.8) { | |
205 high_freq = high_freq * 0.75; | |
206 } else if (bps >= 0.6) { | |
207 high_freq = high_freq * 0.6; | |
208 } else { | |
209 high_freq = high_freq * 0.5; | |
210 } | |
211 } | |
4652 | 212 dprintf(s->avctx, "flags2=0x%x\n", flags2); |
213 dprintf(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n", | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
214 s->version, s->nb_channels, s->sample_rate, s->bit_rate, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
215 s->block_align); |
4652 | 216 dprintf(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n", |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
217 bps, bps1, high_freq, s->byte_offset_bits); |
4652 | 218 dprintf(s->avctx, "use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
219 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); |
4490 | 220 |
221 /* compute the scale factor band sizes for each MDCT block size */ | |
222 { | |
223 int a, b, pos, lpos, k, block_len, i, j, n; | |
224 const uint8_t *table; | |
225 | |
226 if (s->version == 1) { | |
227 s->coefs_start = 3; | |
228 } else { | |
229 s->coefs_start = 0; | |
230 } | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
231 for (k = 0; k < s->nb_block_sizes; k++) { |
4490 | 232 block_len = s->frame_len >> k; |
233 | |
234 if (s->version == 1) { | |
235 lpos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
236 for (i = 0; i < 25; i++) { |
4490 | 237 a = wma_critical_freqs[i]; |
238 b = s->sample_rate; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
239 pos = ((block_len * 2 * a) + (b >> 1)) / b; |
4490 | 240 if (pos > block_len) |
241 pos = block_len; | |
242 s->exponent_bands[0][i] = pos - lpos; | |
243 if (pos >= block_len) { | |
244 i++; | |
245 break; | |
246 } | |
247 lpos = pos; | |
248 } | |
249 s->exponent_sizes[0] = i; | |
250 } else { | |
251 /* hardcoded tables */ | |
252 table = NULL; | |
253 a = s->frame_len_bits - BLOCK_MIN_BITS - k; | |
254 if (a < 3) { | |
255 if (s->sample_rate >= 44100) | |
256 table = exponent_band_44100[a]; | |
257 else if (s->sample_rate >= 32000) | |
258 table = exponent_band_32000[a]; | |
259 else if (s->sample_rate >= 22050) | |
260 table = exponent_band_22050[a]; | |
261 } | |
262 if (table) { | |
263 n = *table++; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
264 for (i = 0; i < n; i++) |
4490 | 265 s->exponent_bands[k][i] = table[i]; |
266 s->exponent_sizes[k] = n; | |
267 } else { | |
268 j = 0; | |
269 lpos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
270 for (i = 0; i < 25; i++) { |
4490 | 271 a = wma_critical_freqs[i]; |
272 b = s->sample_rate; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
273 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b); |
4490 | 274 pos <<= 2; |
275 if (pos > block_len) | |
276 pos = block_len; | |
277 if (pos > lpos) | |
278 s->exponent_bands[k][j++] = pos - lpos; | |
279 if (pos >= block_len) | |
280 break; | |
281 lpos = pos; | |
282 } | |
283 s->exponent_sizes[k] = j; | |
284 } | |
285 } | |
286 | |
287 /* max number of coefs */ | |
288 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k; | |
289 /* high freq computation */ | |
290 s->high_band_start[k] = (int)((block_len * 2 * high_freq) / | |
291 s->sample_rate + 0.5); | |
292 n = s->exponent_sizes[k]; | |
293 j = 0; | |
294 pos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
295 for (i = 0; i < n; i++) { |
4490 | 296 int start, end; |
297 start = pos; | |
298 pos += s->exponent_bands[k][i]; | |
299 end = pos; | |
300 if (start < s->high_band_start[k]) | |
301 start = s->high_band_start[k]; | |
302 if (end > s->coefs_end[k]) | |
303 end = s->coefs_end[k]; | |
304 if (end > start) | |
305 s->exponent_high_bands[k][j++] = end - start; | |
306 } | |
307 s->exponent_high_sizes[k] = j; | |
308 #if 0 | |
4600 | 309 tprintf(s->avctx, "%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
310 s->frame_len >> k, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
311 s->coefs_end[k], |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
312 s->high_band_start[k], |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
313 s->exponent_high_sizes[k]); |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
314 for (j = 0; j < s->exponent_high_sizes[k]; j++) |
4600 | 315 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]); |
316 tprintf(s->avctx, "\n"); | |
4490 | 317 #endif |
318 } | |
319 } | |
320 | |
321 #ifdef TRACE | |
322 { | |
323 int i, j; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
324 for (i = 0; i < s->nb_block_sizes; i++) { |
4600 | 325 tprintf(s->avctx, "%5d: n=%2d:", |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
326 s->frame_len >> i, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
327 s->exponent_sizes[i]); |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
328 for (j = 0; j < s->exponent_sizes[i]; j++) |
4600 | 329 tprintf(s->avctx, " %d", s->exponent_bands[i][j]); |
330 tprintf(s->avctx, "\n"); | |
4490 | 331 } |
332 } | |
333 #endif | |
334 | |
335 /* init MDCT windows : simple sinus window */ | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
336 for (i = 0; i < s->nb_block_sizes; i++) { |
7572
d72f9295fe6e
Change wma.c to use the ff_sine_window_init() from mdct.c
superdump
parents:
5369
diff
changeset
|
337 int n; |
4490 | 338 n = 1 << (s->frame_len_bits - i); |
7682
a08c1a035386
Fix index to ff_sine_windows[]. Previously the index was usually in reverse
superdump
parents:
7582
diff
changeset
|
339 ff_sine_window_init(ff_sine_windows[s->frame_len_bits - i - 7], n); |
a08c1a035386
Fix index to ff_sine_windows[]. Previously the index was usually in reverse
superdump
parents:
7582
diff
changeset
|
340 s->windows[i] = ff_sine_windows[s->frame_len_bits - i - 7]; |
4490 | 341 } |
342 | |
343 s->reset_block_lengths = 1; | |
344 | |
345 if (s->use_noise_coding) { | |
346 | |
347 /* init the noise generator */ | |
348 if (s->use_exp_vlc) | |
349 s->noise_mult = 0.02; | |
350 else | |
351 s->noise_mult = 0.04; | |
352 | |
353 #ifdef TRACE | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
354 for (i = 0; i < NOISE_TAB_SIZE; i++) |
4490 | 355 s->noise_table[i] = 1.0 * s->noise_mult; |
356 #else | |
357 { | |
358 unsigned int seed; | |
359 float norm; | |
360 seed = 1; | |
361 norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
362 for (i = 0; i < NOISE_TAB_SIZE; i++) { |
4490 | 363 seed = seed * 314159 + 1; |
364 s->noise_table[i] = (float)((int)seed) * norm; | |
365 } | |
366 } | |
367 #endif | |
368 } | |
369 | |
370 /* choose the VLC tables for the coefficients */ | |
371 coef_vlc_table = 2; | |
372 if (s->sample_rate >= 32000) { | |
373 if (bps1 < 0.72) | |
374 coef_vlc_table = 0; | |
375 else if (bps1 < 1.16) | |
376 coef_vlc_table = 1; | |
377 } | |
378 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ]; | |
379 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1]; | |
380 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0], | |
381 s->coef_vlcs[0]); | |
382 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1], | |
383 s->coef_vlcs[1]); | |
384 | |
385 return 0; | |
386 } | |
387 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
388 int ff_wma_total_gain_to_bits(int total_gain) |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
389 { |
4490 | 390 if (total_gain < 15) return 13; |
391 else if (total_gain < 32) return 12; | |
392 else if (total_gain < 40) return 11; | |
393 else if (total_gain < 45) return 10; | |
394 else return 9; | |
395 } | |
396 | |
397 int ff_wma_end(AVCodecContext *avctx) | |
398 { | |
4601 | 399 WMACodecContext *s = avctx->priv_data; |
4490 | 400 int i; |
401 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
402 for (i = 0; i < s->nb_block_sizes; i++) |
4490 | 403 ff_mdct_end(&s->mdct_ctx[i]); |
404 | |
405 if (s->use_exp_vlc) { | |
406 free_vlc(&s->exp_vlc); | |
407 } | |
408 if (s->use_noise_coding) { | |
409 free_vlc(&s->hgain_vlc); | |
410 } | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
411 for (i = 0; i < 2; i++) { |
4490 | 412 free_vlc(&s->coef_vlc[i]); |
413 av_free(s->run_table[i]); | |
414 av_free(s->level_table[i]); | |
5369 | 415 av_free(s->int_table[i]); |
4490 | 416 } |
417 | |
418 return 0; | |
419 } |