vlc: Add header #include when the types are used
[libav.git] / libavcodec / imc.c
CommitLineData
84ed36da
KS
1/*
2 * IMC compatible decoder
3 * Copyright (c) 2002-2004 Maxim Poliakovski
4 * Copyright (c) 2006 Benjamin Larsson
5 * Copyright (c) 2006 Konstantin Shishkov
6 *
2912e87a 7 * This file is part of Libav.
84ed36da 8 *
2912e87a 9 * Libav is free software; you can redistribute it and/or
84ed36da
KS
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
2912e87a 14 * Libav is distributed in the hope that it will be useful,
84ed36da
KS
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
2912e87a 20 * License along with Libav; if not, write to the Free Software
84ed36da 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
84ed36da
KS
22 */
23
24/**
ba87f080
DB
25 * @file
26 * IMC - Intel Music Coder
84ed36da 27 * A mdct based codec using a 256 points large transform
f05b69a7 28 * divided into 32 bands with some mix of scale factors.
84ed36da 29 * Only mono is supported.
84ed36da
KS
30 */
31
32
33#include <math.h>
34#include <stddef.h>
35#include <stdio.h>
36
a903f8f0 37#include "libavutil/channel_layout.h"
5959bfac 38#include "libavutil/float_dsp.h"
218aefce 39#include "libavutil/internal.h"
f5b7bd2a 40
84ed36da 41#include "avcodec.h"
f5b7bd2a 42#include "bitstream.h"
c67b449b 43#include "bswapdsp.h"
1429224b 44#include "fft.h"
594d4d5d 45#include "internal.h"
4538729a 46#include "sinewin.h"
73fc82f3 47#include "vlc.h"
84ed36da
KS
48
49#include "imcdata.h"
50
0fe04628 51#define IMC_BLOCK_SIZE 64
84ed36da
KS
52#define IMC_FRAME_ID 0x21
53#define BANDS 32
54#define COEFFS 256
55
c45e2da6 56typedef struct IMCChannel {
84ed36da
KS
57 float old_floor[BANDS];
58 float flcoeffs1[BANDS];
59 float flcoeffs2[BANDS];
60 float flcoeffs3[BANDS];
61 float flcoeffs4[BANDS];
62 float flcoeffs5[BANDS];
63 float flcoeffs6[BANDS];
64 float CWdecoded[COEFFS];
65
84ed36da
KS
66 int bandWidthT[BANDS]; ///< codewords per band
67 int bitsBandT[BANDS]; ///< how many bits per codeword in band
68 int CWlengthT[COEFFS]; ///< how many bits in each codeword
69 int levlCoeffBuf[BANDS];
70 int bandFlagsBuf[BANDS]; ///< flags for each band
71 int sumLenArr[BANDS]; ///< bits for all coeffs in band
72 int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
73 int skipFlagBits[BANDS]; ///< bits used to code skip flags
41ed7ab4 74 int skipFlagCount[BANDS]; ///< skipped coefficients per band
84ed36da
KS
75 int skipFlags[COEFFS]; ///< skip coefficient decoding or not
76 int codewords[COEFFS]; ///< raw codewords read from bitstream
c45e2da6
KS
77
78 float last_fft_im[COEFFS];
79
80 int decoder_reset;
81} IMCChannel;
82
7f9f771e 83typedef struct IMCContext {
c6061443 84 IMCChannel chctx[2];
c45e2da6
KS
85
86 /** MDCT tables */
87 //@{
88 float mdct_sine_window[COEFFS];
89 float post_cos[COEFFS];
90 float post_sin[COEFFS];
91 float pre_coef1[COEFFS];
92 float pre_coef2[COEFFS];
93 //@}
94
84ed36da 95 float sqrt_tab[30];
f5b7bd2a 96 BitstreamContext bc;
84ed36da 97
c67b449b 98 BswapDSPContext bdsp;
5959bfac 99 AVFloatDSPContext fdsp;
84ed36da 100 FFTContext fft;
d073f122 101 DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS / 2];
66b84e4a 102 float *out_samples;
c6061443 103
4eb4bb3a
KS
104 int coef0_pos;
105
c6061443
KS
106 int8_t cyclTab[32], cyclTab2[32];
107 float weights1[31], weights2[31];
84ed36da
KS
108} IMCContext;
109
09fec2b9
RD
110static VLC huffman_vlc[4][4];
111
112#define VLC_TABLES_SIZE 9512
113
114static const int vlc_offsets[17] = {
115 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
d073f122
KS
116 4452, 5220, 5860, 6628, 7268, 7908, 8424, 8936, VLC_TABLES_SIZE
117};
09fec2b9
RD
118
119static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2];
84ed36da 120
cac4760b
KS
121static inline double freq2bark(double freq)
122{
123 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
124}
125
126static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
127{
128 double freqmin[32], freqmid[32], freqmax[32];
129 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
130 double nyquist_freq = sampling_rate * 0.5;
131 double freq, bark, prev_bark = 0, tf, tb;
132 int i, j;
133
134 for (i = 0; i < 32; i++) {
135 freq = (band_tab[i] + band_tab[i + 1] - 1) * scale;
136 bark = freq2bark(freq);
137
138 if (i > 0) {
139 tb = bark - prev_bark;
140 q->weights1[i - 1] = pow(10.0, -1.0 * tb);
141 q->weights2[i - 1] = pow(10.0, -2.7 * tb);
142 }
143 prev_bark = bark;
144
145 freqmid[i] = freq;
146
147 tf = freq;
148 while (tf < nyquist_freq) {
149 tf += 0.5;
150 tb = freq2bark(tf);
151 if (tb > bark + 0.5)
152 break;
153 }
154 freqmax[i] = tf;
155
156 tf = freq;
157 while (tf > 0.0) {
158 tf -= 0.5;
159 tb = freq2bark(tf);
160 if (tb <= bark - 0.5)
161 break;
162 }
163 freqmin[i] = tf;
164 }
165
166 for (i = 0; i < 32; i++) {
167 freq = freqmax[i];
168 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
169 q->cyclTab[i] = j + 1;
170
171 freq = freqmin[i];
172 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
173 q->cyclTab2[i] = j - 1;
174 }
175}
176
d073f122 177static av_cold int imc_decode_init(AVCodecContext *avctx)
84ed36da 178{
95fee70d 179 int i, j, ret;
84ed36da
KS
180 IMCContext *q = avctx->priv_data;
181 double r1, r2;
182
1c7a0161
JR
183 if (avctx->codec_id == AV_CODEC_ID_IMC)
184 avctx->channels = 1;
185
186 if (avctx->channels > 2) {
6d97484d 187 avpriv_request_sample(avctx, "Number of channels > 2");
7b7f47e7
JR
188 return AVERROR_PATCHWELCOME;
189 }
190
c45e2da6
KS
191 for (j = 0; j < avctx->channels; j++) {
192 q->chctx[j].decoder_reset = 1;
84ed36da 193
c45e2da6
KS
194 for (i = 0; i < BANDS; i++)
195 q->chctx[j].old_floor[i] = 1.0;
196
197 for (i = 0; i < COEFFS / 2; i++)
198 q->chctx[j].last_fft_im[i] = 0;
199 }
84ed36da
KS
200
201 /* Build mdct window, a simple sine window normalized with sqrt(2) */
9146e4d6 202 ff_sine_window_init(q->mdct_sine_window, COEFFS);
d073f122 203 for (i = 0; i < COEFFS; i++)
9146e4d6 204 q->mdct_sine_window[i] *= sqrt(2.0);
d073f122 205 for (i = 0; i < COEFFS / 2; i++) {
66b84e4a
VS
206 q->post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);
207 q->post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);
84ed36da
KS
208
209 r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
210 r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
211
d073f122 212 if (i & 0x1) {
84ed36da
KS
213 q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);
214 q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
d073f122 215 } else {
84ed36da
KS
216 q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
217 q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
218 }
84ed36da 219 }
84ed36da
KS
220
221 /* Generate a square root table */
222
d073f122 223 for (i = 0; i < 30; i++)
84ed36da 224 q->sqrt_tab[i] = sqrt(i);
84ed36da
KS
225
226 /* initialize the VLC tables */
d073f122
KS
227 for (i = 0; i < 4 ; i++) {
228 for (j = 0; j < 4; j++) {
b836fb00 229 huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]];
09fec2b9
RD
230 huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
231 init_vlc(&huffman_vlc[i][j], 9, imc_huffman_sizes[i],
84ed36da 232 imc_huffman_lens[i][j], 1, 1,
09fec2b9 233 imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);
84ed36da
KS
234 }
235 }
84ed36da 236
36ef5369 237 if (avctx->codec_id == AV_CODEC_ID_IAC) {
cac4760b 238 iac_generate_tabs(q, avctx->sample_rate);
c6061443 239 } else {
cac4760b
KS
240 memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
241 memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
c6061443
KS
242 memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
243 memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
244 }
245
95fee70d
JR
246 if ((ret = ff_fft_init(&q->fft, 7, 1))) {
247 av_log(avctx, AV_LOG_INFO, "FFT init failed\n");
248 return ret;
249 }
c67b449b 250 ff_bswapdsp_init(&q->bdsp);
7c6eb0a1 251 avpriv_float_dsp_init(&q->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
3fca0d72 252 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
c45e2da6
KS
253 avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
254 : AV_CH_LAYOUT_STEREO;
0eea2129 255
84ed36da
KS
256 return 0;
257}
258
d073f122
KS
259static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
260 float *flcoeffs2, int *bandWidthT,
261 float *flcoeffs3, float *flcoeffs5)
84ed36da
KS
262{
263 float workT1[BANDS];
264 float workT2[BANDS];
265 float workT3[BANDS];
266 float snr_limit = 1.e-30;
267 float accum = 0.0;
268 int i, cnt2;
269
d073f122 270 for (i = 0; i < BANDS; i++) {
84ed36da 271 flcoeffs5[i] = workT2[i] = 0.0;
d073f122 272 if (bandWidthT[i]) {
84ed36da
KS
273 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
274 flcoeffs3[i] = 2.0 * flcoeffs2[i];
275 } else {
d073f122 276 workT1[i] = 0.0;
84ed36da
KS
277 flcoeffs3[i] = -30000.0;
278 }
279 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
280 if (workT3[i] <= snr_limit)
281 workT3[i] = 0.0;
282 }
283
d073f122 284 for (i = 0; i < BANDS; i++) {
c6061443 285 for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
84ed36da 286 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
d073f122 287 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
84ed36da
KS
288 }
289
d073f122 290 for (i = 1; i < BANDS; i++) {
c6061443 291 accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
84ed36da
KS
292 flcoeffs5[i] += accum;
293 }
294
d073f122 295 for (i = 0; i < BANDS; i++)
84ed36da
KS
296 workT2[i] = 0.0;
297
d073f122 298 for (i = 0; i < BANDS; i++) {
c6061443 299 for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
84ed36da
KS
300 flcoeffs5[cnt2] += workT3[i];
301 workT2[cnt2+1] += workT3[i];
302 }
303
304 accum = 0.0;
305
d073f122 306 for (i = BANDS-2; i >= 0; i--) {
c6061443 307 accum = (workT2[i+1] + accum) * q->weights2[i];
84ed36da 308 flcoeffs5[i] += accum;
d073f122 309 // there is missing code here, but it seems to never be triggered
84ed36da
KS
310 }
311}
312
313
d073f122
KS
314static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
315 int *levlCoeffs)
84ed36da
KS
316{
317 int i;
318 VLC *hufftab[4];
319 int start = 0;
320 const uint8_t *cb_sel;
321 int s;
322
323 s = stream_format_code >> 1;
09fec2b9
RD
324 hufftab[0] = &huffman_vlc[s][0];
325 hufftab[1] = &huffman_vlc[s][1];
326 hufftab[2] = &huffman_vlc[s][2];
327 hufftab[3] = &huffman_vlc[s][3];
84ed36da
KS
328 cb_sel = imc_cb_select[s];
329
d073f122 330 if (stream_format_code & 4)
84ed36da 331 start = 1;
d073f122 332 if (start)
f5b7bd2a 333 levlCoeffs[0] = bitstream_read(&q->bc, 7);
d073f122 334 for (i = start; i < BANDS; i++) {
f5b7bd2a
AH
335 levlCoeffs[i] = bitstream_read_vlc(&q->bc, hufftab[cb_sel[i]]->table,
336 hufftab[cb_sel[i]]->bits, 2);
d073f122 337 if (levlCoeffs[i] == 17)
f5b7bd2a 338 levlCoeffs[i] += bitstream_read(&q->bc, 4);
84ed36da
KS
339 }
340}
341
4eb4bb3a
KS
342static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
343 int *levlCoeffs)
344{
345 int i;
346
f5b7bd2a
AH
347 q->coef0_pos = bitstream_read(&q->bc, 5);
348 levlCoeffs[0] = bitstream_read(&q->bc, 7);
4eb4bb3a 349 for (i = 1; i < BANDS; i++)
f5b7bd2a 350 levlCoeffs[i] = bitstream_read(&q->bc, 4);
4eb4bb3a
KS
351}
352
d073f122
KS
353static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
354 float *flcoeffs1, float *flcoeffs2)
84ed36da
KS
355{
356 int i, level;
357 float tmp, tmp2;
d073f122 358 // maybe some frequency division thingy
84ed36da 359
521fe1d2 360 flcoeffs1[0] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
d752509b 361 flcoeffs2[0] = log2f(flcoeffs1[0]);
d073f122 362 tmp = flcoeffs1[0];
84ed36da
KS
363 tmp2 = flcoeffs2[0];
364
d073f122 365 for (i = 1; i < BANDS; i++) {
84ed36da
KS
366 level = levlCoeffBuf[i];
367 if (level == 16) {
368 flcoeffs1[i] = 1.0;
369 flcoeffs2[i] = 0.0;
370 } else {
371 if (level < 17)
d073f122 372 level -= 7;
84ed36da 373 else if (level <= 24)
d073f122 374 level -= 32;
84ed36da 375 else
d073f122 376 level -= 16;
84ed36da
KS
377
378 tmp *= imc_exp_tab[15 + level];
521fe1d2 379 tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
84ed36da
KS
380 flcoeffs1[i] = tmp;
381 flcoeffs2[i] = tmp2;
382 }
383 }
384}
385
386
d073f122
KS
387static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
388 float *old_floor, float *flcoeffs1,
389 float *flcoeffs2)
390{
84ed36da 391 int i;
d073f122
KS
392 /* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
393 * and flcoeffs2 old scale factors
394 * might be incomplete due to a missing table that is in the binary code
395 */
396 for (i = 0; i < BANDS; i++) {
84ed36da 397 flcoeffs1[i] = 0;
d073f122 398 if (levlCoeffBuf[i] < 16) {
84ed36da 399 flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
d073f122 400 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
84ed36da
KS
401 } else {
402 flcoeffs1[i] = old_floor[i];
403 }
404 }
405}
406
4eb4bb3a
KS
407static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
408 float *flcoeffs1, float *flcoeffs2)
409{
410 int i, level, pos;
411 float tmp, tmp2;
412
413 pos = q->coef0_pos;
414 flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
1410eeb6 415 flcoeffs2[pos] = log2f(flcoeffs1[pos]);
4eb4bb3a
KS
416 tmp = flcoeffs1[pos];
417 tmp2 = flcoeffs2[pos];
418
419 levlCoeffBuf++;
420 for (i = 0; i < BANDS; i++) {
421 if (i == pos)
422 continue;
423 level = *levlCoeffBuf++;
424 flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
425 flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
426 }
427}
428
84ed36da
KS
429/**
430 * Perform bit allocation depending on bits available
431 */
c45e2da6
KS
432static int bit_allocation(IMCContext *q, IMCChannel *chctx,
433 int stream_format_code, int freebits, int flag)
d073f122 434{
84ed36da
KS
435 int i, j;
436 const float limit = -1.e20;
437 float highest = 0.0;
438 int indx;
439 int t1 = 0;
440 int t2 = 1;
441 float summa = 0.0;
442 int iacc = 0;
443 int summer = 0;
444 int rres, cwlen;
445 float lowest = 1.e10;
446 int low_indx = 0;
447 float workT[32];
448 int flg;
449 int found_indx = 0;
450
d073f122 451 for (i = 0; i < BANDS; i++)
c45e2da6 452 highest = FFMAX(highest, chctx->flcoeffs1[i]);
84ed36da 453
d073f122 454 for (i = 0; i < BANDS - 1; i++)
d752509b 455 chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
c45e2da6 456 chctx->flcoeffs4[BANDS - 1] = limit;
84ed36da
KS
457
458 highest = highest * 0.25;
459
d073f122 460 for (i = 0; i < BANDS; i++) {
84ed36da 461 indx = -1;
c45e2da6 462 if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
84ed36da
KS
463 indx = 0;
464
c45e2da6 465 if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
84ed36da
KS
466 indx = 1;
467
c45e2da6 468 if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
84ed36da
KS
469 indx = 2;
470
471 if (indx == -1)
08e5cd38 472 return AVERROR_INVALIDDATA;
84ed36da 473
c45e2da6 474 chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
84ed36da
KS
475 }
476
477 if (stream_format_code & 0x2) {
c45e2da6
KS
478 chctx->flcoeffs4[0] = limit;
479 chctx->flcoeffs4[1] = limit;
480 chctx->flcoeffs4[2] = limit;
481 chctx->flcoeffs4[3] = limit;
84ed36da
KS
482 }
483
d073f122 484 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
c45e2da6
KS
485 iacc += chctx->bandWidthT[i];
486 summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
84ed36da 487 }
bbf6a4aa
LB
488
489 if (!iacc)
490 return AVERROR_INVALIDDATA;
491
c45e2da6 492 chctx->bandWidthT[BANDS - 1] = 0;
84ed36da
KS
493 summa = (summa * 0.5 - freebits) / iacc;
494
495
d073f122 496 for (i = 0; i < BANDS / 2; i++) {
84ed36da 497 rres = summer - freebits;
d073f122
KS
498 if ((rres >= -8) && (rres <= 8))
499 break;
84ed36da
KS
500
501 summer = 0;
d073f122 502 iacc = 0;
84ed36da 503
d073f122 504 for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
c45e2da6 505 cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
84ed36da 506
c45e2da6
KS
507 chctx->bitsBandT[j] = cwlen;
508 summer += chctx->bandWidthT[j] * cwlen;
84ed36da
KS
509
510 if (cwlen > 0)
c45e2da6 511 iacc += chctx->bandWidthT[j];
84ed36da
KS
512 }
513
514 flg = t2;
515 t2 = 1;
516 if (freebits < summer)
517 t2 = -1;
518 if (i == 0)
519 flg = t2;
d073f122 520 if (flg != t2)
84ed36da
KS
521 t1++;
522
523 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
524 }
525
d073f122
KS
526 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
527 for (j = band_tab[i]; j < band_tab[i + 1]; j++)
c45e2da6 528 chctx->CWlengthT[j] = chctx->bitsBandT[i];
84ed36da
KS
529 }
530
531 if (freebits > summer) {
d073f122 532 for (i = 0; i < BANDS; i++) {
c45e2da6
KS
533 workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
534 : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
84ed36da
KS
535 }
536
537 highest = 0.0;
538
d073f122 539 do {
84ed36da
KS
540 if (highest <= -1.e20)
541 break;
542
543 found_indx = 0;
544 highest = -1.e20;
545
d073f122 546 for (i = 0; i < BANDS; i++) {
84ed36da
KS
547 if (workT[i] > highest) {
548 highest = workT[i];
549 found_indx = i;
550 }
551 }
552
553 if (highest > -1.e20) {
554 workT[found_indx] -= 2.0;
c45e2da6 555 if (++chctx->bitsBandT[found_indx] == 6)
84ed36da
KS
556 workT[found_indx] = -1.e20;
557
d073f122 558 for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
c45e2da6 559 chctx->CWlengthT[j]++;
84ed36da
KS
560 summer++;
561 }
562 }
d073f122 563 } while (freebits > summer);
84ed36da
KS
564 }
565 if (freebits < summer) {
d073f122 566 for (i = 0; i < BANDS; i++) {
c45e2da6 567 workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
d073f122 568 : 1.e20;
84ed36da
KS
569 }
570 if (stream_format_code & 0x2) {
571 workT[0] = 1.e20;
572 workT[1] = 1.e20;
573 workT[2] = 1.e20;
574 workT[3] = 1.e20;
575 }
d073f122
KS
576 while (freebits < summer) {
577 lowest = 1.e10;
84ed36da 578 low_indx = 0;
d073f122 579 for (i = 0; i < BANDS; i++) {
84ed36da 580 if (workT[i] < lowest) {
d073f122 581 lowest = workT[i];
84ed36da
KS
582 low_indx = i;
583 }
584 }
d073f122
KS
585 // if (lowest >= 1.e10)
586 // break;
84ed36da
KS
587 workT[low_indx] = lowest + 2.0;
588
c45e2da6 589 if (!--chctx->bitsBandT[low_indx])
84ed36da
KS
590 workT[low_indx] = 1.e20;
591
d073f122 592 for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
c45e2da6
KS
593 if (chctx->CWlengthT[j] > 0) {
594 chctx->CWlengthT[j]--;
84ed36da
KS
595 summer--;
596 }
597 }
598 }
599 }
600 return 0;
601}
602
c45e2da6 603static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
d073f122 604{
84ed36da
KS
605 int i, j;
606
c45e2da6
KS
607 memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
608 memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
d073f122 609 for (i = 0; i < BANDS; i++) {
c45e2da6 610 if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
84ed36da
KS
611 continue;
612
c45e2da6
KS
613 if (!chctx->skipFlagRaw[i]) {
614 chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
84ed36da 615
d073f122 616 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
f5b7bd2a 617 chctx->skipFlags[j] = bitstream_read_bit(&q->bc);
c45e2da6
KS
618 if (chctx->skipFlags[j])
619 chctx->skipFlagCount[i]++;
84ed36da
KS
620 }
621 } else {
d073f122 622 for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
f5b7bd2a 623 if (!bitstream_read_bit(&q->bc)) { // 0
c45e2da6
KS
624 chctx->skipFlagBits[i]++;
625 chctx->skipFlags[j] = 1;
626 chctx->skipFlags[j + 1] = 1;
627 chctx->skipFlagCount[i] += 2;
d073f122 628 } else {
f5b7bd2a 629 if (bitstream_read_bit(&q->bc)) { // 11
c45e2da6
KS
630 chctx->skipFlagBits[i] += 2;
631 chctx->skipFlags[j] = 0;
632 chctx->skipFlags[j + 1] = 1;
633 chctx->skipFlagCount[i]++;
d073f122 634 } else {
c45e2da6
KS
635 chctx->skipFlagBits[i] += 3;
636 chctx->skipFlags[j + 1] = 0;
f5b7bd2a 637 if (!bitstream_read_bit(&q->bc)) { // 100
c45e2da6
KS
638 chctx->skipFlags[j] = 1;
639 chctx->skipFlagCount[i]++;
d073f122 640 } else { // 101
c45e2da6 641 chctx->skipFlags[j] = 0;
84ed36da
KS
642 }
643 }
644 }
645 }
646
d073f122 647 if (j < band_tab[i + 1]) {
c45e2da6 648 chctx->skipFlagBits[i]++;
f5b7bd2a 649 if ((chctx->skipFlags[j] = bitstream_read_bit(&q->bc)))
c45e2da6 650 chctx->skipFlagCount[i]++;
84ed36da
KS
651 }
652 }
653 }
654}
655
656/**
657 * Increase highest' band coefficient sizes as some bits won't be used
658 */
c45e2da6
KS
659static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx,
660 int summer)
d073f122 661{
84ed36da
KS
662 float workT[32];
663 int corrected = 0;
664 int i, j;
d073f122
KS
665 float highest = 0;
666 int found_indx = 0;
84ed36da 667
d073f122 668 for (i = 0; i < BANDS; i++) {
c45e2da6
KS
669 workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
670 : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
84ed36da
KS
671 }
672
673 while (corrected < summer) {
d073f122 674 if (highest <= -1.e20)
84ed36da
KS
675 break;
676
677 highest = -1.e20;
678
d073f122 679 for (i = 0; i < BANDS; i++) {
84ed36da
KS
680 if (workT[i] > highest) {
681 highest = workT[i];
682 found_indx = i;
683 }
684 }
685
686 if (highest > -1.e20) {
687 workT[found_indx] -= 2.0;
c45e2da6 688 if (++(chctx->bitsBandT[found_indx]) == 6)
84ed36da
KS
689 workT[found_indx] = -1.e20;
690
d073f122 691 for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
c45e2da6
KS
692 if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
693 chctx->CWlengthT[j]++;
84ed36da
KS
694 corrected++;
695 }
696 }
697 }
698 }
699}
700
34271cab 701static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
d073f122 702{
84ed36da
KS
703 int i;
704 float re, im;
34271cab 705 float *dst1 = q->out_samples;
3fca0d72 706 float *dst2 = q->out_samples + (COEFFS - 1);
84ed36da
KS
707
708 /* prerotation */
d073f122 709 for (i = 0; i < COEFFS / 2; i++) {
c45e2da6
KS
710 q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
711 (q->pre_coef2[i] * chctx->CWdecoded[i * 2]);
712 q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
713 (q->pre_coef1[i] * chctx->CWdecoded[i * 2]);
84ed36da
KS
714 }
715
716 /* FFT */
26f548bb 717 q->fft.fft_permute(&q->fft, q->samples);
d073f122 718 q->fft.fft_calc(&q->fft, q->samples);
84ed36da
KS
719
720 /* postrotation, window and reorder */
d073f122
KS
721 for (i = 0; i < COEFFS / 2; i++) {
722 re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
723 im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]);
34271cab
KS
724 *dst1 = (q->mdct_sine_window[COEFFS - 1 - i * 2] * chctx->last_fft_im[i])
725 + (q->mdct_sine_window[i * 2] * re);
726 *dst2 = (q->mdct_sine_window[i * 2] * chctx->last_fft_im[i])
727 - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re);
3fca0d72
JR
728 dst1 += 2;
729 dst2 -= 2;
c45e2da6 730 chctx->last_fft_im[i] = im;
84ed36da
KS
731 }
732}
733
c45e2da6
KS
734static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx,
735 int stream_format_code)
d073f122 736{
84ed36da
KS
737 int i, j;
738 int middle_value, cw_len, max_size;
d073f122 739 const float *quantizer;
84ed36da 740
d073f122
KS
741 for (i = 0; i < BANDS; i++) {
742 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
c45e2da6
KS
743 chctx->CWdecoded[j] = 0;
744 cw_len = chctx->CWlengthT[j];
84ed36da 745
c45e2da6 746 if (cw_len <= 0 || chctx->skipFlags[j])
84ed36da
KS
747 continue;
748
d073f122 749 max_size = 1 << cw_len;
84ed36da
KS
750 middle_value = max_size >> 1;
751
c45e2da6 752 if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
08e5cd38 753 return AVERROR_INVALIDDATA;
84ed36da 754
d073f122 755 if (cw_len >= 4) {
84ed36da 756 quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
c45e2da6
KS
757 if (chctx->codewords[j] >= middle_value)
758 chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
84ed36da 759 else
c45e2da6 760 chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
84ed36da 761 }else{
c45e2da6
KS
762 quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
763 if (chctx->codewords[j] >= middle_value)
764 chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
84ed36da 765 else
c45e2da6 766 chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
84ed36da
KS
767 }
768 }
769 }
770 return 0;
771}
772
773
c45e2da6 774static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx)
d073f122 775{
84ed36da
KS
776 int i, j, cw_len, cw;
777
d073f122 778 for (i = 0; i < BANDS; i++) {
c45e2da6 779 if (!chctx->sumLenArr[i])
d073f122 780 continue;
c45e2da6 781 if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
d073f122 782 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
c45e2da6 783 cw_len = chctx->CWlengthT[j];
84ed36da
KS
784 cw = 0;
785
f5b7bd2a 786 if (bitstream_tell(&q->bc) + cw_len > 512) {
6a85dfc8 787 ff_dlog(NULL, "Band %i coeff %i cw_len %i\n", i, j, cw_len);
08e5cd38 788 return AVERROR_INVALIDDATA;
84ed36da
KS
789 }
790
c45e2da6 791 if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j]))
f5b7bd2a 792 cw = bitstream_read(&q->bc, cw_len);
84ed36da 793
c45e2da6 794 chctx->codewords[j] = cw;
84ed36da
KS
795 }
796 }
797 }
798 return 0;
799}
800
4eb4bb3a
KS
801static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
802{
803 int i, j;
804 int bits, summer;
805
806 for (i = 0; i < BANDS; i++) {
807 chctx->sumLenArr[i] = 0;
808 chctx->skipFlagRaw[i] = 0;
809 for (j = band_tab[i]; j < band_tab[i + 1]; j++)
810 chctx->sumLenArr[i] += chctx->CWlengthT[j];
811 if (chctx->bandFlagsBuf[i])
812 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
813 chctx->skipFlagRaw[i] = 1;
814 }
815
816 imc_get_skip_coeff(q, chctx);
817
818 for (i = 0; i < BANDS; i++) {
819 chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
820 /* band has flag set and at least one coded coefficient */
821 if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
822 chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
823 q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
824 }
825 }
826
827 /* calculate bits left, bits needed and adjust bit allocation */
828 bits = summer = 0;
829
830 for (i = 0; i < BANDS; i++) {
831 if (chctx->bandFlagsBuf[i]) {
832 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
833 if (chctx->skipFlags[j]) {
834 summer += chctx->CWlengthT[j];
835 chctx->CWlengthT[j] = 0;
836 }
837 }
838 bits += chctx->skipFlagBits[i];
839 summer -= chctx->skipFlagBits[i];
840 }
841 }
842 imc_adjust_bit_allocation(q, chctx, summer);
843}
844
c45e2da6 845static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
84ed36da 846{
84ed36da 847 int stream_format_code;
0eea2129 848 int imc_hdr, i, j, ret;
84ed36da 849 int flag;
4eb4bb3a 850 int bits;
84ed36da 851 int counter, bitscount;
c45e2da6 852 IMCChannel *chctx = q->chctx + ch;
84ed36da 853
84ed36da
KS
854
855 /* Check the frame header */
f5b7bd2a 856 imc_hdr = bitstream_read(&q->bc, 9);
c6061443
KS
857 if (imc_hdr & 0x18) {
858 av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
859 av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
08e5cd38 860 return AVERROR_INVALIDDATA;
84ed36da 861 }
f5b7bd2a 862 stream_format_code = bitstream_read(&q->bc, 3);
84ed36da 863
84ed36da 864 if (stream_format_code & 0x04)
c45e2da6 865 chctx->decoder_reset = 1;
84ed36da 866
c45e2da6 867 if (chctx->decoder_reset) {
d073f122 868 for (i = 0; i < BANDS; i++)
c45e2da6 869 chctx->old_floor[i] = 1.0;
d073f122 870 for (i = 0; i < COEFFS; i++)
c45e2da6
KS
871 chctx->CWdecoded[i] = 0;
872 chctx->decoder_reset = 0;
84ed36da
KS
873 }
874
f5b7bd2a 875 flag = bitstream_read_bit(&q->bc);
4eb4bb3a 876 if (stream_format_code & 0x1)
4eb4bb3a
KS
877 imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
878 else
879 imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
84ed36da 880
1ac5a29b
VG
881 if (stream_format_code & 0x1)
882 imc_decode_level_coefficients_raw(q, chctx->levlCoeffBuf,
883 chctx->flcoeffs1, chctx->flcoeffs2);
884 else if (stream_format_code & 0x4)
c45e2da6
KS
885 imc_decode_level_coefficients(q, chctx->levlCoeffBuf,
886 chctx->flcoeffs1, chctx->flcoeffs2);
84ed36da 887 else
c45e2da6
KS
888 imc_decode_level_coefficients2(q, chctx->levlCoeffBuf, chctx->old_floor,
889 chctx->flcoeffs1, chctx->flcoeffs2);
84ed36da 890
c45e2da6 891 memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
84ed36da
KS
892
893 counter = 0;
4eb4bb3a
KS
894 if (stream_format_code & 0x1) {
895 for (i = 0; i < BANDS; i++) {
896 chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
897 chctx->bandFlagsBuf[i] = 0;
898 chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
899 chctx->flcoeffs5[i] = 1.0;
900 }
901 } else {
902 for (i = 0; i < BANDS; i++) {
903 if (chctx->levlCoeffBuf[i] == 16) {
904 chctx->bandWidthT[i] = 0;
905 counter++;
906 } else
907 chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
908 }
909
910 memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
911 for (i = 0; i < BANDS - 1; i++)
912 if (chctx->bandWidthT[i])
f5b7bd2a 913 chctx->bandFlagsBuf[i] = bitstream_read_bit(&q->bc);
84ed36da 914
4eb4bb3a
KS
915 imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
916 chctx->bandWidthT, chctx->flcoeffs3,
917 chctx->flcoeffs5);
918 }
84ed36da
KS
919
920 bitscount = 0;
921 /* first 4 bands will be assigned 5 bits per coefficient */
922 if (stream_format_code & 0x2) {
923 bitscount += 15;
924
c45e2da6
KS
925 chctx->bitsBandT[0] = 5;
926 chctx->CWlengthT[0] = 5;
927 chctx->CWlengthT[1] = 5;
928 chctx->CWlengthT[2] = 5;
d073f122 929 for (i = 1; i < 4; i++) {
4eb4bb3a
KS
930 if (stream_format_code & 0x1)
931 bits = 5;
932 else
933 bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
c45e2da6 934 chctx->bitsBandT[i] = bits;
d073f122 935 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
c45e2da6 936 chctx->CWlengthT[j] = bits;
d073f122 937 bitscount += bits;
84ed36da
KS
938 }
939 }
940 }
36ef5369 941 if (avctx->codec_id == AV_CODEC_ID_IAC) {
c6061443
KS
942 bitscount += !!chctx->bandWidthT[BANDS - 1];
943 if (!(stream_format_code & 0x2))
944 bitscount += 16;
945 }
84ed36da 946
c45e2da6 947 if ((ret = bit_allocation(q, chctx, stream_format_code,
f5b7bd2a 948 512 - bitscount - bitstream_tell(&q->bc),
d073f122 949 flag)) < 0) {
84ed36da 950 av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
c45e2da6 951 chctx->decoder_reset = 1;
08e5cd38 952 return ret;
84ed36da
KS
953 }
954
4eb4bb3a
KS
955 if (stream_format_code & 0x1) {
956 for (i = 0; i < BANDS; i++)
957 chctx->skipFlags[i] = 0;
958 } else {
959 imc_refine_bit_allocation(q, chctx);
84ed36da 960 }
84ed36da 961
d073f122 962 for (i = 0; i < BANDS; i++) {
c45e2da6 963 chctx->sumLenArr[i] = 0;
84ed36da 964
d073f122 965 for (j = band_tab[i]; j < band_tab[i + 1]; j++)
c45e2da6
KS
966 if (!chctx->skipFlags[j])
967 chctx->sumLenArr[i] += chctx->CWlengthT[j];
84ed36da
KS
968 }
969
c45e2da6 970 memset(chctx->codewords, 0, sizeof(chctx->codewords));
84ed36da 971
c45e2da6 972 if (imc_get_coeffs(q, chctx) < 0) {
84ed36da 973 av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
c45e2da6 974 chctx->decoder_reset = 1;
a4998e44 975 return AVERROR_INVALIDDATA;
84ed36da
KS
976 }
977
c45e2da6 978 if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
84ed36da 979 av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
c45e2da6
KS
980 chctx->decoder_reset = 1;
981 return AVERROR_INVALIDDATA;
982 }
983
984 memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
985
34271cab 986 imc_imdct256(q, chctx, avctx->channels);
c45e2da6
KS
987
988 return 0;
989}
990
991static int imc_decode_frame(AVCodecContext *avctx, void *data,
992 int *got_frame_ptr, AVPacket *avpkt)
993{
9b28e583 994 AVFrame *frame = data;
c45e2da6
KS
995 const uint8_t *buf = avpkt->data;
996 int buf_size = avpkt->size;
997 int ret, i;
998
999 IMCContext *q = avctx->priv_data;
1000
059a9348 1001 LOCAL_ALIGNED_16(uint16_t, buf16, [(IMC_BLOCK_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / 2]);
c45e2da6 1002
c6061443
KS
1003 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
1004 av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
a4998e44 1005 return AVERROR_INVALIDDATA;
84ed36da
KS
1006 }
1007
c45e2da6 1008 /* get output buffer */
9b28e583 1009 frame->nb_samples = COEFFS;
759001c5 1010 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
c45e2da6
KS
1011 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1012 return ret;
1013 }
84ed36da 1014
c45e2da6 1015 for (i = 0; i < avctx->channels; i++) {
9b28e583 1016 q->out_samples = (float *)frame->extended_data[i];
c45e2da6 1017
c67b449b 1018 q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
c45e2da6 1019
a25dac97 1020 bitstream_init8(&q->bc, (const uint8_t *)buf16, IMC_BLOCK_SIZE);
c45e2da6
KS
1021
1022 buf += IMC_BLOCK_SIZE;
1023
1024 if ((ret = imc_decode_block(avctx, q, i)) < 0)
1025 return ret;
1026 }
84ed36da 1027
c6061443 1028 if (avctx->channels == 2) {
9b28e583
JR
1029 q->fdsp.butterflies_float((float *)frame->extended_data[0],
1030 (float *)frame->extended_data[1], COEFFS);
c6061443
KS
1031 }
1032
9b28e583 1033 *got_frame_ptr = 1;
84ed36da 1034
c45e2da6 1035 return IMC_BLOCK_SIZE * avctx->channels;
84ed36da
KS
1036}
1037
1038
98a6fff9 1039static av_cold int imc_decode_close(AVCodecContext * avctx)
84ed36da
KS
1040{
1041 IMCContext *q = avctx->priv_data;
1042
1043 ff_fft_end(&q->fft);
0eea2129 1044
84ed36da
KS
1045 return 0;
1046}
1047
1048
d36beb3f 1049AVCodec ff_imc_decoder = {
00c3b67b 1050 .name = "imc",
b2bed932 1051 .long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"),
00c3b67b 1052 .type = AVMEDIA_TYPE_AUDIO,
36ef5369 1053 .id = AV_CODEC_ID_IMC,
84ed36da 1054 .priv_data_size = sizeof(IMCContext),
00c3b67b
MS
1055 .init = imc_decode_init,
1056 .close = imc_decode_close,
1057 .decode = imc_decode_frame,
def97856 1058 .capabilities = AV_CODEC_CAP_DR1,
3fca0d72
JR
1059 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1060 AV_SAMPLE_FMT_NONE },
84ed36da 1061};
c6061443
KS
1062
1063AVCodec ff_iac_decoder = {
1064 .name = "iac",
b2bed932 1065 .long_name = NULL_IF_CONFIG_SMALL("IAC (Indeo Audio Coder)"),
c6061443 1066 .type = AVMEDIA_TYPE_AUDIO,
36ef5369 1067 .id = AV_CODEC_ID_IAC,
c6061443
KS
1068 .priv_data_size = sizeof(IMCContext),
1069 .init = imc_decode_init,
1070 .close = imc_decode_close,
1071 .decode = imc_decode_frame,
def97856 1072 .capabilities = AV_CODEC_CAP_DR1,
3fca0d72
JR
1073 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1074 AV_SAMPLE_FMT_NONE },
c6061443 1075};