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