Mercurial > libavcodec.hg
annotate wma.c @ 9841:39bb2646fe00 libavcodec
Move frame len bits calculation to ff_wma_get_frame_len_bits
so that it can be reused for wmapro
author | faust3 |
---|---|
date | Fri, 12 Jun 2009 15:21:43 +0000 |
parents | 71066f133e1c |
children | 32d100ad81a6 |
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; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
83 else |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
84 frame_len_bits = 11; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
85 |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
86 return frame_len_bits; |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
87 } |
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
88 |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
89 int ff_wma_init(AVCodecContext *avctx, int flags2) |
4490 | 90 { |
4601 | 91 WMACodecContext *s = avctx->priv_data; |
4490 | 92 int i; |
93 float bps1, high_freq; | |
94 volatile float bps; | |
95 int sample_rate1; | |
96 int coef_vlc_table; | |
97 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
98 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
|
99 || avctx->channels <= 0 || avctx->channels > 8 |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
100 || avctx->bit_rate <= 0) |
5086
a10ebd496bd9
sanity checks (should prevent hypothetical div by zero issue)
michael
parents:
4737
diff
changeset
|
101 return -1; |
a10ebd496bd9
sanity checks (should prevent hypothetical div by zero issue)
michael
parents:
4737
diff
changeset
|
102 |
4490 | 103 s->sample_rate = avctx->sample_rate; |
104 s->nb_channels = avctx->channels; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
105 s->bit_rate = avctx->bit_rate; |
4490 | 106 s->block_align = avctx->block_align; |
107 | |
108 dsputil_init(&s->dsp, avctx); | |
109 | |
110 if (avctx->codec->id == CODEC_ID_WMAV1) { | |
111 s->version = 1; | |
112 } else { | |
113 s->version = 2; | |
114 } | |
115 | |
116 /* compute MDCT block size */ | |
9841
39bb2646fe00
Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents:
9840
diff
changeset
|
117 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
|
118 |
4490 | 119 s->frame_len = 1 << s->frame_len_bits; |
120 if (s->use_variable_block_len) { | |
121 int nb_max, nb; | |
122 nb = ((flags2 >> 3) & 3) + 1; | |
123 if ((s->bit_rate / s->nb_channels) >= 32000) | |
124 nb += 2; | |
125 nb_max = s->frame_len_bits - BLOCK_MIN_BITS; | |
126 if (nb > nb_max) | |
127 nb = nb_max; | |
128 s->nb_block_sizes = nb + 1; | |
129 } else { | |
130 s->nb_block_sizes = 1; | |
131 } | |
132 | |
4588
fc155ff94878
cosmetics: Fix another common typo, dependAnt --> dependEnt.
diego
parents:
4490
diff
changeset
|
133 /* init rate dependent parameters */ |
4490 | 134 s->use_noise_coding = 1; |
135 high_freq = s->sample_rate * 0.5; | |
136 | |
137 /* if version 2, then the rates are normalized */ | |
138 sample_rate1 = s->sample_rate; | |
139 if (s->version == 2) { | |
140 if (sample_rate1 >= 44100) | |
141 sample_rate1 = 44100; | |
142 else if (sample_rate1 >= 22050) | |
143 sample_rate1 = 22050; | |
144 else if (sample_rate1 >= 16000) | |
145 sample_rate1 = 16000; | |
146 else if (sample_rate1 >= 11025) | |
147 sample_rate1 = 11025; | |
148 else if (sample_rate1 >= 8000) | |
149 sample_rate1 = 8000; | |
150 } | |
151 | |
152 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate); | |
153 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2; | |
154 | |
155 /* compute high frequency value and choose if noise coding should | |
156 be activated */ | |
157 bps1 = bps; | |
158 if (s->nb_channels == 2) | |
159 bps1 = bps * 1.6; | |
160 if (sample_rate1 == 44100) { | |
161 if (bps1 >= 0.61) | |
162 s->use_noise_coding = 0; | |
163 else | |
164 high_freq = high_freq * 0.4; | |
165 } else if (sample_rate1 == 22050) { | |
166 if (bps1 >= 1.16) | |
167 s->use_noise_coding = 0; | |
168 else if (bps1 >= 0.72) | |
169 high_freq = high_freq * 0.7; | |
170 else | |
171 high_freq = high_freq * 0.6; | |
172 } else if (sample_rate1 == 16000) { | |
173 if (bps > 0.5) | |
174 high_freq = high_freq * 0.5; | |
175 else | |
176 high_freq = high_freq * 0.3; | |
177 } else if (sample_rate1 == 11025) { | |
178 high_freq = high_freq * 0.7; | |
179 } else if (sample_rate1 == 8000) { | |
180 if (bps <= 0.625) { | |
181 high_freq = high_freq * 0.5; | |
182 } else if (bps > 0.75) { | |
183 s->use_noise_coding = 0; | |
184 } else { | |
185 high_freq = high_freq * 0.65; | |
186 } | |
187 } else { | |
188 if (bps >= 0.8) { | |
189 high_freq = high_freq * 0.75; | |
190 } else if (bps >= 0.6) { | |
191 high_freq = high_freq * 0.6; | |
192 } else { | |
193 high_freq = high_freq * 0.5; | |
194 } | |
195 } | |
4652 | 196 dprintf(s->avctx, "flags2=0x%x\n", flags2); |
197 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
|
198 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
|
199 s->block_align); |
4652 | 200 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
|
201 bps, bps1, high_freq, s->byte_offset_bits); |
4652 | 202 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
|
203 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); |
4490 | 204 |
205 /* compute the scale factor band sizes for each MDCT block size */ | |
206 { | |
207 int a, b, pos, lpos, k, block_len, i, j, n; | |
208 const uint8_t *table; | |
209 | |
210 if (s->version == 1) { | |
211 s->coefs_start = 3; | |
212 } else { | |
213 s->coefs_start = 0; | |
214 } | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
215 for (k = 0; k < s->nb_block_sizes; k++) { |
4490 | 216 block_len = s->frame_len >> k; |
217 | |
218 if (s->version == 1) { | |
219 lpos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
220 for (i = 0; i < 25; i++) { |
4490 | 221 a = wma_critical_freqs[i]; |
222 b = s->sample_rate; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
223 pos = ((block_len * 2 * a) + (b >> 1)) / b; |
4490 | 224 if (pos > block_len) |
225 pos = block_len; | |
226 s->exponent_bands[0][i] = pos - lpos; | |
227 if (pos >= block_len) { | |
228 i++; | |
229 break; | |
230 } | |
231 lpos = pos; | |
232 } | |
233 s->exponent_sizes[0] = i; | |
234 } else { | |
235 /* hardcoded tables */ | |
236 table = NULL; | |
237 a = s->frame_len_bits - BLOCK_MIN_BITS - k; | |
238 if (a < 3) { | |
239 if (s->sample_rate >= 44100) | |
240 table = exponent_band_44100[a]; | |
241 else if (s->sample_rate >= 32000) | |
242 table = exponent_band_32000[a]; | |
243 else if (s->sample_rate >= 22050) | |
244 table = exponent_band_22050[a]; | |
245 } | |
246 if (table) { | |
247 n = *table++; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
248 for (i = 0; i < n; i++) |
4490 | 249 s->exponent_bands[k][i] = table[i]; |
250 s->exponent_sizes[k] = n; | |
251 } else { | |
252 j = 0; | |
253 lpos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
254 for (i = 0; i < 25; i++) { |
4490 | 255 a = wma_critical_freqs[i]; |
256 b = s->sample_rate; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
257 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b); |
4490 | 258 pos <<= 2; |
259 if (pos > block_len) | |
260 pos = block_len; | |
261 if (pos > lpos) | |
262 s->exponent_bands[k][j++] = pos - lpos; | |
263 if (pos >= block_len) | |
264 break; | |
265 lpos = pos; | |
266 } | |
267 s->exponent_sizes[k] = j; | |
268 } | |
269 } | |
270 | |
271 /* max number of coefs */ | |
272 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k; | |
273 /* high freq computation */ | |
274 s->high_band_start[k] = (int)((block_len * 2 * high_freq) / | |
275 s->sample_rate + 0.5); | |
276 n = s->exponent_sizes[k]; | |
277 j = 0; | |
278 pos = 0; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
279 for (i = 0; i < n; i++) { |
4490 | 280 int start, end; |
281 start = pos; | |
282 pos += s->exponent_bands[k][i]; | |
283 end = pos; | |
284 if (start < s->high_band_start[k]) | |
285 start = s->high_band_start[k]; | |
286 if (end > s->coefs_end[k]) | |
287 end = s->coefs_end[k]; | |
288 if (end > start) | |
289 s->exponent_high_bands[k][j++] = end - start; | |
290 } | |
291 s->exponent_high_sizes[k] = j; | |
292 #if 0 | |
4600 | 293 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
|
294 s->frame_len >> k, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
295 s->coefs_end[k], |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
296 s->high_band_start[k], |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
297 s->exponent_high_sizes[k]); |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
298 for (j = 0; j < s->exponent_high_sizes[k]; j++) |
4600 | 299 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]); |
300 tprintf(s->avctx, "\n"); | |
4490 | 301 #endif |
302 } | |
303 } | |
304 | |
305 #ifdef TRACE | |
306 { | |
307 int i, j; | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
308 for (i = 0; i < s->nb_block_sizes; i++) { |
4600 | 309 tprintf(s->avctx, "%5d: n=%2d:", |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
310 s->frame_len >> i, |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
311 s->exponent_sizes[i]); |
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
312 for (j = 0; j < s->exponent_sizes[i]; j++) |
4600 | 313 tprintf(s->avctx, " %d", s->exponent_bands[i][j]); |
314 tprintf(s->avctx, "\n"); | |
4490 | 315 } |
316 } | |
317 #endif | |
318 | |
319 /* init MDCT windows : simple sinus window */ | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
320 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
|
321 int n; |
4490 | 322 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
|
323 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
|
324 s->windows[i] = ff_sine_windows[s->frame_len_bits - i - 7]; |
4490 | 325 } |
326 | |
327 s->reset_block_lengths = 1; | |
328 | |
329 if (s->use_noise_coding) { | |
330 | |
331 /* init the noise generator */ | |
332 if (s->use_exp_vlc) | |
333 s->noise_mult = 0.02; | |
334 else | |
335 s->noise_mult = 0.04; | |
336 | |
337 #ifdef TRACE | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
338 for (i = 0; i < NOISE_TAB_SIZE; i++) |
4490 | 339 s->noise_table[i] = 1.0 * s->noise_mult; |
340 #else | |
341 { | |
342 unsigned int seed; | |
343 float norm; | |
344 seed = 1; | |
345 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
|
346 for (i = 0; i < NOISE_TAB_SIZE; i++) { |
4490 | 347 seed = seed * 314159 + 1; |
348 s->noise_table[i] = (float)((int)seed) * norm; | |
349 } | |
350 } | |
351 #endif | |
352 } | |
353 | |
354 /* choose the VLC tables for the coefficients */ | |
355 coef_vlc_table = 2; | |
356 if (s->sample_rate >= 32000) { | |
357 if (bps1 < 0.72) | |
358 coef_vlc_table = 0; | |
359 else if (bps1 < 1.16) | |
360 coef_vlc_table = 1; | |
361 } | |
362 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ]; | |
363 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1]; | |
364 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0], | |
365 s->coef_vlcs[0]); | |
366 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1], | |
367 s->coef_vlcs[1]); | |
368 | |
369 return 0; | |
370 } | |
371 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
372 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
|
373 { |
4490 | 374 if (total_gain < 15) return 13; |
375 else if (total_gain < 32) return 12; | |
376 else if (total_gain < 40) return 11; | |
377 else if (total_gain < 45) return 10; | |
378 else return 9; | |
379 } | |
380 | |
381 int ff_wma_end(AVCodecContext *avctx) | |
382 { | |
4601 | 383 WMACodecContext *s = avctx->priv_data; |
4490 | 384 int i; |
385 | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
386 for (i = 0; i < s->nb_block_sizes; i++) |
4490 | 387 ff_mdct_end(&s->mdct_ctx[i]); |
388 | |
389 if (s->use_exp_vlc) { | |
390 free_vlc(&s->exp_vlc); | |
391 } | |
392 if (s->use_noise_coding) { | |
393 free_vlc(&s->hgain_vlc); | |
394 } | |
9840
71066f133e1c
cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents:
8629
diff
changeset
|
395 for (i = 0; i < 2; i++) { |
4490 | 396 free_vlc(&s->coef_vlc[i]); |
397 av_free(s->run_table[i]); | |
398 av_free(s->level_table[i]); | |
5369 | 399 av_free(s->int_table[i]); |
4490 | 400 } |
401 | |
402 return 0; | |
403 } |