annotate wma.c @ 11017:aa10bb3c244c libavcodec

optimize h264_loop_filter_strength_mmx2 244->160 cycles on core2
author lorenm
date Tue, 26 Jan 2010 17:17:48 +0000
parents c29ee479e359
children 1b6557975db1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
1 /*
0efc832d9102 wma encoder
michael
parents:
diff changeset
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
0efc832d9102 wma encoder
michael
parents:
diff changeset
4 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
0efc832d9102 wma encoder
michael
parents:
diff changeset
6 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0efc832d9102 wma encoder
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
0efc832d9102 wma encoder
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
0efc832d9102 wma encoder
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0efc832d9102 wma encoder
michael
parents:
diff changeset
11 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0efc832d9102 wma encoder
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0efc832d9102 wma encoder
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0efc832d9102 wma encoder
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
0efc832d9102 wma encoder
michael
parents:
diff changeset
16 *
0efc832d9102 wma encoder
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
0efc832d9102 wma encoder
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
0efc832d9102 wma encoder
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0efc832d9102 wma encoder
michael
parents:
diff changeset
20 */
0efc832d9102 wma encoder
michael
parents:
diff changeset
21
0efc832d9102 wma encoder
michael
parents:
diff changeset
22 #include "avcodec.h"
0efc832d9102 wma encoder
michael
parents:
diff changeset
23 #include "wma.h"
0efc832d9102 wma encoder
michael
parents:
diff changeset
24 #include "wmadata.h"
0efc832d9102 wma encoder
michael
parents:
diff changeset
25
0efc832d9102 wma encoder
michael
parents:
diff changeset
26 #undef NDEBUG
0efc832d9102 wma encoder
michael
parents:
diff changeset
27 #include <assert.h>
0efc832d9102 wma encoder
michael
parents:
diff changeset
28
0efc832d9102 wma encoder
michael
parents:
diff changeset
29 /* XXX: use same run/length optimization as mpeg decoders */
0efc832d9102 wma encoder
michael
parents:
diff changeset
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,
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
32 float **plevel_table, uint16_t **pint_table,
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
33 const CoefVLCTable *vlc_table)
0efc832d9102 wma encoder
michael
parents:
diff changeset
34 {
0efc832d9102 wma encoder
michael
parents:
diff changeset
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
0efc832d9102 wma encoder
michael
parents:
diff changeset
38 const uint16_t *levels_table = vlc_table->levels;
0efc832d9102 wma encoder
michael
parents:
diff changeset
39 uint16_t *run_table, *level_table, *int_table;
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
40 float *flevel_table;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
41 int i, l, j, k, level;
0efc832d9102 wma encoder
michael
parents:
diff changeset
42
0efc832d9102 wma encoder
michael
parents:
diff changeset
43 init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0);
0efc832d9102 wma encoder
michael
parents:
diff changeset
44
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
45 run_table = av_malloc(n * sizeof(uint16_t));
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
46 level_table = av_malloc(n * sizeof(uint16_t));
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
47 flevel_table= av_malloc(n * sizeof(*flevel_table));
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
48 int_table = av_malloc(n * sizeof(uint16_t));
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
49 i = 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
50 level = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
51 k = 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
52 while (i < n) {
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
53 int_table[k] = i;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
54 l = levels_table[k++];
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
55 for (j = 0; j < l; j++) {
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
56 run_table[i] = j;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
57 level_table[i] = level;
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
58 flevel_table[i]= level;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
59 i++;
0efc832d9102 wma encoder
michael
parents:
diff changeset
60 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
61 level++;
0efc832d9102 wma encoder
michael
parents:
diff changeset
62 }
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
63 *prun_table = run_table;
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
64 *plevel_table = flevel_table;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
65 *pint_table = int_table;
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
66 av_free(level_table);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
67 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
68
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
69 /**
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
70 *@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
71 *@param sample_rate output sample_rate
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
72 *@param version wma version
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
73 *@param decode_flags codec compression features
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
74 *@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
75 */
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
76 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
77 unsigned int decode_flags)
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
78 {
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
79
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
80 int frame_len_bits;
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
81
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
82 if (sample_rate <= 16000) {
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
83 frame_len_bits = 9;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
84 } else if (sample_rate <= 22050 ||
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
85 (sample_rate <= 32000 && version == 1)) {
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
86 frame_len_bits = 10;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
87 } else if (sample_rate <= 48000) {
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
88 frame_len_bits = 11;
9842
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
89 } else if (sample_rate <= 96000) {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
90 frame_len_bits = 12;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
91 } else {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
92 frame_len_bits = 13;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
93 }
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
94
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
95 if (version == 3) {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
96 int tmp = decode_flags & 0x6;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
97 if (tmp == 0x2) {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
98 ++frame_len_bits;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
99 } else if (tmp == 0x4) {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
100 --frame_len_bits;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
101 } else if (tmp == 0x6) {
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
102 frame_len_bits -= 2;
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
103 }
32d100ad81a6 Add additional sample rates to the frame len bits calculation code
faust3
parents: 9841
diff changeset
104 }
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
105
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
106 return frame_len_bits;
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
107 }
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
108
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
109 int ff_wma_init(AVCodecContext *avctx, int flags2)
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
110 {
4601
7b9ce6f729ae Rename WMADecodeContext to WMACodecContext
mbardiaux
parents: 4600
diff changeset
111 WMACodecContext *s = avctx->priv_data;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
112 int i;
0efc832d9102 wma encoder
michael
parents:
diff changeset
113 float bps1, high_freq;
0efc832d9102 wma encoder
michael
parents:
diff changeset
114 volatile float bps;
0efc832d9102 wma encoder
michael
parents:
diff changeset
115 int sample_rate1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
116 int coef_vlc_table;
0efc832d9102 wma encoder
michael
parents:
diff changeset
117
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
118 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
119 || avctx->channels <= 0 || avctx->channels > 8
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
120 || avctx->bit_rate <= 0)
5086
a10ebd496bd9 sanity checks (should prevent hypothetical div by zero issue)
michael
parents: 4737
diff changeset
121 return -1;
a10ebd496bd9 sanity checks (should prevent hypothetical div by zero issue)
michael
parents: 4737
diff changeset
122
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
123 s->sample_rate = avctx->sample_rate;
0efc832d9102 wma encoder
michael
parents:
diff changeset
124 s->nb_channels = avctx->channels;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
125 s->bit_rate = avctx->bit_rate;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
126 s->block_align = avctx->block_align;
0efc832d9102 wma encoder
michael
parents:
diff changeset
127
0efc832d9102 wma encoder
michael
parents:
diff changeset
128 dsputil_init(&s->dsp, avctx);
0efc832d9102 wma encoder
michael
parents:
diff changeset
129
0efc832d9102 wma encoder
michael
parents:
diff changeset
130 if (avctx->codec->id == CODEC_ID_WMAV1) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
131 s->version = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
132 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
133 s->version = 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
134 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
135
0efc832d9102 wma encoder
michael
parents:
diff changeset
136 /* compute MDCT block size */
9841
39bb2646fe00 Move frame len bits calculation to ff_wma_get_frame_len_bits
faust3
parents: 9840
diff changeset
137 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
138
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
139 s->frame_len = 1 << s->frame_len_bits;
0efc832d9102 wma encoder
michael
parents:
diff changeset
140 if (s->use_variable_block_len) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
141 int nb_max, nb;
0efc832d9102 wma encoder
michael
parents:
diff changeset
142 nb = ((flags2 >> 3) & 3) + 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
143 if ((s->bit_rate / s->nb_channels) >= 32000)
0efc832d9102 wma encoder
michael
parents:
diff changeset
144 nb += 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
145 nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
0efc832d9102 wma encoder
michael
parents:
diff changeset
146 if (nb > nb_max)
0efc832d9102 wma encoder
michael
parents:
diff changeset
147 nb = nb_max;
0efc832d9102 wma encoder
michael
parents:
diff changeset
148 s->nb_block_sizes = nb + 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
149 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
150 s->nb_block_sizes = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
151 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
152
4588
fc155ff94878 cosmetics: Fix another common typo, dependAnt --> dependEnt.
diego
parents: 4490
diff changeset
153 /* init rate dependent parameters */
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
154 s->use_noise_coding = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
155 high_freq = s->sample_rate * 0.5;
0efc832d9102 wma encoder
michael
parents:
diff changeset
156
0efc832d9102 wma encoder
michael
parents:
diff changeset
157 /* if version 2, then the rates are normalized */
0efc832d9102 wma encoder
michael
parents:
diff changeset
158 sample_rate1 = s->sample_rate;
0efc832d9102 wma encoder
michael
parents:
diff changeset
159 if (s->version == 2) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
160 if (sample_rate1 >= 44100) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
161 sample_rate1 = 44100;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
162 } else if (sample_rate1 >= 22050) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
163 sample_rate1 = 22050;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
164 } else if (sample_rate1 >= 16000) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
165 sample_rate1 = 16000;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
166 } else if (sample_rate1 >= 11025) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
167 sample_rate1 = 11025;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
168 } else if (sample_rate1 >= 8000) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
169 sample_rate1 = 8000;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
170 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
171 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
172
0efc832d9102 wma encoder
michael
parents:
diff changeset
173 bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
0efc832d9102 wma encoder
michael
parents:
diff changeset
174 s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0 + 0.5)) + 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
175
0efc832d9102 wma encoder
michael
parents:
diff changeset
176 /* compute high frequency value and choose if noise coding should
0efc832d9102 wma encoder
michael
parents:
diff changeset
177 be activated */
0efc832d9102 wma encoder
michael
parents:
diff changeset
178 bps1 = bps;
0efc832d9102 wma encoder
michael
parents:
diff changeset
179 if (s->nb_channels == 2)
0efc832d9102 wma encoder
michael
parents:
diff changeset
180 bps1 = bps * 1.6;
0efc832d9102 wma encoder
michael
parents:
diff changeset
181 if (sample_rate1 == 44100) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
182 if (bps1 >= 0.61) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
183 s->use_noise_coding = 0;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
184 } else {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
185 high_freq = high_freq * 0.4;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
186 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
187 } else if (sample_rate1 == 22050) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
188 if (bps1 >= 1.16) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
189 s->use_noise_coding = 0;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
190 } else if (bps1 >= 0.72) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
191 high_freq = high_freq * 0.7;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
192 } else {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
193 high_freq = high_freq * 0.6;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
194 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
195 } else if (sample_rate1 == 16000) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
196 if (bps > 0.5) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
197 high_freq = high_freq * 0.5;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
198 } else {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
199 high_freq = high_freq * 0.3;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
200 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
201 } else if (sample_rate1 == 11025) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
202 high_freq = high_freq * 0.7;
0efc832d9102 wma encoder
michael
parents:
diff changeset
203 } else if (sample_rate1 == 8000) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
204 if (bps <= 0.625) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
205 high_freq = high_freq * 0.5;
0efc832d9102 wma encoder
michael
parents:
diff changeset
206 } else if (bps > 0.75) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
207 s->use_noise_coding = 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
208 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
209 high_freq = high_freq * 0.65;
0efc832d9102 wma encoder
michael
parents:
diff changeset
210 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
211 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
212 if (bps >= 0.8) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
213 high_freq = high_freq * 0.75;
0efc832d9102 wma encoder
michael
parents:
diff changeset
214 } else if (bps >= 0.6) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
215 high_freq = high_freq * 0.6;
0efc832d9102 wma encoder
michael
parents:
diff changeset
216 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
217 high_freq = high_freq * 0.5;
0efc832d9102 wma encoder
michael
parents:
diff changeset
218 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
219 }
4652
6679d37a3338 Give context to dprintf
mbardiaux
parents: 4636
diff changeset
220 dprintf(s->avctx, "flags2=0x%x\n", flags2);
6679d37a3338 Give context to dprintf
mbardiaux
parents: 4636
diff changeset
221 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
222 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
223 s->block_align);
4652
6679d37a3338 Give context to dprintf
mbardiaux
parents: 4636
diff changeset
224 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
225 bps, bps1, high_freq, s->byte_offset_bits);
4652
6679d37a3338 Give context to dprintf
mbardiaux
parents: 4636
diff changeset
226 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
227 s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
228
0efc832d9102 wma encoder
michael
parents:
diff changeset
229 /* compute the scale factor band sizes for each MDCT block size */
0efc832d9102 wma encoder
michael
parents:
diff changeset
230 {
0efc832d9102 wma encoder
michael
parents:
diff changeset
231 int a, b, pos, lpos, k, block_len, i, j, n;
0efc832d9102 wma encoder
michael
parents:
diff changeset
232 const uint8_t *table;
0efc832d9102 wma encoder
michael
parents:
diff changeset
233
0efc832d9102 wma encoder
michael
parents:
diff changeset
234 if (s->version == 1) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
235 s->coefs_start = 3;
0efc832d9102 wma encoder
michael
parents:
diff changeset
236 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
237 s->coefs_start = 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
238 }
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
239 for (k = 0; k < s->nb_block_sizes; k++) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
240 block_len = s->frame_len >> k;
0efc832d9102 wma encoder
michael
parents:
diff changeset
241
0efc832d9102 wma encoder
michael
parents:
diff changeset
242 if (s->version == 1) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
243 lpos = 0;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
244 for (i = 0; i < 25; i++) {
10966
c29ee479e359 Export wma_critical_freqs as ff_wma_critical_freqs
daniel
parents: 10827
diff changeset
245 a = ff_wma_critical_freqs[i];
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
246 b = s->sample_rate;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
247 pos = ((block_len * 2 * a) + (b >> 1)) / b;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
248 if (pos > block_len)
0efc832d9102 wma encoder
michael
parents:
diff changeset
249 pos = block_len;
0efc832d9102 wma encoder
michael
parents:
diff changeset
250 s->exponent_bands[0][i] = pos - lpos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
251 if (pos >= block_len) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
252 i++;
0efc832d9102 wma encoder
michael
parents:
diff changeset
253 break;
0efc832d9102 wma encoder
michael
parents:
diff changeset
254 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
255 lpos = pos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
256 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
257 s->exponent_sizes[0] = i;
0efc832d9102 wma encoder
michael
parents:
diff changeset
258 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
259 /* hardcoded tables */
0efc832d9102 wma encoder
michael
parents:
diff changeset
260 table = NULL;
0efc832d9102 wma encoder
michael
parents:
diff changeset
261 a = s->frame_len_bits - BLOCK_MIN_BITS - k;
0efc832d9102 wma encoder
michael
parents:
diff changeset
262 if (a < 3) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
263 if (s->sample_rate >= 44100) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
264 table = exponent_band_44100[a];
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
265 } else if (s->sample_rate >= 32000) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
266 table = exponent_band_32000[a];
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
267 } else if (s->sample_rate >= 22050) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
268 table = exponent_band_22050[a];
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
269 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
270 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
271 if (table) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
272 n = *table++;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
273 for (i = 0; i < n; i++)
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
274 s->exponent_bands[k][i] = table[i];
0efc832d9102 wma encoder
michael
parents:
diff changeset
275 s->exponent_sizes[k] = n;
0efc832d9102 wma encoder
michael
parents:
diff changeset
276 } else {
0efc832d9102 wma encoder
michael
parents:
diff changeset
277 j = 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
278 lpos = 0;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
279 for (i = 0; i < 25; i++) {
10966
c29ee479e359 Export wma_critical_freqs as ff_wma_critical_freqs
daniel
parents: 10827
diff changeset
280 a = ff_wma_critical_freqs[i];
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
281 b = s->sample_rate;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
282 pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
283 pos <<= 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
284 if (pos > block_len)
0efc832d9102 wma encoder
michael
parents:
diff changeset
285 pos = block_len;
0efc832d9102 wma encoder
michael
parents:
diff changeset
286 if (pos > lpos)
0efc832d9102 wma encoder
michael
parents:
diff changeset
287 s->exponent_bands[k][j++] = pos - lpos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
288 if (pos >= block_len)
0efc832d9102 wma encoder
michael
parents:
diff changeset
289 break;
0efc832d9102 wma encoder
michael
parents:
diff changeset
290 lpos = pos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
291 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
292 s->exponent_sizes[k] = j;
0efc832d9102 wma encoder
michael
parents:
diff changeset
293 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
294 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
295
0efc832d9102 wma encoder
michael
parents:
diff changeset
296 /* max number of coefs */
0efc832d9102 wma encoder
michael
parents:
diff changeset
297 s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
0efc832d9102 wma encoder
michael
parents:
diff changeset
298 /* high freq computation */
0efc832d9102 wma encoder
michael
parents:
diff changeset
299 s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
0efc832d9102 wma encoder
michael
parents:
diff changeset
300 s->sample_rate + 0.5);
0efc832d9102 wma encoder
michael
parents:
diff changeset
301 n = s->exponent_sizes[k];
0efc832d9102 wma encoder
michael
parents:
diff changeset
302 j = 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
303 pos = 0;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
304 for (i = 0; i < n; i++) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
305 int start, end;
0efc832d9102 wma encoder
michael
parents:
diff changeset
306 start = pos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
307 pos += s->exponent_bands[k][i];
0efc832d9102 wma encoder
michael
parents:
diff changeset
308 end = pos;
0efc832d9102 wma encoder
michael
parents:
diff changeset
309 if (start < s->high_band_start[k])
0efc832d9102 wma encoder
michael
parents:
diff changeset
310 start = s->high_band_start[k];
0efc832d9102 wma encoder
michael
parents:
diff changeset
311 if (end > s->coefs_end[k])
0efc832d9102 wma encoder
michael
parents:
diff changeset
312 end = s->coefs_end[k];
0efc832d9102 wma encoder
michael
parents:
diff changeset
313 if (end > start)
0efc832d9102 wma encoder
michael
parents:
diff changeset
314 s->exponent_high_bands[k][j++] = end - start;
0efc832d9102 wma encoder
michael
parents:
diff changeset
315 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
316 s->exponent_high_sizes[k] = j;
0efc832d9102 wma encoder
michael
parents:
diff changeset
317 #if 0
4600
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
318 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
319 s->frame_len >> k,
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
320 s->coefs_end[k],
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
321 s->high_band_start[k],
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
322 s->exponent_high_sizes[k]);
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
323 for (j = 0; j < s->exponent_high_sizes[k]; j++)
4600
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
324 tprintf(s->avctx, " %d", s->exponent_high_bands[k][j]);
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
325 tprintf(s->avctx, "\n");
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
326 #endif
0efc832d9102 wma encoder
michael
parents:
diff changeset
327 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
328 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
329
0efc832d9102 wma encoder
michael
parents:
diff changeset
330 #ifdef TRACE
0efc832d9102 wma encoder
michael
parents:
diff changeset
331 {
0efc832d9102 wma encoder
michael
parents:
diff changeset
332 int i, j;
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
333 for (i = 0; i < s->nb_block_sizes; i++) {
4600
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
334 tprintf(s->avctx, "%5d: n=%2d:",
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
335 s->frame_len >> i,
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
336 s->exponent_sizes[i]);
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
337 for (j = 0; j < s->exponent_sizes[i]; j++)
4600
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
338 tprintf(s->avctx, " %d", s->exponent_bands[i][j]);
6ac364a4ce2b Supply context to tprintf
mbardiaux
parents: 4588
diff changeset
339 tprintf(s->avctx, "\n");
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
340 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
341 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
342 #endif
0efc832d9102 wma encoder
michael
parents:
diff changeset
343
0efc832d9102 wma encoder
michael
parents:
diff changeset
344 /* init MDCT windows : simple sinus window */
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
345 for (i = 0; i < s->nb_block_sizes; i++) {
10827
3d011a01a6a0 Add support for hard-coded MDCT-related ff_sine_windows tables.
reimar
parents: 10314
diff changeset
346 ff_init_ff_sine_windows(s->frame_len_bits - i);
10174
89cd870ca180 Add two more sizes to ff_sine_windows[] and also pad it with NULLs so
vitor
parents: 9872
diff changeset
347 s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
348 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
349
0efc832d9102 wma encoder
michael
parents:
diff changeset
350 s->reset_block_lengths = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
351
0efc832d9102 wma encoder
michael
parents:
diff changeset
352 if (s->use_noise_coding) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
353
0efc832d9102 wma encoder
michael
parents:
diff changeset
354 /* init the noise generator */
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
355 if (s->use_exp_vlc) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
356 s->noise_mult = 0.02;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
357 } else {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
358 s->noise_mult = 0.04;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
359 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
360
0efc832d9102 wma encoder
michael
parents:
diff changeset
361 #ifdef TRACE
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
0efc832d9102 wma encoder
michael
parents:
diff changeset
363 s->noise_table[i] = 1.0 * s->noise_mult;
0efc832d9102 wma encoder
michael
parents:
diff changeset
364 #else
0efc832d9102 wma encoder
michael
parents:
diff changeset
365 {
0efc832d9102 wma encoder
michael
parents:
diff changeset
366 unsigned int seed;
0efc832d9102 wma encoder
michael
parents:
diff changeset
367 float norm;
0efc832d9102 wma encoder
michael
parents:
diff changeset
368 seed = 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
369 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
370 for (i = 0; i < NOISE_TAB_SIZE; i++) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
371 seed = seed * 314159 + 1;
0efc832d9102 wma encoder
michael
parents:
diff changeset
372 s->noise_table[i] = (float)((int)seed) * norm;
0efc832d9102 wma encoder
michael
parents:
diff changeset
373 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
374 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
375 #endif
0efc832d9102 wma encoder
michael
parents:
diff changeset
376 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
377
0efc832d9102 wma encoder
michael
parents:
diff changeset
378 /* choose the VLC tables for the coefficients */
0efc832d9102 wma encoder
michael
parents:
diff changeset
379 coef_vlc_table = 2;
0efc832d9102 wma encoder
michael
parents:
diff changeset
380 if (s->sample_rate >= 32000) {
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
381 if (bps1 < 0.72) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
382 coef_vlc_table = 0;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
383 } else if (bps1 < 1.16) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
384 coef_vlc_table = 1;
9843
893b27768692 cosmetics: Add brackets between if/else
faust3
parents: 9842
diff changeset
385 }
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
386 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
387 s->coef_vlcs[0]= &coef_vlcs[coef_vlc_table * 2 ];
0efc832d9102 wma encoder
michael
parents:
diff changeset
388 s->coef_vlcs[1]= &coef_vlcs[coef_vlc_table * 2 + 1];
0efc832d9102 wma encoder
michael
parents:
diff changeset
389 init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0], &s->int_table[0],
0efc832d9102 wma encoder
michael
parents:
diff changeset
390 s->coef_vlcs[0]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
391 init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1], &s->int_table[1],
0efc832d9102 wma encoder
michael
parents:
diff changeset
392 s->coef_vlcs[1]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
393
0efc832d9102 wma encoder
michael
parents:
diff changeset
394 return 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
395 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
396
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
397 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
398 {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
399 if (total_gain < 15) return 13;
0efc832d9102 wma encoder
michael
parents:
diff changeset
400 else if (total_gain < 32) return 12;
0efc832d9102 wma encoder
michael
parents:
diff changeset
401 else if (total_gain < 40) return 11;
0efc832d9102 wma encoder
michael
parents:
diff changeset
402 else if (total_gain < 45) return 10;
0efc832d9102 wma encoder
michael
parents:
diff changeset
403 else return 9;
0efc832d9102 wma encoder
michael
parents:
diff changeset
404 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
405
0efc832d9102 wma encoder
michael
parents:
diff changeset
406 int ff_wma_end(AVCodecContext *avctx)
0efc832d9102 wma encoder
michael
parents:
diff changeset
407 {
4601
7b9ce6f729ae Rename WMADecodeContext to WMACodecContext
mbardiaux
parents: 4600
diff changeset
408 WMACodecContext *s = avctx->priv_data;
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
409 int i;
0efc832d9102 wma encoder
michael
parents:
diff changeset
410
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
411 for (i = 0; i < s->nb_block_sizes; i++)
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
412 ff_mdct_end(&s->mdct_ctx[i]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
413
0efc832d9102 wma encoder
michael
parents:
diff changeset
414 if (s->use_exp_vlc) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
415 free_vlc(&s->exp_vlc);
0efc832d9102 wma encoder
michael
parents:
diff changeset
416 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
417 if (s->use_noise_coding) {
0efc832d9102 wma encoder
michael
parents:
diff changeset
418 free_vlc(&s->hgain_vlc);
0efc832d9102 wma encoder
michael
parents:
diff changeset
419 }
9840
71066f133e1c cosmetics: Prettyprint and reformat wma.c closer to K&R style.
diego
parents: 8629
diff changeset
420 for (i = 0; i < 2; i++) {
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
421 free_vlc(&s->coef_vlc[i]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
422 av_free(s->run_table[i]);
0efc832d9102 wma encoder
michael
parents:
diff changeset
423 av_free(s->level_table[i]);
5369
04a241c308e8 fix mem leak
benoit
parents: 5086
diff changeset
424 av_free(s->int_table[i]);
4490
0efc832d9102 wma encoder
michael
parents:
diff changeset
425 }
0efc832d9102 wma encoder
michael
parents:
diff changeset
426
0efc832d9102 wma encoder
michael
parents:
diff changeset
427 return 0;
0efc832d9102 wma encoder
michael
parents:
diff changeset
428 }
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
429
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
430 /**
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
431 * Decode an uncompressed coefficient.
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
432 * @param s codec context
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
433 * @return the decoded coefficient
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
434 */
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
435 unsigned int ff_wma_get_large_val(GetBitContext* gb)
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
436 {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
437 /** consumes up to 34 bits */
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
438 int n_bits = 8;
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
439 /** decode length */
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
440 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
441 n_bits += 8;
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
442 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
443 n_bits += 8;
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
444 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
445 n_bits += 7;
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
446 }
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
447 }
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
448 }
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
449 return get_bits_long(gb, n_bits);
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
450 }
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
451
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
452 /**
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
453 * Decode run level compressed coefficients.
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
454 * @param avctx codec context
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
455 * @param gb bitstream reader context
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
456 * @param vlc vlc table for get_vlc2
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
457 * @param level_table level codes
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
458 * @param run_table run codes
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
459 * @param version 0 for wma1,2 1 for wmapro
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
460 * @param ptr output buffer
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
461 * @param offset offset in the output buffer
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
462 * @param num_coefs number of input coefficents
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
463 * @param block_len input buffer length (2^n)
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
464 * @param frame_len_bits number of bits for escaped run codes
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
465 * @param coef_nb_bits number of bits for escaped level codes
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
466 * @return 0 on success, -1 otherwise
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
467 */
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
468 int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
469 VLC *vlc,
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
470 const float *level_table, const uint16_t *run_table,
9868
5cc32c474caf Introduce WMACoef typedef for decoded coefficients
faust3
parents: 9844
diff changeset
471 int version, WMACoef *ptr, int offset,
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
472 int num_coefs, int block_len, int frame_len_bits,
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
473 int coef_nb_bits)
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
474 {
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
475 int code, level, sign;
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
476 const uint32_t *ilvl = (const uint32_t*)level_table;
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
477 uint32_t *iptr = (uint32_t*)ptr;
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
478 const unsigned int coef_mask = block_len - 1;
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
479 for (; offset < num_coefs; offset++) {
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
480 code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
481 if (code > 1) {
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
482 /** normal code */
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
483 offset += run_table[code];
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
484 sign = get_bits1(gb) - 1;
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
485 iptr[offset & coef_mask] = ilvl[code] ^ sign<<31;
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
486 } else if (code == 1) {
9872
01ccb357a33c Make remaining run level decode comments doxygen comments
faust3
parents: 9871
diff changeset
487 /** EOB */
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
488 break;
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
489 } else {
9872
01ccb357a33c Make remaining run level decode comments doxygen comments
faust3
parents: 9871
diff changeset
490 /** escape */
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
491 if (!version) {
9870
40638c6c2d69 Fix indentation after the previous commit
faust3
parents: 9869
diff changeset
492 level = get_bits(gb, coef_nb_bits);
9872
01ccb357a33c Make remaining run level decode comments doxygen comments
faust3
parents: 9871
diff changeset
493 /** NOTE: this is rather suboptimal. reading
01ccb357a33c Make remaining run level decode comments doxygen comments
faust3
parents: 9871
diff changeset
494 block_len_bits would be better */
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
495 offset += get_bits(gb, frame_len_bits);
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
496 } else {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
497 level = ff_wma_get_large_val(gb);
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
498 /** escape decode */
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
499 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
500 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
501 if (get_bits1(gb)) {
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
502 av_log(avctx,AV_LOG_ERROR,
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
503 "broken escape sequence\n");
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
504 return -1;
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
505 } else
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
506 offset += get_bits(gb, frame_len_bits) + 4;
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
507 } else
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
508 offset += get_bits(gb, 2) + 1;
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
509 }
9869
1f6b569bf958 Add support for escape coded wmapro run level coefficients
faust3
parents: 9868
diff changeset
510 }
10314
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
511 sign = get_bits1(gb) - 1;
ab687351bfef WMA: store level_table as floats, use type punning for sign flip in decode
mru
parents: 10174
diff changeset
512 ptr[offset & coef_mask] = (level^sign) - sign;
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
513 }
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
514 }
9871
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
515 /** NOTE: EOB can be omitted */
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
516 if (offset > num_coefs) {
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
517 av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
518 return -1;
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
519 }
4433ce8ef249 Simplify run level decoding:
faust3
parents: 9870
diff changeset
520
9844
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
521 return 0;
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
522 }
eb5916527064 Move run level decode functionality to ff_wma_run_level_decode
faust3
parents: 9843
diff changeset
523