Originally committed as revision 6839 to svn://svn.ffmpeg.org/ffmpeg/trunk
Kostya Shishkov authored on 2006/10/30 22:48:48... | ... |
@@ -934,6 +934,7 @@ following image formats are supported: |
934 | 934 |
@item WavPack Audio @tab @tab X |
935 | 935 |
@item Cin Audio @tab @tab X |
936 | 936 |
@tab Codec used in Delphine Software games. |
937 |
+@item Intel Music Coder @tab @tab X |
|
937 | 938 |
@end multitable |
938 | 939 |
|
939 | 940 |
@code{X} means that encoding (resp. decoding) is supported. |
... | ... |
@@ -88,6 +88,7 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o |
88 | 88 |
OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o |
89 | 89 |
OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o |
90 | 90 |
OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o |
91 |
+OBJS-$(CONFIG_IMC_DECODER) += imc.o |
|
91 | 92 |
OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o |
92 | 93 |
OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o |
93 | 94 |
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o |
... | ... |
@@ -563,6 +563,9 @@ void avcodec_register_all(void) |
563 | 563 |
#ifdef CONFIG_TIFF_DECODER |
564 | 564 |
register_avcodec(&tiff_decoder); |
565 | 565 |
#endif //CONFIG_TIFF_DECODER |
566 |
+#ifdef CONFIG_IMC_DECODER |
|
567 |
+ register_avcodec(&imc_decoder); |
|
568 |
+#endif //CONFIG_IMC_DECODER |
|
566 | 569 |
|
567 | 570 |
#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) |
568 | 571 |
#ifdef CONFIG_AMR_NB_DECODER |
... | ... |
@@ -37,8 +37,8 @@ extern "C" { |
37 | 37 |
#define AV_STRINGIFY(s) AV_TOSTRING(s) |
38 | 38 |
#define AV_TOSTRING(s) #s |
39 | 39 |
|
40 |
-#define LIBAVCODEC_VERSION_INT ((51<<16)+(22<<8)+0) |
|
41 |
-#define LIBAVCODEC_VERSION 51.22.0 |
|
40 |
+#define LIBAVCODEC_VERSION_INT ((51<<16)+(23<<8)+0) |
|
41 |
+#define LIBAVCODEC_VERSION 51.23.0 |
|
42 | 42 |
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT |
43 | 43 |
|
44 | 44 |
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) |
... | ... |
@@ -233,6 +233,7 @@ enum CodecID { |
233 | 233 |
CODEC_ID_QCELP, |
234 | 234 |
CODEC_ID_WAVPACK, |
235 | 235 |
CODEC_ID_DSICINAUDIO, |
236 |
+ CODEC_ID_IMC, |
|
236 | 237 |
|
237 | 238 |
/* subtitle codecs */ |
238 | 239 |
CODEC_ID_DVD_SUBTITLE= 0x17000, |
... | ... |
@@ -2304,6 +2305,7 @@ extern AVCodec dsicinvideo_decoder; |
2304 | 2304 |
extern AVCodec dsicinaudio_decoder; |
2305 | 2305 |
extern AVCodec tiertexseqvideo_decoder; |
2306 | 2306 |
extern AVCodec tiff_decoder; |
2307 |
+extern AVCodec imc_decoder; |
|
2307 | 2308 |
|
2308 | 2309 |
/* pcm codecs */ |
2309 | 2310 |
#define PCM_CODEC(id, name) \ |
2310 | 2311 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,816 @@ |
0 |
+/* |
|
1 |
+ * IMC compatible decoder |
|
2 |
+ * Copyright (c) 2002-2004 Maxim Poliakovski |
|
3 |
+ * Copyright (c) 2006 Benjamin Larsson |
|
4 |
+ * Copyright (c) 2006 Konstantin Shishkov |
|
5 |
+ * |
|
6 |
+ * This file is part of FFmpeg. |
|
7 |
+ * |
|
8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
10 |
+ * License as published by the Free Software Foundation; either |
|
11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
12 |
+ * |
|
13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
+ * Lesser General Public License for more details. |
|
17 |
+ * |
|
18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+/** |
|
25 |
+ * @file imc.c IMC - Intel Music Coder |
|
26 |
+ * A mdct based codec using a 256 points large transform |
|
27 |
+ * divied into 32 bands with some mix of scale factors. |
|
28 |
+ * Only mono is supported. |
|
29 |
+ * |
|
30 |
+ */ |
|
31 |
+ |
|
32 |
+ |
|
33 |
+#include <math.h> |
|
34 |
+#include <stddef.h> |
|
35 |
+#include <stdio.h> |
|
36 |
+ |
|
37 |
+#define ALT_BITSTREAM_READER |
|
38 |
+#include "avcodec.h" |
|
39 |
+#include "bitstream.h" |
|
40 |
+#include "dsputil.h" |
|
41 |
+ |
|
42 |
+#include "imcdata.h" |
|
43 |
+ |
|
44 |
+#define IMC_FRAME_ID 0x21 |
|
45 |
+#define BANDS 32 |
|
46 |
+#define COEFFS 256 |
|
47 |
+ |
|
48 |
+typedef struct { |
|
49 |
+ float old_floor[BANDS]; |
|
50 |
+ float flcoeffs1[BANDS]; |
|
51 |
+ float flcoeffs2[BANDS]; |
|
52 |
+ float flcoeffs3[BANDS]; |
|
53 |
+ float flcoeffs4[BANDS]; |
|
54 |
+ float flcoeffs5[BANDS]; |
|
55 |
+ float flcoeffs6[BANDS]; |
|
56 |
+ float CWdecoded[COEFFS]; |
|
57 |
+ |
|
58 |
+ /** MDCT tables */ |
|
59 |
+ //@{ |
|
60 |
+ float mdct_sine_window[COEFFS]; |
|
61 |
+ float post_cos[COEFFS]; |
|
62 |
+ float post_sin[COEFFS]; |
|
63 |
+ float pre_coef1[COEFFS]; |
|
64 |
+ float pre_coef2[COEFFS]; |
|
65 |
+ float last_fft_im[COEFFS]; |
|
66 |
+ //@} |
|
67 |
+ |
|
68 |
+ int bandWidthT[BANDS]; ///< codewords per band |
|
69 |
+ int bitsBandT[BANDS]; ///< how many bits per codeword in band |
|
70 |
+ int CWlengthT[COEFFS]; ///< how many bits in each codeword |
|
71 |
+ int levlCoeffBuf[BANDS]; |
|
72 |
+ int bandFlagsBuf[BANDS]; ///< flags for each band |
|
73 |
+ int sumLenArr[BANDS]; ///< bits for all coeffs in band |
|
74 |
+ int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not |
|
75 |
+ int skipFlagBits[BANDS]; ///< bits used to code skip flags |
|
76 |
+ int skipFlagCount[BANDS]; ///< skipped coeffients per band |
|
77 |
+ int skipFlags[COEFFS]; ///< skip coefficient decoding or not |
|
78 |
+ int codewords[COEFFS]; ///< raw codewords read from bitstream |
|
79 |
+ float sqrt_tab[30]; |
|
80 |
+ GetBitContext gb; |
|
81 |
+ VLC huffman_vlc[4][4]; |
|
82 |
+ float flcf1, flcf2; |
|
83 |
+ int decoder_reset; |
|
84 |
+ float one_div_log2; |
|
85 |
+ |
|
86 |
+ DSPContext dsp; |
|
87 |
+ FFTContext fft; |
|
88 |
+ DECLARE_ALIGNED_16(FFTComplex, samples[COEFFS/2]); |
|
89 |
+ DECLARE_ALIGNED_16(float, out_samples[COEFFS]); |
|
90 |
+} IMCContext; |
|
91 |
+ |
|
92 |
+ |
|
93 |
+static int imc_decode_init(AVCodecContext * avctx) |
|
94 |
+{ |
|
95 |
+ int i, j; |
|
96 |
+ IMCContext *q = avctx->priv_data; |
|
97 |
+ double r1, r2; |
|
98 |
+ |
|
99 |
+ q->decoder_reset = 1; |
|
100 |
+ |
|
101 |
+ for(i = 0; i < BANDS; i++) |
|
102 |
+ q->old_floor[i] = 1.0; |
|
103 |
+ |
|
104 |
+ /* Build mdct window, a simple sine window normalized with sqrt(2) */ |
|
105 |
+ for(i = 0; i < COEFFS; i++) |
|
106 |
+ q->mdct_sine_window[i] = sin((i + 0.5) / 512.0 * M_PI) * sqrt(2.0); |
|
107 |
+ for(i = 0; i < COEFFS/2; i++){ |
|
108 |
+ q->post_cos[i] = cos(i / 256.0 * M_PI); |
|
109 |
+ q->post_sin[i] = sin(i / 256.0 * M_PI); |
|
110 |
+ |
|
111 |
+ r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI); |
|
112 |
+ r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI); |
|
113 |
+ |
|
114 |
+ if (i & 0x1) |
|
115 |
+ { |
|
116 |
+ q->pre_coef1[i] = (r1 + r2) * sqrt(2.0); |
|
117 |
+ q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0); |
|
118 |
+ } |
|
119 |
+ else |
|
120 |
+ { |
|
121 |
+ q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0); |
|
122 |
+ q->pre_coef2[i] = (r1 - r2) * sqrt(2.0); |
|
123 |
+ } |
|
124 |
+ |
|
125 |
+ q->last_fft_im[i] = 0; |
|
126 |
+ } |
|
127 |
+ q->flcf1 = log2(10) * 0.05703125; |
|
128 |
+ q->flcf2 = log2(10) * 0.25; |
|
129 |
+ |
|
130 |
+ /* Generate a square root table */ |
|
131 |
+ |
|
132 |
+ for(i = 0; i < 30; i++) { |
|
133 |
+ q->sqrt_tab[i] = sqrt(i); |
|
134 |
+ } |
|
135 |
+ |
|
136 |
+ /* initialize the VLC tables */ |
|
137 |
+ for(i = 0; i < 4 ; i++) { |
|
138 |
+ for(j = 0; j < 4; j++) { |
|
139 |
+ init_vlc (&q->huffman_vlc[i][j], 9, imc_huffman_sizes[i], |
|
140 |
+ imc_huffman_lens[i][j], 1, 1, |
|
141 |
+ imc_huffman_bits[i][j], 2, 2, 0); |
|
142 |
+ } |
|
143 |
+ } |
|
144 |
+ q->one_div_log2 = 1/log(2); |
|
145 |
+ |
|
146 |
+ ff_fft_init(&q->fft, 7, 1); |
|
147 |
+ dsputil_init(&q->dsp, avctx); |
|
148 |
+ return 0; |
|
149 |
+} |
|
150 |
+ |
|
151 |
+static void imc_calculate_coeffs(IMCContext* q, float* flcoeffs1, float* flcoeffs2, int* bandWidthT, |
|
152 |
+ float* flcoeffs3, float* flcoeffs5) |
|
153 |
+{ |
|
154 |
+ float workT1[BANDS]; |
|
155 |
+ float workT2[BANDS]; |
|
156 |
+ float workT3[BANDS]; |
|
157 |
+ float snr_limit = 1.e-30; |
|
158 |
+ float accum = 0.0; |
|
159 |
+ int i, cnt2; |
|
160 |
+ |
|
161 |
+ for(i = 0; i < BANDS; i++) { |
|
162 |
+ flcoeffs5[i] = workT2[i] = 0.0; |
|
163 |
+ if (bandWidthT[i]){ |
|
164 |
+ workT1[i] = flcoeffs1[i] * flcoeffs1[i]; |
|
165 |
+ flcoeffs3[i] = 2.0 * flcoeffs2[i]; |
|
166 |
+ } else { |
|
167 |
+ workT1[i] = 0.0; |
|
168 |
+ flcoeffs3[i] = -30000.0; |
|
169 |
+ } |
|
170 |
+ workT3[i] = bandWidthT[i] * workT1[i] * 0.01; |
|
171 |
+ if (workT3[i] <= snr_limit) |
|
172 |
+ workT3[i] = 0.0; |
|
173 |
+ } |
|
174 |
+ |
|
175 |
+ for(i = 0; i < BANDS; i++) { |
|
176 |
+ for(cnt2 = i; cnt2 < cyclTab[i]; cnt2++) |
|
177 |
+ flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i]; |
|
178 |
+ workT2[cnt2-1] = workT2[cnt2-1] + workT3[i]; |
|
179 |
+ } |
|
180 |
+ |
|
181 |
+ for(i = 1; i < BANDS; i++) { |
|
182 |
+ accum = (workT2[i-1] + accum) * imc_weights1[i-1]; |
|
183 |
+ flcoeffs5[i] += accum; |
|
184 |
+ } |
|
185 |
+ |
|
186 |
+ for(i = 0; i < BANDS; i++) |
|
187 |
+ workT2[i] = 0.0; |
|
188 |
+ |
|
189 |
+ for(i = 0; i < BANDS; i++) { |
|
190 |
+ for(cnt2 = i-1; cnt2 > cyclTab2[i]; cnt2--) |
|
191 |
+ flcoeffs5[cnt2] += workT3[i]; |
|
192 |
+ workT2[cnt2+1] += workT3[i]; |
|
193 |
+ } |
|
194 |
+ |
|
195 |
+ accum = 0.0; |
|
196 |
+ |
|
197 |
+ for(i = BANDS-2; i >= 0; i--) { |
|
198 |
+ accum = (workT2[i+1] + accum) * imc_weights2[i]; |
|
199 |
+ flcoeffs5[i] += accum; |
|
200 |
+ //there is missing code here, but it seems to never be triggered |
|
201 |
+ } |
|
202 |
+} |
|
203 |
+ |
|
204 |
+ |
|
205 |
+static void imc_read_level_coeffs(IMCContext* q, int stream_format_code, int* levlCoeffs) |
|
206 |
+{ |
|
207 |
+ int i; |
|
208 |
+ VLC *hufftab[4]; |
|
209 |
+ int start = 0; |
|
210 |
+ const uint8_t *cb_sel; |
|
211 |
+ int s; |
|
212 |
+ |
|
213 |
+ s = stream_format_code >> 1; |
|
214 |
+ hufftab[0] = &q->huffman_vlc[s][0]; |
|
215 |
+ hufftab[1] = &q->huffman_vlc[s][1]; |
|
216 |
+ hufftab[2] = &q->huffman_vlc[s][2]; |
|
217 |
+ hufftab[3] = &q->huffman_vlc[s][3]; |
|
218 |
+ cb_sel = imc_cb_select[s]; |
|
219 |
+ |
|
220 |
+ if(stream_format_code & 4) |
|
221 |
+ start = 1; |
|
222 |
+ if(start) |
|
223 |
+ levlCoeffs[0] = get_bits(&q->gb, 7); |
|
224 |
+ for(i = start; i < BANDS; i++){ |
|
225 |
+ levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table, hufftab[cb_sel[i]]->bits, 2); |
|
226 |
+ if(levlCoeffs[i] == 17) |
|
227 |
+ levlCoeffs[i] += get_bits(&q->gb, 4); |
|
228 |
+ } |
|
229 |
+} |
|
230 |
+ |
|
231 |
+static void imc_decode_level_coefficients(IMCContext* q, int* levlCoeffBuf, float* flcoeffs1, |
|
232 |
+ float* flcoeffs2) |
|
233 |
+{ |
|
234 |
+ int i, level; |
|
235 |
+ float tmp, tmp2; |
|
236 |
+ //maybe some frequency division thingy |
|
237 |
+ |
|
238 |
+ flcoeffs1[0] = 20000.0 / pow (2, levlCoeffBuf[0] * q->flcf1); |
|
239 |
+ flcoeffs2[0] = log2(flcoeffs1[0]); |
|
240 |
+ tmp = flcoeffs1[0]; |
|
241 |
+ tmp2 = flcoeffs2[0]; |
|
242 |
+ |
|
243 |
+ for(i = 1; i < BANDS; i++) { |
|
244 |
+ level = levlCoeffBuf[i]; |
|
245 |
+ if (level == 16) { |
|
246 |
+ flcoeffs1[i] = 1.0; |
|
247 |
+ flcoeffs2[i] = 0.0; |
|
248 |
+ } else { |
|
249 |
+ if (level < 17) |
|
250 |
+ level -=7; |
|
251 |
+ else if (level <= 24) |
|
252 |
+ level -=32; |
|
253 |
+ else |
|
254 |
+ level -=16; |
|
255 |
+ |
|
256 |
+ tmp *= imc_exp_tab[15 + level]; |
|
257 |
+ tmp2 += q->flcf2 * level; |
|
258 |
+ flcoeffs1[i] = tmp; |
|
259 |
+ flcoeffs2[i] = tmp2; |
|
260 |
+ } |
|
261 |
+ } |
|
262 |
+} |
|
263 |
+ |
|
264 |
+ |
|
265 |
+static void imc_decode_level_coefficients2(IMCContext* q, int* levlCoeffBuf, float* old_floor, float* flcoeffs1, |
|
266 |
+ float* flcoeffs2) { |
|
267 |
+ int i; |
|
268 |
+ //FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors |
|
269 |
+ // and flcoeffs2 old scale factors |
|
270 |
+ // might be incomplete due to a missing table that is in the binary code |
|
271 |
+ for(i = 0; i < BANDS; i++) { |
|
272 |
+ flcoeffs1[i] = 0; |
|
273 |
+ if(levlCoeffBuf[i] < 16) { |
|
274 |
+ flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i]; |
|
275 |
+ flcoeffs2[i] = (levlCoeffBuf[i]-7) * q->flcf2 + flcoeffs2[i]; |
|
276 |
+ } else { |
|
277 |
+ flcoeffs1[i] = old_floor[i]; |
|
278 |
+ } |
|
279 |
+ } |
|
280 |
+} |
|
281 |
+ |
|
282 |
+/** |
|
283 |
+ * Perform bit allocation depending on bits available |
|
284 |
+ */ |
|
285 |
+static int bit_allocation (IMCContext* q, int stream_format_code, int freebits, int flag) { |
|
286 |
+ int i, j; |
|
287 |
+ const float limit = -1.e20; |
|
288 |
+ float highest = 0.0; |
|
289 |
+ int indx; |
|
290 |
+ int t1 = 0; |
|
291 |
+ int t2 = 1; |
|
292 |
+ float summa = 0.0; |
|
293 |
+ int iacc = 0; |
|
294 |
+ int summer = 0; |
|
295 |
+ int rres, cwlen; |
|
296 |
+ float lowest = 1.e10; |
|
297 |
+ int low_indx = 0; |
|
298 |
+ float workT[32]; |
|
299 |
+ int flg; |
|
300 |
+ int found_indx = 0; |
|
301 |
+ |
|
302 |
+ for(i = 0; i < BANDS; i++) |
|
303 |
+ highest = FFMAX(highest, q->flcoeffs1[i]); |
|
304 |
+ |
|
305 |
+ for(i = 0; i < BANDS-1; i++) { |
|
306 |
+ q->flcoeffs4[i] = q->flcoeffs3[i] - log2(q->flcoeffs5[i]); |
|
307 |
+ } |
|
308 |
+ q->flcoeffs4[BANDS - 1] = limit; |
|
309 |
+ |
|
310 |
+ highest = highest * 0.25; |
|
311 |
+ |
|
312 |
+ for(i = 0; i < BANDS; i++) { |
|
313 |
+ indx = -1; |
|
314 |
+ if ((band_tab[i+1] - band_tab[i]) == q->bandWidthT[i]) |
|
315 |
+ indx = 0; |
|
316 |
+ |
|
317 |
+ if ((band_tab[i+1] - band_tab[i]) > q->bandWidthT[i]) |
|
318 |
+ indx = 1; |
|
319 |
+ |
|
320 |
+ if (((band_tab[i+1] - band_tab[i])/2) >= q->bandWidthT[i]) |
|
321 |
+ indx = 2; |
|
322 |
+ |
|
323 |
+ if (indx == -1) |
|
324 |
+ return -1; |
|
325 |
+ |
|
326 |
+ q->flcoeffs4[i] = q->flcoeffs4[i] + xTab[(indx*2 + (q->flcoeffs1[i] < highest)) * 2 + flag]; |
|
327 |
+ } |
|
328 |
+ |
|
329 |
+ if (stream_format_code & 0x2) { |
|
330 |
+ q->flcoeffs4[0] = limit; |
|
331 |
+ q->flcoeffs4[1] = limit; |
|
332 |
+ q->flcoeffs4[2] = limit; |
|
333 |
+ q->flcoeffs4[3] = limit; |
|
334 |
+ } |
|
335 |
+ |
|
336 |
+ for(i = (stream_format_code & 0x2)?4:0; i < BANDS-1; i++) { |
|
337 |
+ iacc += q->bandWidthT[i]; |
|
338 |
+ summa += q->bandWidthT[i] * q->flcoeffs4[i]; |
|
339 |
+ } |
|
340 |
+ q->bandWidthT[BANDS-1] = 0; |
|
341 |
+ summa = (summa * 0.5 - freebits) / iacc; |
|
342 |
+ |
|
343 |
+ |
|
344 |
+ for(i = 0; i < BANDS/2; i++) { |
|
345 |
+ rres = summer - freebits; |
|
346 |
+ if((rres >= -8) && (rres <= 8)) break; |
|
347 |
+ |
|
348 |
+ summer = 0; |
|
349 |
+ iacc = 0; |
|
350 |
+ |
|
351 |
+ for(j = (stream_format_code & 0x2)?4:0; j < BANDS; j++) { |
|
352 |
+ cwlen = clip((int)((q->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); |
|
353 |
+ |
|
354 |
+ q->bitsBandT[j] = cwlen; |
|
355 |
+ summer += q->bandWidthT[j] * cwlen; |
|
356 |
+ |
|
357 |
+ if (cwlen > 0) |
|
358 |
+ iacc += q->bandWidthT[j]; |
|
359 |
+ } |
|
360 |
+ |
|
361 |
+ flg = t2; |
|
362 |
+ t2 = 1; |
|
363 |
+ if (freebits < summer) |
|
364 |
+ t2 = -1; |
|
365 |
+ if (i == 0) |
|
366 |
+ flg = t2; |
|
367 |
+ if(flg != t2) |
|
368 |
+ t1++; |
|
369 |
+ |
|
370 |
+ summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa; |
|
371 |
+ } |
|
372 |
+ |
|
373 |
+ for(i = (stream_format_code & 0x2)?4:0; i < BANDS; i++) { |
|
374 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) |
|
375 |
+ q->CWlengthT[j] = q->bitsBandT[i]; |
|
376 |
+ } |
|
377 |
+ |
|
378 |
+ if (freebits > summer) { |
|
379 |
+ for(i = 0; i < BANDS; i++) { |
|
380 |
+ workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415); |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ highest = 0.0; |
|
384 |
+ |
|
385 |
+ do{ |
|
386 |
+ if (highest <= -1.e20) |
|
387 |
+ break; |
|
388 |
+ |
|
389 |
+ found_indx = 0; |
|
390 |
+ highest = -1.e20; |
|
391 |
+ |
|
392 |
+ for(i = 0; i < BANDS; i++) { |
|
393 |
+ if (workT[i] > highest) { |
|
394 |
+ highest = workT[i]; |
|
395 |
+ found_indx = i; |
|
396 |
+ } |
|
397 |
+ } |
|
398 |
+ |
|
399 |
+ if (highest > -1.e20) { |
|
400 |
+ workT[found_indx] -= 2.0; |
|
401 |
+ if (++(q->bitsBandT[found_indx]) == 6) |
|
402 |
+ workT[found_indx] = -1.e20; |
|
403 |
+ |
|
404 |
+ for(j = band_tab[found_indx]; j < band_tab[found_indx+1] && (freebits > summer); j++){ |
|
405 |
+ q->CWlengthT[j]++; |
|
406 |
+ summer++; |
|
407 |
+ } |
|
408 |
+ } |
|
409 |
+ }while (freebits > summer); |
|
410 |
+ } |
|
411 |
+ if (freebits < summer) { |
|
412 |
+ for(i = 0; i < BANDS; i++) { |
|
413 |
+ workT[i] = q->bitsBandT[i] ? (q->bitsBandT[i] * -2 + q->flcoeffs4[i] + 1.585) : 1.e20; |
|
414 |
+ } |
|
415 |
+ if (stream_format_code & 0x2) { |
|
416 |
+ workT[0] = 1.e20; |
|
417 |
+ workT[1] = 1.e20; |
|
418 |
+ workT[2] = 1.e20; |
|
419 |
+ workT[3] = 1.e20; |
|
420 |
+ } |
|
421 |
+ while (freebits < summer){ |
|
422 |
+ lowest = 1.e10; |
|
423 |
+ low_indx = 0; |
|
424 |
+ for(i = 0; i < BANDS; i++) { |
|
425 |
+ if (workT[i] < lowest) { |
|
426 |
+ lowest = workT[i]; |
|
427 |
+ low_indx = i; |
|
428 |
+ } |
|
429 |
+ } |
|
430 |
+ //if(lowest >= 1.e10) break; |
|
431 |
+ workT[low_indx] = lowest + 2.0; |
|
432 |
+ |
|
433 |
+ if (!(--q->bitsBandT[low_indx])) |
|
434 |
+ workT[low_indx] = 1.e20; |
|
435 |
+ |
|
436 |
+ for(j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++){ |
|
437 |
+ if(q->CWlengthT[j] > 0){ |
|
438 |
+ q->CWlengthT[j]--; |
|
439 |
+ summer--; |
|
440 |
+ } |
|
441 |
+ } |
|
442 |
+ } |
|
443 |
+ } |
|
444 |
+ return 0; |
|
445 |
+} |
|
446 |
+ |
|
447 |
+static void imc_get_skip_coeff(IMCContext* q) { |
|
448 |
+ int i, j; |
|
449 |
+ |
|
450 |
+ memset(q->skipFlagBits, 0, sizeof(q->skipFlagBits)); |
|
451 |
+ memset(q->skipFlagCount, 0, sizeof(q->skipFlagCount)); |
|
452 |
+ for(i = 0; i < BANDS; i++) { |
|
453 |
+ if (!q->bandFlagsBuf[i] || !q->bandWidthT[i]) |
|
454 |
+ continue; |
|
455 |
+ |
|
456 |
+ if (!q->skipFlagRaw[i]) { |
|
457 |
+ q->skipFlagBits[i] = band_tab[i+1] - band_tab[i]; |
|
458 |
+ |
|
459 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) { |
|
460 |
+ if ((q->skipFlags[j] = get_bits(&q->gb,1))) |
|
461 |
+ q->skipFlagCount[i]++; |
|
462 |
+ } |
|
463 |
+ } else { |
|
464 |
+ for(j = band_tab[i]; j < (band_tab[i+1]-1); j += 2) { |
|
465 |
+ if(!get_bits1(&q->gb)){//0 |
|
466 |
+ q->skipFlagBits[i]++; |
|
467 |
+ q->skipFlags[j]=1; |
|
468 |
+ q->skipFlags[j+1]=1; |
|
469 |
+ q->skipFlagCount[i] += 2; |
|
470 |
+ }else{ |
|
471 |
+ if(get_bits1(&q->gb)){//11 |
|
472 |
+ q->skipFlagBits[i] +=2; |
|
473 |
+ q->skipFlags[j]=0; |
|
474 |
+ q->skipFlags[j+1]=1; |
|
475 |
+ q->skipFlagCount[i]++; |
|
476 |
+ }else{ |
|
477 |
+ q->skipFlagBits[i] +=3; |
|
478 |
+ q->skipFlags[j+1]=0; |
|
479 |
+ if(!get_bits1(&q->gb)){//100 |
|
480 |
+ q->skipFlags[j]=1; |
|
481 |
+ q->skipFlagCount[i]++; |
|
482 |
+ }else{//101 |
|
483 |
+ q->skipFlags[j]=0; |
|
484 |
+ } |
|
485 |
+ } |
|
486 |
+ } |
|
487 |
+ } |
|
488 |
+ |
|
489 |
+ if (j < band_tab[i+1]) { |
|
490 |
+ q->skipFlagBits[i]++; |
|
491 |
+ if ((q->skipFlags[j] = get_bits(&q->gb,1))) |
|
492 |
+ q->skipFlagCount[i]++; |
|
493 |
+ } |
|
494 |
+ } |
|
495 |
+ } |
|
496 |
+} |
|
497 |
+ |
|
498 |
+/** |
|
499 |
+ * Increase highest' band coefficient sizes as some bits won't be used |
|
500 |
+ */ |
|
501 |
+static void imc_adjust_bit_allocation (IMCContext* q, int summer) { |
|
502 |
+ float workT[32]; |
|
503 |
+ int corrected = 0; |
|
504 |
+ int i, j; |
|
505 |
+ float highest = 0; |
|
506 |
+ int found_indx=0; |
|
507 |
+ |
|
508 |
+ for(i = 0; i < BANDS; i++) { |
|
509 |
+ workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415); |
|
510 |
+ } |
|
511 |
+ |
|
512 |
+ while (corrected < summer) { |
|
513 |
+ if(highest <= -1.e20) |
|
514 |
+ break; |
|
515 |
+ |
|
516 |
+ highest = -1.e20; |
|
517 |
+ |
|
518 |
+ for(i = 0; i < BANDS; i++) { |
|
519 |
+ if (workT[i] > highest) { |
|
520 |
+ highest = workT[i]; |
|
521 |
+ found_indx = i; |
|
522 |
+ } |
|
523 |
+ } |
|
524 |
+ |
|
525 |
+ if (highest > -1.e20) { |
|
526 |
+ workT[found_indx] -= 2.0; |
|
527 |
+ if (++(q->bitsBandT[found_indx]) == 6) |
|
528 |
+ workT[found_indx] = -1.e20; |
|
529 |
+ |
|
530 |
+ for(j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) { |
|
531 |
+ if (!q->skipFlags[j] && (q->CWlengthT[j] < 6)) { |
|
532 |
+ q->CWlengthT[j]++; |
|
533 |
+ corrected++; |
|
534 |
+ } |
|
535 |
+ } |
|
536 |
+ } |
|
537 |
+ } |
|
538 |
+} |
|
539 |
+ |
|
540 |
+void imc_imdct256(IMCContext *q) { |
|
541 |
+ int i; |
|
542 |
+ float re, im; |
|
543 |
+ |
|
544 |
+ /* prerotation */ |
|
545 |
+ for(i=0; i < COEFFS/2; i++){ |
|
546 |
+ q->samples[i].re = -(q->pre_coef1[i] * q->CWdecoded[COEFFS-1-i*2]) - |
|
547 |
+ (q->pre_coef2[i] * q->CWdecoded[i*2]); |
|
548 |
+ q->samples[i].im = (q->pre_coef2[i] * q->CWdecoded[COEFFS-1-i*2]) - |
|
549 |
+ (q->pre_coef1[i] * q->CWdecoded[i*2]); |
|
550 |
+ } |
|
551 |
+ |
|
552 |
+ /* FFT */ |
|
553 |
+ ff_fft_permute(&q->fft, q->samples); |
|
554 |
+ ff_fft_calc (&q->fft, q->samples); |
|
555 |
+ |
|
556 |
+ /* postrotation, window and reorder */ |
|
557 |
+ for(i = 0; i < COEFFS/2; i++){ |
|
558 |
+ re = (q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]); |
|
559 |
+ im = (-q->samples[i].im * q->post_cos[i]) - (q->samples[i].re * q->post_sin[i]); |
|
560 |
+ q->out_samples[i*2] = (q->mdct_sine_window[COEFFS-1-i*2] * q->last_fft_im[i]) + (q->mdct_sine_window[i*2] * re); |
|
561 |
+ q->out_samples[COEFFS-1-i*2] = (q->mdct_sine_window[i*2] * q->last_fft_im[i]) - (q->mdct_sine_window[COEFFS-1-i*2] * re); |
|
562 |
+ q->last_fft_im[i] = im; |
|
563 |
+ } |
|
564 |
+} |
|
565 |
+ |
|
566 |
+static int inverse_quant_coeff (IMCContext* q, int stream_format_code) { |
|
567 |
+ int i, j; |
|
568 |
+ int middle_value, cw_len, max_size; |
|
569 |
+ const float* quantizer; |
|
570 |
+ |
|
571 |
+ for(i = 0; i < BANDS; i++) { |
|
572 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) { |
|
573 |
+ q->CWdecoded[j] = 0; |
|
574 |
+ cw_len = q->CWlengthT[j]; |
|
575 |
+ |
|
576 |
+ if (cw_len <= 0 || q->skipFlags[j]) |
|
577 |
+ continue; |
|
578 |
+ |
|
579 |
+ max_size = 1 << cw_len; |
|
580 |
+ middle_value = max_size >> 1; |
|
581 |
+ |
|
582 |
+ if (q->codewords[j] >= max_size || q->codewords[j] < 0) |
|
583 |
+ return -1; |
|
584 |
+ |
|
585 |
+ if (cw_len >= 4){ |
|
586 |
+ quantizer = imc_quantizer2[(stream_format_code & 2) >> 1]; |
|
587 |
+ if (q->codewords[j] >= middle_value) |
|
588 |
+ q->CWdecoded[j] = quantizer[q->codewords[j] - 8] * q->flcoeffs6[i]; |
|
589 |
+ else |
|
590 |
+ q->CWdecoded[j] = -quantizer[max_size - q->codewords[j] - 8 - 1] * q->flcoeffs6[i]; |
|
591 |
+ }else{ |
|
592 |
+ quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (q->bandFlagsBuf[i] << 1)]; |
|
593 |
+ if (q->codewords[j] >= middle_value) |
|
594 |
+ q->CWdecoded[j] = quantizer[q->codewords[j] - 1] * q->flcoeffs6[i]; |
|
595 |
+ else |
|
596 |
+ q->CWdecoded[j] = -quantizer[max_size - 2 - q->codewords[j]] * q->flcoeffs6[i]; |
|
597 |
+ } |
|
598 |
+ } |
|
599 |
+ } |
|
600 |
+ return 0; |
|
601 |
+} |
|
602 |
+ |
|
603 |
+ |
|
604 |
+static int imc_get_coeffs (IMCContext* q) { |
|
605 |
+ int i, j, cw_len, cw; |
|
606 |
+ |
|
607 |
+ for(i = 0; i < BANDS; i++) { |
|
608 |
+ if(!q->sumLenArr[i]) continue; |
|
609 |
+ if (q->bandFlagsBuf[i] || q->bandWidthT[i]) { |
|
610 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) { |
|
611 |
+ cw_len = q->CWlengthT[j]; |
|
612 |
+ cw = 0; |
|
613 |
+ |
|
614 |
+ if (get_bits_count(&q->gb) + cw_len > 512){ |
|
615 |
+//av_log(NULL,0,"Band %i coeff %i cw_len %i\n",i,j,cw_len); |
|
616 |
+ return -1; |
|
617 |
+ } |
|
618 |
+ |
|
619 |
+ if(cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j])) |
|
620 |
+ cw = get_bits(&q->gb, cw_len); |
|
621 |
+ |
|
622 |
+ q->codewords[j] = cw; |
|
623 |
+ } |
|
624 |
+ } |
|
625 |
+ } |
|
626 |
+ return 0; |
|
627 |
+} |
|
628 |
+ |
|
629 |
+static int imc_decode_frame(AVCodecContext * avctx, |
|
630 |
+ void *data, int *data_size, |
|
631 |
+ uint8_t * buf, int buf_size) |
|
632 |
+{ |
|
633 |
+ |
|
634 |
+ IMCContext *q = avctx->priv_data; |
|
635 |
+ |
|
636 |
+ int stream_format_code; |
|
637 |
+ int imc_hdr, i, j; |
|
638 |
+ int flag; |
|
639 |
+ int bits, summer; |
|
640 |
+ int counter, bitscount; |
|
641 |
+ uint16_t *buf16 = (uint16_t *) buf; |
|
642 |
+ |
|
643 |
+ /* FIXME: input should not be modified */ |
|
644 |
+ for(i = 0; i < FFMIN(buf_size, avctx->block_align) / 2; i++) |
|
645 |
+ buf16[i] = bswap_16(buf16[i]); |
|
646 |
+ |
|
647 |
+ init_get_bits(&q->gb, buf, 512); |
|
648 |
+ |
|
649 |
+ /* Check the frame header */ |
|
650 |
+ imc_hdr = get_bits(&q->gb, 9); |
|
651 |
+ if (imc_hdr != IMC_FRAME_ID) { |
|
652 |
+ av_log(avctx, AV_LOG_ERROR, "imc frame header check failed!\n"); |
|
653 |
+ av_log(avctx, AV_LOG_ERROR, "got %x instead of 0x21.\n", imc_hdr); |
|
654 |
+ return -1; |
|
655 |
+ } |
|
656 |
+ stream_format_code = get_bits(&q->gb, 3); |
|
657 |
+ |
|
658 |
+ if(stream_format_code & 1){ |
|
659 |
+ av_log(avctx, AV_LOG_ERROR, "Stream code format %X is not supported\n", stream_format_code); |
|
660 |
+ return -1; |
|
661 |
+ } |
|
662 |
+ |
|
663 |
+// av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code); |
|
664 |
+ |
|
665 |
+ if (stream_format_code & 0x04) |
|
666 |
+ q->decoder_reset = 1; |
|
667 |
+ |
|
668 |
+ if(q->decoder_reset) { |
|
669 |
+ memset(q->out_samples, 0, sizeof(q->out_samples)); |
|
670 |
+ for(i = 0; i < BANDS; i++)q->old_floor[i] = 1.0; |
|
671 |
+ for(i = 0; i < COEFFS; i++)q->CWdecoded[i] = 0; |
|
672 |
+ q->decoder_reset = 0; |
|
673 |
+ } |
|
674 |
+ |
|
675 |
+ flag = get_bits1(&q->gb); |
|
676 |
+ imc_read_level_coeffs(q, stream_format_code, q->levlCoeffBuf); |
|
677 |
+ |
|
678 |
+ if (stream_format_code & 0x4) |
|
679 |
+ imc_decode_level_coefficients(q, q->levlCoeffBuf, q->flcoeffs1, q->flcoeffs2); |
|
680 |
+ else |
|
681 |
+ imc_decode_level_coefficients2(q, q->levlCoeffBuf, q->old_floor, q->flcoeffs1, q->flcoeffs2); |
|
682 |
+ |
|
683 |
+ memcpy(q->old_floor, q->flcoeffs1, 32 * sizeof(float)); |
|
684 |
+ |
|
685 |
+ counter = 0; |
|
686 |
+ for (i=0 ; i<BANDS ; i++) { |
|
687 |
+ if (q->levlCoeffBuf[i] == 16) { |
|
688 |
+ q->bandWidthT[i] = 0; |
|
689 |
+ counter++; |
|
690 |
+ } else |
|
691 |
+ q->bandWidthT[i] = band_tab[i+1] - band_tab[i]; |
|
692 |
+ } |
|
693 |
+ memset(q->bandFlagsBuf, 0, BANDS * sizeof(int)); |
|
694 |
+ for(i = 0; i < BANDS-1; i++) { |
|
695 |
+ if (q->bandWidthT[i]) |
|
696 |
+ q->bandFlagsBuf[i] = get_bits1(&q->gb); |
|
697 |
+ } |
|
698 |
+ |
|
699 |
+ imc_calculate_coeffs(q, q->flcoeffs1, q->flcoeffs2, q->bandWidthT, q->flcoeffs3, q->flcoeffs5); |
|
700 |
+ |
|
701 |
+ bitscount = 0; |
|
702 |
+ /* first 4 bands will be assigned 5 bits per coefficient */ |
|
703 |
+ if (stream_format_code & 0x2) { |
|
704 |
+ bitscount += 15; |
|
705 |
+ |
|
706 |
+ q->bitsBandT[0] = 5; |
|
707 |
+ q->CWlengthT[0] = 5; |
|
708 |
+ q->CWlengthT[1] = 5; |
|
709 |
+ q->CWlengthT[2] = 5; |
|
710 |
+ for(i = 1; i < 4; i++){ |
|
711 |
+ bits = (q->levlCoeffBuf[i] == 16) ? 0 : 5; |
|
712 |
+ q->bitsBandT[i] = bits; |
|
713 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) { |
|
714 |
+ q->CWlengthT[j] = bits; |
|
715 |
+ bitscount += bits; |
|
716 |
+ } |
|
717 |
+ } |
|
718 |
+ } |
|
719 |
+ |
|
720 |
+ if(bit_allocation (q, stream_format_code, 512 - bitscount - get_bits_count(&q->gb), flag) < 0) { |
|
721 |
+ av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n"); |
|
722 |
+ q->decoder_reset = 1; |
|
723 |
+ return -1; |
|
724 |
+ } |
|
725 |
+ |
|
726 |
+ for(i = 0; i < BANDS; i++) { |
|
727 |
+ q->sumLenArr[i] = 0; |
|
728 |
+ q->skipFlagRaw[i] = 0; |
|
729 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) |
|
730 |
+ q->sumLenArr[i] += q->CWlengthT[j]; |
|
731 |
+ if (q->bandFlagsBuf[i]) |
|
732 |
+ if( (((band_tab[i+1] - band_tab[i]) * 1.5) > q->sumLenArr[i]) && (q->sumLenArr[i] > 0)) |
|
733 |
+ q->skipFlagRaw[i] = 1; |
|
734 |
+ } |
|
735 |
+ |
|
736 |
+ imc_get_skip_coeff(q); |
|
737 |
+ |
|
738 |
+ for(i = 0; i < BANDS; i++) { |
|
739 |
+ q->flcoeffs6[i] = q->flcoeffs1[i]; |
|
740 |
+ /* band has flag set and at least one coded coefficient */ |
|
741 |
+ if (q->bandFlagsBuf[i] && (band_tab[i+1] - band_tab[i]) != q->skipFlagCount[i]){ |
|
742 |
+ q->flcoeffs6[i] *= q->sqrt_tab[band_tab[i+1] - band_tab[i]] / |
|
743 |
+ q->sqrt_tab[(band_tab[i+1] - band_tab[i] - q->skipFlagCount[i])]; |
|
744 |
+ } |
|
745 |
+ } |
|
746 |
+ |
|
747 |
+ /* calculate bits left, bits needed and adjust bit allocation */ |
|
748 |
+ bits = summer = 0; |
|
749 |
+ |
|
750 |
+ for(i = 0; i < BANDS; i++) { |
|
751 |
+ if (q->bandFlagsBuf[i]) { |
|
752 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) { |
|
753 |
+ if(q->skipFlags[j]) { |
|
754 |
+ summer += q->CWlengthT[j]; |
|
755 |
+ q->CWlengthT[j] = 0; |
|
756 |
+ } |
|
757 |
+ } |
|
758 |
+ bits += q->skipFlagBits[i]; |
|
759 |
+ summer -= q->skipFlagBits[i]; |
|
760 |
+ } |
|
761 |
+ } |
|
762 |
+ imc_adjust_bit_allocation(q, summer); |
|
763 |
+ |
|
764 |
+ for(i = 0; i < BANDS; i++) { |
|
765 |
+ q->sumLenArr[i] = 0; |
|
766 |
+ |
|
767 |
+ for(j = band_tab[i]; j < band_tab[i+1]; j++) |
|
768 |
+ if (!q->skipFlags[j]) |
|
769 |
+ q->sumLenArr[i] += q->CWlengthT[j]; |
|
770 |
+ } |
|
771 |
+ |
|
772 |
+ memset(q->codewords, 0, sizeof(q->codewords)); |
|
773 |
+ |
|
774 |
+ if(imc_get_coeffs(q) < 0) { |
|
775 |
+ av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n"); |
|
776 |
+ q->decoder_reset = 1; |
|
777 |
+ return 0; |
|
778 |
+ } |
|
779 |
+ |
|
780 |
+ if(inverse_quant_coeff(q, stream_format_code) < 0) { |
|
781 |
+ av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n"); |
|
782 |
+ q->decoder_reset = 1; |
|
783 |
+ return 0; |
|
784 |
+ } |
|
785 |
+ |
|
786 |
+ memset(q->skipFlags, 0, sizeof(q->skipFlags)); |
|
787 |
+ |
|
788 |
+ imc_imdct256(q); |
|
789 |
+ |
|
790 |
+ q->dsp.float_to_int16(data, q->out_samples, COEFFS); |
|
791 |
+ |
|
792 |
+ *data_size = COEFFS * sizeof(int16_t); |
|
793 |
+ |
|
794 |
+ return avctx->block_align; |
|
795 |
+} |
|
796 |
+ |
|
797 |
+ |
|
798 |
+static int imc_decode_close(AVCodecContext * avctx) |
|
799 |
+{ |
|
800 |
+ IMCContext *q = avctx->priv_data; |
|
801 |
+ |
|
802 |
+ ff_fft_end(&q->fft); |
|
803 |
+ return 0; |
|
804 |
+} |
|
805 |
+ |
|
806 |
+ |
|
807 |
+AVCodec imc_decoder = { |
|
808 |
+ .name = "imc", |
|
809 |
+ .type = CODEC_TYPE_AUDIO, |
|
810 |
+ .id = CODEC_ID_IMC, |
|
811 |
+ .priv_data_size = sizeof(IMCContext), |
|
812 |
+ .init = imc_decode_init, |
|
813 |
+ .close = imc_decode_close, |
|
814 |
+ .decode = imc_decode_frame, |
|
815 |
+}; |
0 | 816 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,164 @@ |
0 |
+/* |
|
1 |
+ * IMC compatible decoder |
|
2 |
+ * Copyright (c) 2002-2004 Maxim Poliakovski |
|
3 |
+ * Copyright (c) 2006 Benjamin Larsson |
|
4 |
+ * Copyright (c) 2006 Konstantin Shishkov |
|
5 |
+ * |
|
6 |
+ * This file is part of FFmpeg. |
|
7 |
+ * |
|
8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
10 |
+ * License as published by the Free Software Foundation; either |
|
11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
12 |
+ * |
|
13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
+ * Lesser General Public License for more details. |
|
17 |
+ * |
|
18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+static const uint16_t band_tab[33] = { |
|
25 |
+ 0, 3, 6, 9, 12, 16, 20, 24, 29, 34, 40, |
|
26 |
+ 46, 53, 60, 68, 76, 84, 93, 102, 111, 121, 131, |
|
27 |
+ 141, 151, 162, 173, 184, 195, 207, 219, 231, 243, 256, |
|
28 |
+}; |
|
29 |
+ |
|
30 |
+ |
|
31 |
+static const int8_t cyclTab[32] = { |
|
32 |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
|
33 |
+ 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, |
|
34 |
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 32, |
|
35 |
+}; |
|
36 |
+ |
|
37 |
+static const int8_t cyclTab2[32] = { |
|
38 |
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
|
39 |
+ 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, |
|
40 |
+23, 24, 25, 26, 27, 28, 29}; |
|
41 |
+ |
|
42 |
+static const float imc_weights1[31] = { |
|
43 |
+ 0.119595, 0.123124, 0.129192, 9.97377e-2, 8.1923e-2, 9.61153e-2, 8.77885e-2, 8.61174e-2, |
|
44 |
+ 9.00882e-2, 9.91658e-2, 0.112991, 0.131126, 0.152886, 0.177292, 0.221782, 0.244917, 0.267386, |
|
45 |
+ 0.306816, 0.323046, 0.33729, 0.366773, 0.392557, 0.398076, 0.403302, 0.42451, 0.444777, |
|
46 |
+ 0.449188, 0.455445, 0.477853, 0.500669, 0.510395}; |
|
47 |
+ |
|
48 |
+static const float imc_weights2[31] = { |
|
49 |
+ 3.23466e-3, 3.49886e-3, 3.98413e-3, 1.98116e-3, 1.16465e-3, 1.79283e-3, 1.40372e-3, 1.33274e-3, |
|
50 |
+ 1.50523e-3, 1.95064e-3, 2.77472e-3, 4.14725e-3, 6.2776e-3, 9.36401e-3, 1.71397e-2, 2.24052e-2, |
|
51 |
+ 2.83971e-2, 4.11689e-2, 4.73165e-2, 5.31631e-2, 6.66614e-2, 8.00824e-2, 8.31588e-2, 8.61397e-2, |
|
52 |
+ 9.89229e-2, 0.112197, 0.115227, 0.119613, 0.136174, 0.15445, 0.162685}; |
|
53 |
+ |
|
54 |
+static const float imc_quantizer1[4][8] = { |
|
55 |
+ { 8.4431201e-1, 4.7358301e-1, 1.448354, 2.7073899e-1, 7.4449003e-1, 1.241991, 1.845484, 0.0}, |
|
56 |
+ { 8.6876702e-1, 4.7659001e-1, 1.478224, 2.5672799e-1, 7.55777e-1, 1.3229851, 2.03438, 0.0}, |
|
57 |
+ { 7.5891501e-1, 6.2272799e-1, 1.271322, 3.47904e-1, 7.5317699e-1, 1.150767, 1.628476, 0.0}, |
|
58 |
+ { 7.65257e-1, 6.44647e-1, 1.263824, 3.4548101e-1, 7.6384902e-1, 1.214466, 1.7638789, 0.0}, |
|
59 |
+}; |
|
60 |
+ |
|
61 |
+static const float imc_quantizer2[2][56] = { |
|
62 |
+ { 1.39236e-1, 3.50548e-1, 5.9547901e-1, 8.5772401e-1, 1.121545, 1.3882281, 1.695882, 2.1270809, |
|
63 |
+ 7.2221003e-2, 1.85177e-1, 2.9521701e-1, 4.12568e-1, 5.4068601e-1, 6.7679501e-1, 8.1196898e-1, 9.4765198e-1, |
|
64 |
+ 1.0779999, 1.203415, 1.337265, 1.481871, 1.639982, 1.814766, 2.0701399, 2.449862, |
|
65 |
+ 3.7533998e-2, 1.02722e-1, 1.6021401e-1, 2.16043e-1, 2.7231601e-1, 3.3025399e-1, 3.9022601e-1, 4.52849e-1, |
|
66 |
+ 5.1794899e-1, 5.8529502e-1, 6.53956e-1, 7.2312802e-1, 7.9150802e-1, 8.5891002e-1, 9.28141e-1, 9.9706203e-1, |
|
67 |
+ 1.062153, 1.12564, 1.189834, 1.256122, 1.324469, 1.3955311, 1.468906, 1.545084, |
|
68 |
+ 1.6264729, 1.711524, 1.802705, 1.91023, 2.0533991, 2.22333, 2.4830019, 3.253329 }, |
|
69 |
+ { 1.11654e-1, 3.54469e-1, 6.4232099e-1, 9.6128798e-1, 1.295053, 1.61777, 1.989839, 2.51107, |
|
70 |
+ 5.7721999e-2, 1.69879e-1, 2.97589e-1, 4.3858799e-1, 5.9039903e-1, 7.4934798e-1, 9.1628098e-1, 1.087297, |
|
71 |
+ 1.262751, 1.4288321, 1.6040879, 1.79067, 2.000668, 2.2394669, 2.649332, 5.2760072, |
|
72 |
+ 2.9722e-2, 8.7316997e-2, 1.4445201e-1, 2.04247e-1, 2.6879501e-1, 3.3716801e-1, 4.08811e-1, 4.8306999e-1, |
|
73 |
+ 5.6049401e-1, 6.3955498e-1, 7.2044599e-1, 8.0427998e-1, 8.8933599e-1, 9.7537601e-1, 1.062461, 1.1510431, |
|
74 |
+ 1.240236, 1.326715, 1.412513, 1.500502, 1.591749, 1.686413, 1.785239, 1.891233, |
|
75 |
+ 2.0051291, 2.127681, 2.2709141, 2.475826, 2.7219379, 3.101985, 4.686213, 6.2287788}, |
|
76 |
+}; |
|
77 |
+ |
|
78 |
+ |
|
79 |
+static const float xTab[14] = {7.6, 3.6, 4.4, 3.7, 6.1, 5.1, 2.3, 1.6, 6.2, 1.5, 1.8, 1.2, 0, 0}; //10014048 |
|
80 |
+ |
|
81 |
+/* precomputed table for 10^(i/4), i=-15..16 */ |
|
82 |
+static const float imc_exp_tab[32] = { |
|
83 |
+ 1.778280e-4, 3.162278e-4, 5.623413e-4, 1.000000e-3, |
|
84 |
+ 1.778280e-3, 3.162278e-3, 5.623413e-3, 1.000000e-2, |
|
85 |
+ 1.778280e-2, 3.162278e-2, 5.623413e-2, 1.000000e-1, |
|
86 |
+ 1.778280e-1, 3.162278e-1, 5.623413e-1, 1.000000e00, |
|
87 |
+ 1.778280e00, 3.162278e00, 5.623413e00, 1.000000e01, |
|
88 |
+ 1.778280e01, 3.162278e01, 5.623413e01, 1.000000e02, |
|
89 |
+ 1.778280e02, 3.162278e02, 5.623413e02, 1.000000e03, |
|
90 |
+ 1.778280e03, 3.162278e03, 5.623413e03, 1.000000e04 |
|
91 |
+}; |
|
92 |
+static const float *imc_exp_tab2 = imc_exp_tab + 8; |
|
93 |
+ |
|
94 |
+ |
|
95 |
+static const uint8_t imc_cb_select[4][32] = { |
|
96 |
+ { 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, |
|
97 |
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2 }, |
|
98 |
+ { 0, 2, 0, 3, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
99 |
+ 0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
|
100 |
+ { 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
|
101 |
+ 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2 }, |
|
102 |
+ { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
|
103 |
+ 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
|
104 |
+}; |
|
105 |
+ |
|
106 |
+static const uint8_t imc_huffman_sizes[4] = { |
|
107 |
+ 17, 17, 18, 18 |
|
108 |
+}; |
|
109 |
+ |
|
110 |
+static const uint8_t imc_huffman_lens[4][4][18] = { |
|
111 |
+ { |
|
112 |
+ { 16, 15, 13, 11, 8, 5, 3, 1, 2, 4, 6, 9, 10, 12, 14, 16, 7, 0 }, |
|
113 |
+ { 10, 8, 7, 6, 4, 4, 3, 2, 2, 3, 4, 6, 7, 9, 11, 11, 7, 0 }, |
|
114 |
+ { 15, 15, 14, 11, 8, 6, 4, 2, 1, 4, 5, 7, 9, 10, 12, 13, 4, 0 }, |
|
115 |
+ { 13, 11, 10, 8, 6, 4, 2, 2, 2, 3, 5, 7, 9, 12, 15, 15, 14, 0 }, |
|
116 |
+ }, |
|
117 |
+ { |
|
118 |
+ { 14, 12, 10, 8, 7, 4, 2, 2, 2, 3, 5, 7, 9, 11, 13, 14, 7, 0 }, |
|
119 |
+ { 14, 13, 11, 8, 6, 4, 3, 2, 2, 3, 5, 7, 9, 10, 12, 14, 3, 0 }, |
|
120 |
+ { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, |
|
121 |
+ { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, |
|
122 |
+ }, |
|
123 |
+ { |
|
124 |
+ { 16, 14, 12, 10, 8, 5, 3, 1, 2, 4, 7, 9, 11, 13, 15, 17, 6, 17 }, |
|
125 |
+ { 15, 13, 11, 8, 6, 4, 2, 2, 2, 3, 5, 7, 10, 12, 14, 16, 9, 16 }, |
|
126 |
+ { 14, 12, 11, 9, 8, 6, 3, 1, 2, 5, 7, 10, 13, 15, 16, 17, 4, 17 }, |
|
127 |
+ { 16, 14, 12, 9, 7, 5, 2, 2, 2, 3, 4, 6, 8, 11, 13, 15, 10, 16 }, |
|
128 |
+ }, |
|
129 |
+ { |
|
130 |
+ { 13, 11, 10, 8, 7, 5, 2, 2, 2, 4, 6, 9, 12, 14, 15, 16, 3, 16 }, |
|
131 |
+ { 11, 11, 10, 9, 8, 7, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 5 }, |
|
132 |
+ { 9, 9, 7, 6, 5, 4, 3, 3, 2, 3, 4, 5, 4, 5, 5, 6, 8, 6 }, |
|
133 |
+ { 13, 12, 10, 8, 5, 3, 3, 2, 2, 3, 4, 7, 9, 11, 14, 15, 6, 15 }, |
|
134 |
+ } |
|
135 |
+}; |
|
136 |
+ |
|
137 |
+static const uint16_t imc_huffman_bits[4][4][18] = { |
|
138 |
+ { |
|
139 |
+ { 0xCC32, 0x6618, 0x1987, 0x0660, 0x00CD, 0x0018, 0x0007, 0x0000, 0x0002, 0x000D, 0x0032, 0x0199, 0x0331, 0x0CC2, 0x330D, 0xCC33, 0x0067, 0x0000 }, |
|
140 |
+ { 0x02FE, 0x00BE, 0x005E, 0x002D, 0x000A, 0x0009, 0x0003, 0x0003, 0x0000, 0x0002, 0x0008, 0x002C, 0x005D, 0x017E, 0x05FE, 0x05FF, 0x005C, 0x0000 }, |
|
141 |
+ { 0x5169, 0x5168, 0x28B5, 0x0517, 0x00A3, 0x0029, 0x0008, 0x0003, 0x0000, 0x0009, 0x0015, 0x0050, 0x0144, 0x028A, 0x0A2C, 0x145B, 0x000B, 0x0000 }, |
|
142 |
+ { 0x1231, 0x048D, 0x0247, 0x0090, 0x0025, 0x0008, 0x0001, 0x0003, 0x0000, 0x0005, 0x0013, 0x0049, 0x0122, 0x0919, 0x48C3, 0x48C2, 0x2460, 0x0000 }, |
|
143 |
+ }, |
|
144 |
+ { |
|
145 |
+ { 0x2D1D, 0x0B46, 0x02D0, 0x00B5, 0x0059, 0x000A, 0x0003, 0x0001, 0x0000, 0x0004, 0x0017, 0x005B, 0x0169, 0x05A2, 0x168F, 0x2D1C, 0x0058, 0x0000 }, |
|
146 |
+ { 0x1800, 0x0C01, 0x0301, 0x0061, 0x0019, 0x0007, 0x0004, 0x0003, 0x0000, 0x0005, 0x000D, 0x0031, 0x00C1, 0x0181, 0x0601, 0x1801, 0x0002, 0x0000 }, |
|
147 |
+ { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, |
|
148 |
+ { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, |
|
149 |
+ }, |
|
150 |
+ { |
|
151 |
+ { 0x2993, 0x0A65, 0x0298, 0x00A7, 0x0028, 0x0004, 0x0000, 0x0001, 0x0001, 0x0003, 0x0015, 0x0052, 0x014D, 0x0533, 0x14C8, 0x5324, 0x000B, 0x5325 }, |
|
152 |
+ { 0x09B8, 0x026F, 0x009A, 0x0012, 0x0005, 0x0000, 0x0001, 0x0002, 0x0003, 0x0001, 0x0003, 0x0008, 0x004C, 0x0136, 0x04DD, 0x1373, 0x0027, 0x1372 }, |
|
153 |
+ { 0x0787, 0x01E0, 0x00F1, 0x003D, 0x001F, 0x0006, 0x0001, 0x0001, 0x0001, 0x0002, 0x000E, 0x0079, 0x03C2, 0x0F0D, 0x1E19, 0x3C30, 0x0000, 0x3C31 }, |
|
154 |
+ { 0x4B06, 0x12C0, 0x04B1, 0x0097, 0x0024, 0x0008, 0x0002, 0x0003, 0x0000, 0x0003, 0x0005, 0x0013, 0x004A, 0x0259, 0x0961, 0x2582, 0x012D, 0x4B07 }, |
|
155 |
+ }, |
|
156 |
+ { |
|
157 |
+ { 0x0A5A, 0x0297, 0x014A, 0x0053, 0x0028, 0x000B, 0x0003, 0x0000, 0x0002, 0x0004, 0x0015, 0x00A4, 0x052C, 0x14B7, 0x296C, 0x52DB, 0x0003, 0x52DA }, |
|
158 |
+ { 0x0193, 0x0192, 0x00C8, 0x0065, 0x0033, 0x0018, 0x0007, 0x0004, 0x0000, 0x0004, 0x0005, 0x0007, 0x0006, 0x0003, 0x0005, 0x0005, 0x000D, 0x0004 }, |
|
159 |
+ { 0x0012, 0x0013, 0x0005, 0x0003, 0x0000, 0x0003, 0x0005, 0x0004, 0x0003, 0x0003, 0x0005, 0x0005, 0x0004, 0x0004, 0x0003, 0x0005, 0x0008, 0x0004 }, |
|
160 |
+ { 0x0D66, 0x06B2, 0x01AD, 0x006A, 0x000C, 0x0005, 0x0004, 0x0000, 0x0003, 0x0002, 0x0007, 0x0034, 0x00D7, 0x0358, 0x1ACF, 0x359C, 0x001B, 0x359D }, |
|
161 |
+ } |
|
162 |
+}; |
|
163 |
+ |
... | ... |
@@ -194,6 +194,7 @@ const CodecTag codec_wav_tags[] = { |
194 | 194 |
{ CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' }, |
195 | 195 |
{ CODEC_ID_TRUESPEECH, 0x22 }, |
196 | 196 |
{ CODEC_ID_FLAC, 0xF1AC }, |
197 |
+ { CODEC_ID_IMC, 0x401 }, |
|
197 | 198 |
|
198 | 199 |
/* FIXME: All of the IDs below are not 16 bit and thus illegal. */ |
199 | 200 |
{ CODEC_ID_TTA, MKTAG('T', 'T', 'A', '1') }, |