FFmpeg
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 FFmpeg.
8  *
9  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 /**
25  * @file
26  * IMC - Intel Music Coder
27  * A mdct based codec using a 256 points large transform
28  * divided into 32 bands with some mix of scale factors.
29  * Only mono is supported.
30  */
31 
32 #include "config_components.h"
33 
34 #include <math.h>
35 #include <stddef.h>
36 
38 #include "libavutil/ffmath.h"
39 #include "libavutil/float_dsp.h"
40 #include "libavutil/internal.h"
41 #include "libavutil/mem_internal.h"
42 #include "libavutil/thread.h"
43 #include "libavutil/tx.h"
44 
45 #include "avcodec.h"
46 #include "bswapdsp.h"
47 #include "codec_internal.h"
48 #include "decode.h"
49 #include "get_bits.h"
50 #include "sinewin.h"
51 
52 #include "imcdata.h"
53 
54 #define IMC_BLOCK_SIZE 64
55 #define IMC_FRAME_ID 0x21
56 #define BANDS 32
57 #define COEFFS 256
58 
59 typedef struct IMCChannel {
60  float old_floor[BANDS];
61  float flcoeffs1[BANDS];
62  float flcoeffs2[BANDS];
63  float flcoeffs3[BANDS];
64  float flcoeffs4[BANDS];
65  float flcoeffs5[BANDS];
66  float flcoeffs6[BANDS];
68 
69  int bandWidthT[BANDS]; ///< codewords per band
70  int bitsBandT[BANDS]; ///< how many bits per codeword in band
71  int CWlengthT[COEFFS]; ///< how many bits in each codeword
73  int bandFlagsBuf[BANDS]; ///< flags for each band
74  int sumLenArr[BANDS]; ///< bits for all coeffs in band
75  int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
76  int skipFlagBits[BANDS]; ///< bits used to code skip flags
77  int skipFlagCount[BANDS]; ///< skipped coefficients per band
78  int skipFlags[COEFFS]; ///< skip coefficient decoding or not
79  int codewords[COEFFS]; ///< raw codewords read from bitstream
80 
82  DECLARE_ALIGNED(32, float, prev_win)[128];
83 } IMCChannel;
84 
85 typedef struct IMCContext {
87 
88  /** MDCT tables */
90 
91  float sqrt_tab[30];
93 
98  float *out_samples;
99  DECLARE_ALIGNED(32, float, temp)[256];
100 
102 
103  int8_t cyclTab[32], cyclTab2[32];
104  float weights1[31], weights2[31];
105 
107 } IMCContext;
108 
109 static VLC huffman_vlc[4][4];
110 
111 #define IMC_VLC_BITS 9
112 #define VLC_TABLES_SIZE 9512
113 
115 
116 static inline double freq2bark(double freq)
117 {
118  return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
119 }
120 
121 static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
122 {
123  double freqmin[32], freqmid[32], freqmax[32];
124  double scale = sampling_rate / (256.0 * 2.0 * 2.0);
125  double nyquist_freq = sampling_rate * 0.5;
126  double freq, bark, prev_bark = 0, tf, tb;
127  int i, j;
128 
129  for (i = 0; i < 32; i++) {
130  freq = (band_tab[i] + band_tab[i + 1] - 1) * scale;
131  bark = freq2bark(freq);
132 
133  if (i > 0) {
134  tb = bark - prev_bark;
135  q->weights1[i - 1] = ff_exp10(-1.0 * tb);
136  q->weights2[i - 1] = ff_exp10(-2.7 * tb);
137  }
138  prev_bark = bark;
139 
140  freqmid[i] = freq;
141 
142  tf = freq;
143  while (tf < nyquist_freq) {
144  tf += 0.5;
145  tb = freq2bark(tf);
146  if (tb > bark + 0.5)
147  break;
148  }
149  freqmax[i] = tf;
150 
151  tf = freq;
152  while (tf > 0.0) {
153  tf -= 0.5;
154  tb = freq2bark(tf);
155  if (tb <= bark - 0.5)
156  break;
157  }
158  freqmin[i] = tf;
159  }
160 
161  for (i = 0; i < 32; i++) {
162  freq = freqmax[i];
163  for (j = 31; j > 0 && freq <= freqmid[j]; j--);
164  q->cyclTab[i] = j + 1;
165 
166  freq = freqmin[i];
167  for (j = 0; j < 32 && freq >= freqmid[j]; j++);
168  q->cyclTab2[i] = j - 1;
169  }
170 }
171 
172 static av_cold void imc_init_static(void)
173 {
174  /* initialize the VLC tables */
175  for (int i = 0, offset = 0; i < 4 ; i++) {
176  for (int j = 0; j < 4; j++) {
180  imc_huffman_lens[i][j], 1,
181  imc_huffman_syms[i][j], 1, 1,
184  }
185  }
186 }
187 
189 {
190  int i, j, ret;
191  IMCContext *q = avctx->priv_data;
192  static AVOnce init_static_once = AV_ONCE_INIT;
193  float scale = 1.0f / (16384);
194 
195  if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) {
196  av_log(avctx, AV_LOG_ERROR,
197  "Strange sample rate of %i, file likely corrupt or "
198  "needing a new table derivation method.\n",
199  avctx->sample_rate);
200  return AVERROR_PATCHWELCOME;
201  }
202 
203  if (avctx->codec_id == AV_CODEC_ID_IMC) {
206  }
207 
208  if (avctx->ch_layout.nb_channels > 2) {
209  avpriv_request_sample(avctx, "Number of channels > 2");
210  return AVERROR_PATCHWELCOME;
211  }
212 
213  for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
214  q->chctx[j].decoder_reset = 1;
215 
216  for (i = 0; i < BANDS; i++)
217  q->chctx[j].old_floor[i] = 1.0;
218  }
219 
220  /* Build mdct window, a simple sine window normalized with sqrt(2) */
222  for (i = 0; i < COEFFS; i++)
223  q->mdct_sine_window[i] *= sqrt(2.0);
224 
225  /* Generate a square root table */
226  for (i = 0; i < 30; i++)
227  q->sqrt_tab[i] = sqrt(i);
228 
229  if (avctx->codec_id == AV_CODEC_ID_IAC) {
230  iac_generate_tabs(q, avctx->sample_rate);
231  } else {
232  memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
233  memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
234  memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
235  memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
236  }
237 
239  if (!q->fdsp)
240  return AVERROR(ENOMEM);
241 
242  ret = av_tx_init(&q->mdct, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, COEFFS, &scale, 0);
243  if (ret < 0)
244  return ret;
245 
246  ff_bswapdsp_init(&q->bdsp);
247 
249 
250  ff_thread_once(&init_static_once, imc_init_static);
251 
252  return 0;
253 }
254 
255 static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
256  float *flcoeffs2, int *bandWidthT,
257  float *flcoeffs3, float *flcoeffs5)
258 {
259  float workT1[BANDS];
260  float workT2[BANDS];
261  float workT3[BANDS];
262  float snr_limit = 1.e-30;
263  float accum = 0.0;
264  int i, cnt2;
265 
266  for (i = 0; i < BANDS; i++) {
267  flcoeffs5[i] = workT2[i] = 0.0;
268  if (bandWidthT[i]) {
269  workT1[i] = flcoeffs1[i] * flcoeffs1[i];
270  flcoeffs3[i] = 2.0 * flcoeffs2[i];
271  } else {
272  workT1[i] = 0.0;
273  flcoeffs3[i] = -30000.0;
274  }
275  workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
276  if (workT3[i] <= snr_limit)
277  workT3[i] = 0.0;
278  }
279 
280  for (i = 0; i < BANDS; i++) {
281  for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
282  flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
283  workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
284  }
285 
286  for (i = 1; i < BANDS; i++) {
287  accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
288  flcoeffs5[i] += accum;
289  }
290 
291  for (i = 0; i < BANDS; i++)
292  workT2[i] = 0.0;
293 
294  for (i = 0; i < BANDS; i++) {
295  for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
296  flcoeffs5[cnt2] += workT3[i];
297  workT2[cnt2+1] += workT3[i];
298  }
299 
300  accum = 0.0;
301 
302  for (i = BANDS-2; i >= 0; i--) {
303  accum = (workT2[i+1] + accum) * q->weights2[i];
304  flcoeffs5[i] += accum;
305  // there is missing code here, but it seems to never be triggered
306  }
307 }
308 
309 
310 static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
311  int *levlCoeffs)
312 {
313  int i;
314  VLC *hufftab[4];
315  int start = 0;
316  const uint8_t *cb_sel;
317  int s;
318 
319  s = stream_format_code >> 1;
320  hufftab[0] = &huffman_vlc[s][0];
321  hufftab[1] = &huffman_vlc[s][1];
322  hufftab[2] = &huffman_vlc[s][2];
323  hufftab[3] = &huffman_vlc[s][3];
324  cb_sel = imc_cb_select[s];
325 
326  if (stream_format_code & 4)
327  start = 1;
328  if (start)
329  levlCoeffs[0] = get_bits(&q->gb, 7);
330  for (i = start; i < BANDS; i++) {
331  levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table,
332  IMC_VLC_BITS, 2);
333  if (levlCoeffs[i] == 17)
334  levlCoeffs[i] += get_bits(&q->gb, 4);
335  }
336 }
337 
338 static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
339  int *levlCoeffs)
340 {
341  int i;
342 
343  q->coef0_pos = get_bits(&q->gb, 5);
344  levlCoeffs[0] = get_bits(&q->gb, 7);
345  for (i = 1; i < BANDS; i++)
346  levlCoeffs[i] = get_bits(&q->gb, 4);
347 }
348 
349 static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
350  float *flcoeffs1, float *flcoeffs2)
351 {
352  int i, level;
353  float tmp, tmp2;
354  // maybe some frequency division thingy
355 
356  flcoeffs1[0] = 20000.0 / exp2 (levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
357  flcoeffs2[0] = log2f(flcoeffs1[0]);
358  tmp = flcoeffs1[0];
359  tmp2 = flcoeffs2[0];
360 
361  for (i = 1; i < BANDS; i++) {
362  level = levlCoeffBuf[i];
363  if (level == 16) {
364  flcoeffs1[i] = 1.0;
365  flcoeffs2[i] = 0.0;
366  } else {
367  if (level < 17)
368  level -= 7;
369  else if (level <= 24)
370  level -= 32;
371  else
372  level -= 16;
373 
374  tmp *= imc_exp_tab[15 + level];
375  tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
376  flcoeffs1[i] = tmp;
377  flcoeffs2[i] = tmp2;
378  }
379  }
380 }
381 
382 
383 static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
384  float *old_floor, float *flcoeffs1,
385  float *flcoeffs2)
386 {
387  int i;
388  /* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
389  * and flcoeffs2 old scale factors
390  * might be incomplete due to a missing table that is in the binary code
391  */
392  for (i = 0; i < BANDS; i++) {
393  flcoeffs1[i] = 0;
394  if (levlCoeffBuf[i] < 16) {
395  flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
396  flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
397  } else {
398  flcoeffs1[i] = old_floor[i];
399  }
400  }
401 }
402 
403 static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
404  float *flcoeffs1, float *flcoeffs2)
405 {
406  int i, level, pos;
407  float tmp, tmp2;
408 
409  pos = q->coef0_pos;
410  flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
411  flcoeffs2[pos] = log2f(flcoeffs1[pos]);
412  tmp = flcoeffs1[pos];
413  tmp2 = flcoeffs2[pos];
414 
415  levlCoeffBuf++;
416  for (i = 0; i < BANDS; i++) {
417  if (i == pos)
418  continue;
419  level = *levlCoeffBuf++;
420  flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
421  flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
422  }
423 }
424 
425 /**
426  * Perform bit allocation depending on bits available
427  */
428 static int bit_allocation(IMCContext *q, IMCChannel *chctx,
429  int stream_format_code, int freebits, int flag)
430 {
431  int i, j;
432  const float limit = -1.e20;
433  float highest = 0.0;
434  int indx;
435  int t1 = 0;
436  int t2 = 1;
437  float summa = 0.0;
438  int iacc = 0;
439  int summer = 0;
440  int rres, cwlen;
441  float lowest = 1.e10;
442  int low_indx = 0;
443  float workT[32];
444  int flg;
445  int found_indx = 0;
446 
447  for (i = 0; i < BANDS; i++)
448  highest = FFMAX(highest, chctx->flcoeffs1[i]);
449 
450  for (i = 0; i < BANDS - 1; i++) {
451  if (chctx->flcoeffs5[i] <= 0) {
452  av_log(q->avctx, AV_LOG_ERROR, "flcoeffs5 %f invalid\n", chctx->flcoeffs5[i]);
453  return AVERROR_INVALIDDATA;
454  }
455  chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
456  }
457  chctx->flcoeffs4[BANDS - 1] = limit;
458 
459  highest = highest * 0.25;
460 
461  for (i = 0; i < BANDS; i++) {
462  indx = -1;
463  if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
464  indx = 0;
465 
466  if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
467  indx = 1;
468 
469  if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
470  indx = 2;
471 
472  if (indx == -1)
473  return AVERROR_INVALIDDATA;
474 
475  chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
476  }
477 
478  if (stream_format_code & 0x2) {
479  chctx->flcoeffs4[0] = limit;
480  chctx->flcoeffs4[1] = limit;
481  chctx->flcoeffs4[2] = limit;
482  chctx->flcoeffs4[3] = limit;
483  }
484 
485  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
486  iacc += chctx->bandWidthT[i];
487  summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
488  }
489 
490  if (!iacc)
491  return AVERROR_INVALIDDATA;
492 
493  chctx->bandWidthT[BANDS - 1] = 0;
494  summa = (summa * 0.5 - freebits) / iacc;
495 
496 
497  for (i = 0; i < BANDS / 2; i++) {
498  rres = summer - freebits;
499  if ((rres >= -8) && (rres <= 8))
500  break;
501 
502  summer = 0;
503  iacc = 0;
504 
505  for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
506  cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
507 
508  chctx->bitsBandT[j] = cwlen;
509  summer += chctx->bandWidthT[j] * cwlen;
510 
511  if (cwlen > 0)
512  iacc += chctx->bandWidthT[j];
513  }
514 
515  flg = t2;
516  t2 = 1;
517  if (freebits < summer)
518  t2 = -1;
519  if (i == 0)
520  flg = t2;
521  if (flg != t2)
522  t1++;
523 
524  summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
525  }
526 
527  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
528  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
529  chctx->CWlengthT[j] = chctx->bitsBandT[i];
530  }
531 
532  if (freebits > summer) {
533  for (i = 0; i < BANDS; i++) {
534  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
535  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
536  }
537 
538  highest = 0.0;
539 
540  do {
541  if (highest <= -1.e20)
542  break;
543 
544  found_indx = 0;
545  highest = -1.e20;
546 
547  for (i = 0; i < BANDS; i++) {
548  if (workT[i] > highest) {
549  highest = workT[i];
550  found_indx = i;
551  }
552  }
553 
554  if (highest > -1.e20) {
555  workT[found_indx] -= 2.0;
556  if (++chctx->bitsBandT[found_indx] == 6)
557  workT[found_indx] = -1.e20;
558 
559  for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
560  chctx->CWlengthT[j]++;
561  summer++;
562  }
563  }
564  } while (freebits > summer);
565  }
566  if (freebits < summer) {
567  for (i = 0; i < BANDS; i++) {
568  workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
569  : 1.e20;
570  }
571  if (stream_format_code & 0x2) {
572  workT[0] = 1.e20;
573  workT[1] = 1.e20;
574  workT[2] = 1.e20;
575  workT[3] = 1.e20;
576  }
577  while (freebits < summer) {
578  lowest = 1.e10;
579  low_indx = 0;
580  for (i = 0; i < BANDS; i++) {
581  if (workT[i] < lowest) {
582  lowest = workT[i];
583  low_indx = i;
584  }
585  }
586  // if (lowest >= 1.e10)
587  // break;
588  workT[low_indx] = lowest + 2.0;
589 
590  if (!--chctx->bitsBandT[low_indx])
591  workT[low_indx] = 1.e20;
592 
593  for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
594  if (chctx->CWlengthT[j] > 0) {
595  chctx->CWlengthT[j]--;
596  summer--;
597  }
598  }
599  }
600  }
601  return 0;
602 }
603 
604 static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
605 {
606  int i, j;
607 
608  memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
609  memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
610  for (i = 0; i < BANDS; i++) {
611  if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
612  continue;
613 
614  if (!chctx->skipFlagRaw[i]) {
615  chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
616 
617  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
618  chctx->skipFlags[j] = get_bits1(&q->gb);
619  if (chctx->skipFlags[j])
620  chctx->skipFlagCount[i]++;
621  }
622  } else {
623  for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
624  if (!get_bits1(&q->gb)) { // 0
625  chctx->skipFlagBits[i]++;
626  chctx->skipFlags[j] = 1;
627  chctx->skipFlags[j + 1] = 1;
628  chctx->skipFlagCount[i] += 2;
629  } else {
630  if (get_bits1(&q->gb)) { // 11
631  chctx->skipFlagBits[i] += 2;
632  chctx->skipFlags[j] = 0;
633  chctx->skipFlags[j + 1] = 1;
634  chctx->skipFlagCount[i]++;
635  } else {
636  chctx->skipFlagBits[i] += 3;
637  chctx->skipFlags[j + 1] = 0;
638  if (!get_bits1(&q->gb)) { // 100
639  chctx->skipFlags[j] = 1;
640  chctx->skipFlagCount[i]++;
641  } else { // 101
642  chctx->skipFlags[j] = 0;
643  }
644  }
645  }
646  }
647 
648  if (j < band_tab[i + 1]) {
649  chctx->skipFlagBits[i]++;
650  if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
651  chctx->skipFlagCount[i]++;
652  }
653  }
654  }
655 }
656 
657 /**
658  * Increase highest' band coefficient sizes as some bits won't be used
659  */
661  int summer)
662 {
663  float workT[32];
664  int corrected = 0;
665  int i, j;
666  float highest = 0;
667  int found_indx = 0;
668 
669  for (i = 0; i < BANDS; i++) {
670  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
671  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
672  }
673 
674  while (corrected < summer) {
675  if (highest <= -1.e20)
676  break;
677 
678  highest = -1.e20;
679 
680  for (i = 0; i < BANDS; i++) {
681  if (workT[i] > highest) {
682  highest = workT[i];
683  found_indx = i;
684  }
685  }
686 
687  if (highest > -1.e20) {
688  workT[found_indx] -= 2.0;
689  if (++(chctx->bitsBandT[found_indx]) == 6)
690  workT[found_indx] = -1.e20;
691 
692  for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
693  if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
694  chctx->CWlengthT[j]++;
695  corrected++;
696  }
697  }
698  }
699  }
700 }
701 
703  int stream_format_code)
704 {
705  int i, j;
706  int middle_value, cw_len, max_size;
707  const float *quantizer;
708 
709  for (i = 0; i < BANDS; i++) {
710  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
711  chctx->CWdecoded[j] = 0;
712  cw_len = chctx->CWlengthT[j];
713 
714  if (cw_len <= 0 || chctx->skipFlags[j])
715  continue;
716 
717  max_size = 1 << cw_len;
718  middle_value = max_size >> 1;
719 
720  if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
721  return AVERROR_INVALIDDATA;
722 
723  if (cw_len >= 4) {
724  quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
725  if (chctx->codewords[j] >= middle_value)
726  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
727  else
728  chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
729  }else{
730  quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
731  if (chctx->codewords[j] >= middle_value)
732  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
733  else
734  chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
735  }
736  }
737  }
738  return 0;
739 }
740 
741 
742 static void imc_get_coeffs(AVCodecContext *avctx,
743  IMCContext *q, IMCChannel *chctx)
744 {
745  int i, j, cw_len, cw;
746 
747  for (i = 0; i < BANDS; i++) {
748  if (!chctx->sumLenArr[i])
749  continue;
750  if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
751  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
752  cw_len = chctx->CWlengthT[j];
753  cw = 0;
754 
755  if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) {
756  if (get_bits_count(&q->gb) + cw_len > 512) {
757  av_log(avctx, AV_LOG_WARNING,
758  "Potential problem on band %i, coefficient %i"
759  ": cw_len=%i\n", i, j, cw_len);
760  } else
761  cw = get_bits(&q->gb, cw_len);
762  }
763 
764  chctx->codewords[j] = cw;
765  }
766  }
767  }
768 }
769 
771 {
772  int i, j;
773  int summer;
774 
775  for (i = 0; i < BANDS; i++) {
776  chctx->sumLenArr[i] = 0;
777  chctx->skipFlagRaw[i] = 0;
778  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
779  chctx->sumLenArr[i] += chctx->CWlengthT[j];
780  if (chctx->bandFlagsBuf[i])
781  if (((int)((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
782  chctx->skipFlagRaw[i] = 1;
783  }
784 
785  imc_get_skip_coeff(q, chctx);
786 
787  for (i = 0; i < BANDS; i++) {
788  chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
789  /* band has flag set and at least one coded coefficient */
790  if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
791  chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
792  q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
793  }
794  }
795 
796  /* calculate bits left, bits needed and adjust bit allocation */
797  summer = 0;
798 
799  for (i = 0; i < BANDS; i++) {
800  if (chctx->bandFlagsBuf[i]) {
801  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
802  if (chctx->skipFlags[j]) {
803  summer += chctx->CWlengthT[j];
804  chctx->CWlengthT[j] = 0;
805  }
806  }
807  summer -= chctx->skipFlagBits[i];
808  }
809  }
810  imc_adjust_bit_allocation(q, chctx, summer);
811 }
812 
813 static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
814 {
815  int stream_format_code;
816  int imc_hdr, i, j, ret;
817  int flag;
818  int bits;
819  int bitscount;
820  IMCChannel *chctx = q->chctx + ch;
821 
822 
823  /* Check the frame header */
824  imc_hdr = get_bits(&q->gb, 9);
825  if (imc_hdr & 0x18) {
826  av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
827  av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
828  return AVERROR_INVALIDDATA;
829  }
830  stream_format_code = get_bits(&q->gb, 3);
831 
832  if (stream_format_code & 0x04)
833  chctx->decoder_reset = 1;
834 
835  if (chctx->decoder_reset) {
836  for (i = 0; i < BANDS; i++)
837  chctx->old_floor[i] = 1.0;
838  for (i = 0; i < COEFFS; i++)
839  chctx->CWdecoded[i] = 0;
840  chctx->decoder_reset = 0;
841  }
842 
843  flag = get_bits1(&q->gb);
844  if (stream_format_code & 0x1)
845  imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
846  else
847  imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
848 
849  if (stream_format_code & 0x1)
851  chctx->flcoeffs1, chctx->flcoeffs2);
852  else if (stream_format_code & 0x4)
854  chctx->flcoeffs1, chctx->flcoeffs2);
855  else
857  chctx->flcoeffs1, chctx->flcoeffs2);
858 
859  for(i=0; i<BANDS; i++) {
860  if(chctx->flcoeffs1[i] > INT_MAX) {
861  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
862  return AVERROR_INVALIDDATA;
863  }
864  }
865 
866  memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
867 
868  if (stream_format_code & 0x1) {
869  for (i = 0; i < BANDS; i++) {
870  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
871  chctx->bandFlagsBuf[i] = 0;
872  chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
873  chctx->flcoeffs5[i] = 1.0;
874  }
875  } else {
876  for (i = 0; i < BANDS; i++) {
877  if (chctx->levlCoeffBuf[i] == 16) {
878  chctx->bandWidthT[i] = 0;
879  } else
880  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
881  }
882 
883  memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
884  for (i = 0; i < BANDS - 1; i++)
885  if (chctx->bandWidthT[i])
886  chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
887 
888  imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
889  chctx->bandWidthT, chctx->flcoeffs3,
890  chctx->flcoeffs5);
891  }
892 
893  bitscount = 0;
894  /* first 4 bands will be assigned 5 bits per coefficient */
895  if (stream_format_code & 0x2) {
896  bitscount += 15;
897 
898  chctx->bitsBandT[0] = 5;
899  chctx->CWlengthT[0] = 5;
900  chctx->CWlengthT[1] = 5;
901  chctx->CWlengthT[2] = 5;
902  for (i = 1; i < 4; i++) {
903  if (stream_format_code & 0x1)
904  bits = 5;
905  else
906  bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
907  chctx->bitsBandT[i] = bits;
908  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
909  chctx->CWlengthT[j] = bits;
910  bitscount += bits;
911  }
912  }
913  }
914  if (avctx->codec_id == AV_CODEC_ID_IAC) {
915  bitscount += !!chctx->bandWidthT[BANDS - 1];
916  if (!(stream_format_code & 0x2))
917  bitscount += 16;
918  }
919 
920  if ((ret = bit_allocation(q, chctx, stream_format_code,
921  512 - bitscount - get_bits_count(&q->gb),
922  flag)) < 0) {
923  av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
924  chctx->decoder_reset = 1;
925  return ret;
926  }
927 
928  if (stream_format_code & 0x1) {
929  for (i = 0; i < BANDS; i++)
930  chctx->skipFlags[i] = 0;
931  } else {
932  imc_refine_bit_allocation(q, chctx);
933  }
934 
935  for (i = 0; i < BANDS; i++) {
936  chctx->sumLenArr[i] = 0;
937 
938  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
939  if (!chctx->skipFlags[j])
940  chctx->sumLenArr[i] += chctx->CWlengthT[j];
941  }
942 
943  memset(chctx->codewords, 0, sizeof(chctx->codewords));
944 
945  imc_get_coeffs(avctx, q, chctx);
946 
947  if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
948  av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
949  chctx->decoder_reset = 1;
950  return AVERROR_INVALIDDATA;
951  }
952 
953  memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
954 
955  q->mdct_fn(q->mdct, q->temp, chctx->CWdecoded, sizeof(float));
956  q->fdsp->vector_fmul_window(q->out_samples, chctx->prev_win, q->temp,
957  q->mdct_sine_window, 128);
958  memcpy(chctx->prev_win, q->temp + 128, sizeof(float)*128);
959 
960  return 0;
961 }
962 
964  int *got_frame_ptr, AVPacket *avpkt)
965 {
966  const uint8_t *buf = avpkt->data;
967  int buf_size = avpkt->size;
968  int ret, i;
969 
970  IMCContext *q = avctx->priv_data;
971 
973 
974  q->avctx = avctx;
975 
976  if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
977  av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
978  return AVERROR_INVALIDDATA;
979  }
980 
981  /* get output buffer */
982  frame->nb_samples = COEFFS;
983  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
984  return ret;
985 
986  for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
987  q->out_samples = (float *)frame->extended_data[i];
988 
989  q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
990 
991  init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
992 
993  buf += IMC_BLOCK_SIZE;
994 
995  if ((ret = imc_decode_block(avctx, q, i)) < 0)
996  return ret;
997  }
998 
999  if (avctx->ch_layout.nb_channels == 2) {
1000  q->fdsp->butterflies_float((float *)frame->extended_data[0],
1001  (float *)frame->extended_data[1], COEFFS);
1002  }
1003 
1004  *got_frame_ptr = 1;
1005 
1006  return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
1007 }
1008 
1010 {
1011  IMCContext *q = avctx->priv_data;
1012 
1013  av_free(q->fdsp);
1014  av_tx_uninit(&q->mdct);
1015 
1016  return 0;
1017 }
1018 
1019 static av_cold void flush(AVCodecContext *avctx)
1020 {
1021  IMCContext *q = avctx->priv_data;
1022 
1023  q->chctx[0].decoder_reset =
1024  q->chctx[1].decoder_reset = 1;
1025 }
1026 
1027 #if CONFIG_IMC_DECODER
1028 const FFCodec ff_imc_decoder = {
1029  .p.name = "imc",
1030  CODEC_LONG_NAME("IMC (Intel Music Coder)"),
1031  .p.type = AVMEDIA_TYPE_AUDIO,
1032  .p.id = AV_CODEC_ID_IMC,
1033  .priv_data_size = sizeof(IMCContext),
1034  .init = imc_decode_init,
1035  .close = imc_decode_close,
1037  .flush = flush,
1038  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1039  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1041 };
1042 #endif
1043 #if CONFIG_IAC_DECODER
1044 const FFCodec ff_iac_decoder = {
1045  .p.name = "iac",
1046  CODEC_LONG_NAME("IAC (Indeo Audio Coder)"),
1047  .p.type = AVMEDIA_TYPE_AUDIO,
1048  .p.id = AV_CODEC_ID_IAC,
1049  .priv_data_size = sizeof(IMCContext),
1050  .init = imc_decode_init,
1051  .close = imc_decode_close,
1053  .flush = flush,
1054  .p.capabilities = AV_CODEC_CAP_DR1,
1055  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1057 };
1058 #endif
ff_iac_decoder
const FFCodec ff_iac_decoder
bswapdsp.h
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
IMCContext::cyclTab2
int8_t cyclTab2[32]
Definition: imc.c:103
level
uint8_t level
Definition: svq3.c:204
flush
static av_cold void flush(AVCodecContext *avctx)
Definition: imc.c:1019
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
IMCChannel::CWlengthT
int CWlengthT[COEFFS]
how many bits in each codeword
Definition: imc.c:71
mem_internal.h
IMCContext::coef0_pos
int coef0_pos
Definition: imc.c:101
imc_exp_tab
static const float imc_exp_tab[32]
Definition: imcdata.h:87
IMCChannel::flcoeffs3
float flcoeffs3[BANDS]
Definition: imc.c:63
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1034
imc_huffman_lens
static const uint8_t imc_huffman_lens[4][4][18]
Definition: imcdata.h:115
IMCContext::mdct_fn
av_tx_fn mdct_fn
Definition: imc.c:97
log2f
#define log2f(x)
Definition: libm.h:409
thread.h
IMCChannel::skipFlagCount
int skipFlagCount[BANDS]
skipped coefficients per band
Definition: imc.c:77
AVTXContext
Definition: tx_priv.h:228
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:256
imc_quantizer2
static const float imc_quantizer2[2][56]
Definition: imcdata.h:66
IMCChannel::CWdecoded
float CWdecoded[COEFFS]
Definition: imc.c:67
IMCContext::cyclTab
int8_t cyclTab[32]
Definition: imc.c:103
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
iac_generate_tabs
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
Definition: imc.c:121
AVPacket::data
uint8_t * data
Definition: packet.h:374
IMCContext::fdsp
AVFloatDSPContext * fdsp
Definition: imc.c:94
COEFFS
#define COEFFS
Definition: imc.c:57
FFCodec
Definition: codec_internal.h:127
IMCChannel::old_floor
float old_floor[BANDS]
Definition: imc.c:60
t1
#define t1
Definition: regdef.h:29
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AV_CODEC_ID_IMC
@ AV_CODEC_ID_IMC
Definition: codec_id.h:465
IMCChannel::prev_win
float prev_win[128]
Definition: imc.c:82
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:493
imc_calculate_coeffs
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
Definition: imc.c:255
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:883
imc_read_level_coeffs_raw
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:338
vlc_tables
static VLCElem vlc_tables[VLC_TABLES_SIZE]
Definition: imc.c:114
imc_exp_tab2
static const float *const imc_exp_tab2
Definition: imcdata.h:97
AVFloatDSPContext::butterflies_float
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
Definition: float_dsp.h:164
imc_read_level_coeffs
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:310
IMCChannel::flcoeffs4
float flcoeffs4[BANDS]
Definition: imc.c:64
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:325
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
IMCChannel::skipFlagRaw
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
Definition: imc.c:75
cyclTab
static const int8_t cyclTab[32]
Definition: imcdata.h:36
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2054
imc_init_static
static av_cold void imc_init_static(void)
Definition: imc.c:172
GetBitContext
Definition: get_bits.h:107
imc_weights2
static const float imc_weights2[31]
Definition: imcdata.h:53
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:506
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
IMCContext::sqrt_tab
float sqrt_tab[30]
Definition: imc.c:91
IMC_BLOCK_SIZE
#define IMC_BLOCK_SIZE
Definition: imc.c:54
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:184
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:127
float
float
Definition: af_crystalizer.c:122
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
imc_decode_close
static av_cold int imc_decode_close(AVCodecContext *avctx)
Definition: imc.c:1009
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
s
#define s(width, name)
Definition: cbs_vp9.c:256
IMCChannel
Definition: imc.c:59
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
bits
uint8_t bits
Definition: vp3data.h:128
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:129
imc_weights1
static const float imc_weights1[31]
Definition: imcdata.h:47
imc_get_skip_coeff
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:604
IMCChannel::flcoeffs5
float flcoeffs5[BANDS]
Definition: imc.c:65
decode.h
get_bits.h
BswapDSPContext::bswap16_buf
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
Definition: bswapdsp.h:26
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
IMCChannel::bandFlagsBuf
int bandFlagsBuf[BANDS]
flags for each band
Definition: imc.c:73
imc_decode_level_coefficients2
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:383
if
if(ret)
Definition: filter_design.txt:179
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:182
ff_bswapdsp_init
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
IMCContext::bdsp
BswapDSPContext bdsp
Definition: imc.c:95
IMCChannel::flcoeffs6
float flcoeffs6[BANDS]
Definition: imc.c:66
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:378
IMCContext::temp
float temp[256]
Definition: imc.c:99
band_tab
static const uint16_t band_tab[33]
Definition: imcdata.h:29
ff_init_vlc_from_lengths
int ff_init_vlc_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
Definition: vlc.c:328
huffman_vlc
static VLC huffman_vlc[4][4]
Definition: imc.c:109
IMCContext::weights1
float weights1[31]
Definition: imc.c:104
av_clipf
av_clipf
Definition: af_crystalizer.c:122
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:631
AVOnce
#define AVOnce
Definition: thread.h:181
cyclTab2
static const int8_t cyclTab2[32]
Definition: imcdata.h:42
float_dsp.h
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:103
IMCChannel::bandWidthT
int bandWidthT[BANDS]
codewords per band
Definition: imc.c:69
VLC::table_allocated
int table_allocated
Definition: vlc.h:34
imc_decode_level_coefficients_raw
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:403
imc_huffman_syms
static const uint8_t imc_huffman_syms[4][4][18]
Definition: imcdata.h:142
VLC_TABLES_SIZE
#define VLC_TABLES_SIZE
Definition: imc.c:112
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1473
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:375
powf
#define powf(x, y)
Definition: libm.h:50
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1050
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
VLCElem
Definition: vlc.h:27
imc_quantizer1
static const float imc_quantizer1[4][8]
Definition: imcdata.h:59
AVFloatDSPContext
Definition: float_dsp.h:24
sinewin.h
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
imc_decode_frame
static int imc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: imc.c:963
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
ff_sine_window_init
void ff_sine_window_init(float *window, int n)
Generate a sine window.
Definition: sinewin_tablegen.h:59
flag
#define flag(name)
Definition: cbs_av1.c:553
imc_refine_bit_allocation
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:770
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
bit_allocation
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:428
internal.h
inverse_quant_coeff
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
Definition: imc.c:702
IMCChannel::bitsBandT
int bitsBandT[BANDS]
how many bits per codeword in band
Definition: imc.c:70
BANDS
#define BANDS
Definition: imc.c:56
xTab
static const float xTab[14]
Definition: imcdata.h:84
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
exp2
#define exp2(x)
Definition: libm.h:288
tb
#define tb
Definition: regdef.h:68
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:191
imc_decode_init
static av_cold int imc_decode_init(AVCodecContext *avctx)
Definition: imc.c:188
IMCChannel::levlCoeffBuf
int levlCoeffBuf[BANDS]
Definition: imc.c:72
IMCContext
Definition: imc.c:85
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:130
AV_CODEC_ID_IAC
@ AV_CODEC_ID_IAC
Definition: codec_id.h:496
ret
ret
Definition: filter_design.txt:187
INIT_VLC_STATIC_OVERLONG
#define INIT_VLC_STATIC_OVERLONG
Definition: vlc.h:101
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
imc_huffman_sizes
static const uint8_t imc_huffman_sizes[4]
Definition: imcdata.h:111
pos
unsigned int pos
Definition: spdifenc.c:413
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:426
IMCContext::out_samples
float * out_samples
Definition: imc.c:98
IMC_VLC_BITS
#define IMC_VLC_BITS
Definition: imc.c:111
channel_layout.h
t2
#define t2
Definition: regdef.h:30
IMCChannel::skipFlagBits
int skipFlagBits[BANDS]
bits used to code skip flags
Definition: imc.c:76
IMCContext::weights2
float weights2[31]
Definition: imc.c:104
VLC
Definition: vlc.h:31
IMCContext::avctx
AVCodecContext * avctx
Definition: imc.c:106
IMCChannel::flcoeffs2
float flcoeffs2[BANDS]
Definition: imc.c:62
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:632
imcdata.h
VLC::table
VLCElem * table
Definition: vlc.h:33
tf
#define tf
Definition: regdef.h:73
ffmath.h
IMCChannel::skipFlags
int skipFlags[COEFFS]
skip coefficient decoding or not
Definition: imc.c:78
ff_imc_decoder
const FFCodec ff_imc_decoder
IMCContext::chctx
IMCChannel chctx[2]
Definition: imc.c:86
VLC::table_size
int table_size
Definition: vlc.h:34
imc_decode_block
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
Definition: imc.c:813
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:321
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVFloatDSPContext::vector_fmul_window
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
Definition: float_dsp.h:119
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:368
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
imc_cb_select
static const uint8_t imc_cb_select[4][32]
Definition: imcdata.h:100
imc_decode_level_coefficients
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:349
freq2bark
static double freq2bark(double freq)
Definition: imc.c:116
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
IMCContext::mdct
AVTXContext * mdct
Definition: imc.c:96
IMCContext::mdct_sine_window
float mdct_sine_window[COEFFS]
MDCT tables.
Definition: imc.c:89
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
IMCContext::gb
GetBitContext gb
Definition: imc.c:92
BswapDSPContext
Definition: bswapdsp.h:24
IMCChannel::decoder_reset
int decoder_reset
Definition: imc.c:81
imc_get_coeffs
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
Definition: imc.c:742
imc_adjust_bit_allocation
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:660
IMCChannel::flcoeffs1
float flcoeffs1[BANDS]
Definition: imc.c:61
tx.h
IMCChannel::codewords
int codewords[COEFFS]
raw codewords read from bitstream
Definition: imc.c:79
IMCChannel::sumLenArr
int sumLenArr[BANDS]
bits for all coeffs in band
Definition: imc.c:74