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 
33 #include <math.h>
34 #include <stddef.h>
35 #include <stdio.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 
44 #include "avcodec.h"
45 #include "bswapdsp.h"
46 #include "get_bits.h"
47 #include "fft.h"
48 #include "internal.h"
49 #include "sinewin.h"
50 
51 #include "imcdata.h"
52 
53 #define IMC_BLOCK_SIZE 64
54 #define IMC_FRAME_ID 0x21
55 #define BANDS 32
56 #define COEFFS 256
57 
58 typedef struct IMCChannel {
59  float old_floor[BANDS];
60  float flcoeffs1[BANDS];
61  float flcoeffs2[BANDS];
62  float flcoeffs3[BANDS];
63  float flcoeffs4[BANDS];
64  float flcoeffs5[BANDS];
65  float flcoeffs6[BANDS];
66  float CWdecoded[COEFFS];
67 
68  int bandWidthT[BANDS]; ///< codewords per band
69  int bitsBandT[BANDS]; ///< how many bits per codeword in band
70  int CWlengthT[COEFFS]; ///< how many bits in each codeword
72  int bandFlagsBuf[BANDS]; ///< flags for each band
73  int sumLenArr[BANDS]; ///< bits for all coeffs in band
74  int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
75  int skipFlagBits[BANDS]; ///< bits used to code skip flags
76  int skipFlagCount[BANDS]; ///< skipped coefficients per band
77  int skipFlags[COEFFS]; ///< skip coefficient decoding or not
78  int codewords[COEFFS]; ///< raw codewords read from bitstream
79 
81 
83 } IMCChannel;
84 
85 typedef struct IMCContext {
87 
88  /** MDCT tables */
89  //@{
91  float post_cos[COEFFS];
92  float post_sin[COEFFS];
93  float pre_coef1[COEFFS];
94  float pre_coef2[COEFFS];
95  //@}
96 
97  float sqrt_tab[30];
99 
101  void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len);
104  float *out_samples;
105 
107 
108  int8_t cyclTab[32], cyclTab2[32];
109  float weights1[31], weights2[31];
110 
112 } IMCContext;
113 
114 static VLC huffman_vlc[4][4];
115 
116 #define IMC_VLC_BITS 9
117 #define VLC_TABLES_SIZE 9512
118 
120 
121 static 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 
126 static 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] = ff_exp10(-1.0 * tb);
141  q->weights2[i - 1] = ff_exp10(-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 
177 static av_cold void imc_init_static(void)
178 {
179  /* initialize the VLC tables */
180  for (int i = 0, offset = 0; i < 4 ; i++) {
181  for (int j = 0; j < 4; j++) {
185  imc_huffman_lens[i][j], 1,
186  imc_huffman_syms[i][j], 1, 1,
189  }
190  }
191 }
192 
194 {
195  int i, j, ret;
196  IMCContext *q = avctx->priv_data;
197  static AVOnce init_static_once = AV_ONCE_INIT;
198  AVFloatDSPContext *fdsp;
199  double r1, r2;
200 
201  if (avctx->codec_id == AV_CODEC_ID_IAC && avctx->sample_rate > 96000) {
202  av_log(avctx, AV_LOG_ERROR,
203  "Strange sample rate of %i, file likely corrupt or "
204  "needing a new table derivation method.\n",
205  avctx->sample_rate);
206  return AVERROR_PATCHWELCOME;
207  }
208 
209  if (avctx->codec_id == AV_CODEC_ID_IMC)
210  avctx->channels = 1;
211 
212  if (avctx->channels > 2) {
213  avpriv_request_sample(avctx, "Number of channels > 2");
214  return AVERROR_PATCHWELCOME;
215  }
216 
217  for (j = 0; j < avctx->channels; j++) {
218  q->chctx[j].decoder_reset = 1;
219 
220  for (i = 0; i < BANDS; i++)
221  q->chctx[j].old_floor[i] = 1.0;
222 
223  for (i = 0; i < COEFFS / 2; i++)
224  q->chctx[j].last_fft_im[i] = 0;
225  }
226 
227  /* Build mdct window, a simple sine window normalized with sqrt(2) */
229  for (i = 0; i < COEFFS; i++)
230  q->mdct_sine_window[i] *= sqrt(2.0);
231  for (i = 0; i < COEFFS / 2; i++) {
232  q->post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);
233  q->post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);
234 
235  r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
236  r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
237 
238  if (i & 0x1) {
239  q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);
240  q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
241  } else {
242  q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
243  q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
244  }
245  }
246 
247  /* Generate a square root table */
248 
249  for (i = 0; i < 30; i++)
250  q->sqrt_tab[i] = sqrt(i);
251 
252  if (avctx->codec_id == AV_CODEC_ID_IAC) {
253  iac_generate_tabs(q, avctx->sample_rate);
254  } else {
255  memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
256  memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
257  memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
258  memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
259  }
260 
262  if (!fdsp)
263  return AVERROR(ENOMEM);
265  av_free(fdsp);
266  if ((ret = ff_fft_init(&q->fft, 7, 1))) {
267  av_log(avctx, AV_LOG_INFO, "FFT init failed\n");
268  return ret;
269  }
270  ff_bswapdsp_init(&q->bdsp);
271 
273  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
275 
276  ff_thread_once(&init_static_once, imc_init_static);
277 
278  return 0;
279 }
280 
281 static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
282  float *flcoeffs2, int *bandWidthT,
283  float *flcoeffs3, float *flcoeffs5)
284 {
285  float workT1[BANDS];
286  float workT2[BANDS];
287  float workT3[BANDS];
288  float snr_limit = 1.e-30;
289  float accum = 0.0;
290  int i, cnt2;
291 
292  for (i = 0; i < BANDS; i++) {
293  flcoeffs5[i] = workT2[i] = 0.0;
294  if (bandWidthT[i]) {
295  workT1[i] = flcoeffs1[i] * flcoeffs1[i];
296  flcoeffs3[i] = 2.0 * flcoeffs2[i];
297  } else {
298  workT1[i] = 0.0;
299  flcoeffs3[i] = -30000.0;
300  }
301  workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
302  if (workT3[i] <= snr_limit)
303  workT3[i] = 0.0;
304  }
305 
306  for (i = 0; i < BANDS; i++) {
307  for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
308  flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
309  workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
310  }
311 
312  for (i = 1; i < BANDS; i++) {
313  accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
314  flcoeffs5[i] += accum;
315  }
316 
317  for (i = 0; i < BANDS; i++)
318  workT2[i] = 0.0;
319 
320  for (i = 0; i < BANDS; i++) {
321  for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
322  flcoeffs5[cnt2] += workT3[i];
323  workT2[cnt2+1] += workT3[i];
324  }
325 
326  accum = 0.0;
327 
328  for (i = BANDS-2; i >= 0; i--) {
329  accum = (workT2[i+1] + accum) * q->weights2[i];
330  flcoeffs5[i] += accum;
331  // there is missing code here, but it seems to never be triggered
332  }
333 }
334 
335 
336 static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
337  int *levlCoeffs)
338 {
339  int i;
340  VLC *hufftab[4];
341  int start = 0;
342  const uint8_t *cb_sel;
343  int s;
344 
345  s = stream_format_code >> 1;
346  hufftab[0] = &huffman_vlc[s][0];
347  hufftab[1] = &huffman_vlc[s][1];
348  hufftab[2] = &huffman_vlc[s][2];
349  hufftab[3] = &huffman_vlc[s][3];
350  cb_sel = imc_cb_select[s];
351 
352  if (stream_format_code & 4)
353  start = 1;
354  if (start)
355  levlCoeffs[0] = get_bits(&q->gb, 7);
356  for (i = start; i < BANDS; i++) {
357  levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table,
358  IMC_VLC_BITS, 2);
359  if (levlCoeffs[i] == 17)
360  levlCoeffs[i] += get_bits(&q->gb, 4);
361  }
362 }
363 
364 static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
365  int *levlCoeffs)
366 {
367  int i;
368 
369  q->coef0_pos = get_bits(&q->gb, 5);
370  levlCoeffs[0] = get_bits(&q->gb, 7);
371  for (i = 1; i < BANDS; i++)
372  levlCoeffs[i] = get_bits(&q->gb, 4);
373 }
374 
375 static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
376  float *flcoeffs1, float *flcoeffs2)
377 {
378  int i, level;
379  float tmp, tmp2;
380  // maybe some frequency division thingy
381 
382  flcoeffs1[0] = 20000.0 / exp2 (levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
383  flcoeffs2[0] = log2f(flcoeffs1[0]);
384  tmp = flcoeffs1[0];
385  tmp2 = flcoeffs2[0];
386 
387  for (i = 1; i < BANDS; i++) {
388  level = levlCoeffBuf[i];
389  if (level == 16) {
390  flcoeffs1[i] = 1.0;
391  flcoeffs2[i] = 0.0;
392  } else {
393  if (level < 17)
394  level -= 7;
395  else if (level <= 24)
396  level -= 32;
397  else
398  level -= 16;
399 
400  tmp *= imc_exp_tab[15 + level];
401  tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
402  flcoeffs1[i] = tmp;
403  flcoeffs2[i] = tmp2;
404  }
405  }
406 }
407 
408 
409 static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
410  float *old_floor, float *flcoeffs1,
411  float *flcoeffs2)
412 {
413  int i;
414  /* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
415  * and flcoeffs2 old scale factors
416  * might be incomplete due to a missing table that is in the binary code
417  */
418  for (i = 0; i < BANDS; i++) {
419  flcoeffs1[i] = 0;
420  if (levlCoeffBuf[i] < 16) {
421  flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
422  flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
423  } else {
424  flcoeffs1[i] = old_floor[i];
425  }
426  }
427 }
428 
429 static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
430  float *flcoeffs1, float *flcoeffs2)
431 {
432  int i, level, pos;
433  float tmp, tmp2;
434 
435  pos = q->coef0_pos;
436  flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
437  flcoeffs2[pos] = log2f(flcoeffs1[pos]);
438  tmp = flcoeffs1[pos];
439  tmp2 = flcoeffs2[pos];
440 
441  levlCoeffBuf++;
442  for (i = 0; i < BANDS; i++) {
443  if (i == pos)
444  continue;
445  level = *levlCoeffBuf++;
446  flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
447  flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
448  }
449 }
450 
451 /**
452  * Perform bit allocation depending on bits available
453  */
454 static int bit_allocation(IMCContext *q, IMCChannel *chctx,
455  int stream_format_code, int freebits, int flag)
456 {
457  int i, j;
458  const float limit = -1.e20;
459  float highest = 0.0;
460  int indx;
461  int t1 = 0;
462  int t2 = 1;
463  float summa = 0.0;
464  int iacc = 0;
465  int summer = 0;
466  int rres, cwlen;
467  float lowest = 1.e10;
468  int low_indx = 0;
469  float workT[32];
470  int flg;
471  int found_indx = 0;
472 
473  for (i = 0; i < BANDS; i++)
474  highest = FFMAX(highest, chctx->flcoeffs1[i]);
475 
476  for (i = 0; i < BANDS - 1; i++) {
477  if (chctx->flcoeffs5[i] <= 0) {
478  av_log(q->avctx, AV_LOG_ERROR, "flcoeffs5 %f invalid\n", chctx->flcoeffs5[i]);
479  return AVERROR_INVALIDDATA;
480  }
481  chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
482  }
483  chctx->flcoeffs4[BANDS - 1] = limit;
484 
485  highest = highest * 0.25;
486 
487  for (i = 0; i < BANDS; i++) {
488  indx = -1;
489  if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
490  indx = 0;
491 
492  if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
493  indx = 1;
494 
495  if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
496  indx = 2;
497 
498  if (indx == -1)
499  return AVERROR_INVALIDDATA;
500 
501  chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
502  }
503 
504  if (stream_format_code & 0x2) {
505  chctx->flcoeffs4[0] = limit;
506  chctx->flcoeffs4[1] = limit;
507  chctx->flcoeffs4[2] = limit;
508  chctx->flcoeffs4[3] = limit;
509  }
510 
511  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
512  iacc += chctx->bandWidthT[i];
513  summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
514  }
515 
516  if (!iacc)
517  return AVERROR_INVALIDDATA;
518 
519  chctx->bandWidthT[BANDS - 1] = 0;
520  summa = (summa * 0.5 - freebits) / iacc;
521 
522 
523  for (i = 0; i < BANDS / 2; i++) {
524  rres = summer - freebits;
525  if ((rres >= -8) && (rres <= 8))
526  break;
527 
528  summer = 0;
529  iacc = 0;
530 
531  for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
532  cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
533 
534  chctx->bitsBandT[j] = cwlen;
535  summer += chctx->bandWidthT[j] * cwlen;
536 
537  if (cwlen > 0)
538  iacc += chctx->bandWidthT[j];
539  }
540 
541  flg = t2;
542  t2 = 1;
543  if (freebits < summer)
544  t2 = -1;
545  if (i == 0)
546  flg = t2;
547  if (flg != t2)
548  t1++;
549 
550  summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
551  }
552 
553  for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
554  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
555  chctx->CWlengthT[j] = chctx->bitsBandT[i];
556  }
557 
558  if (freebits > summer) {
559  for (i = 0; i < BANDS; i++) {
560  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
561  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
562  }
563 
564  highest = 0.0;
565 
566  do {
567  if (highest <= -1.e20)
568  break;
569 
570  found_indx = 0;
571  highest = -1.e20;
572 
573  for (i = 0; i < BANDS; i++) {
574  if (workT[i] > highest) {
575  highest = workT[i];
576  found_indx = i;
577  }
578  }
579 
580  if (highest > -1.e20) {
581  workT[found_indx] -= 2.0;
582  if (++chctx->bitsBandT[found_indx] == 6)
583  workT[found_indx] = -1.e20;
584 
585  for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
586  chctx->CWlengthT[j]++;
587  summer++;
588  }
589  }
590  } while (freebits > summer);
591  }
592  if (freebits < summer) {
593  for (i = 0; i < BANDS; i++) {
594  workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
595  : 1.e20;
596  }
597  if (stream_format_code & 0x2) {
598  workT[0] = 1.e20;
599  workT[1] = 1.e20;
600  workT[2] = 1.e20;
601  workT[3] = 1.e20;
602  }
603  while (freebits < summer) {
604  lowest = 1.e10;
605  low_indx = 0;
606  for (i = 0; i < BANDS; i++) {
607  if (workT[i] < lowest) {
608  lowest = workT[i];
609  low_indx = i;
610  }
611  }
612  // if (lowest >= 1.e10)
613  // break;
614  workT[low_indx] = lowest + 2.0;
615 
616  if (!--chctx->bitsBandT[low_indx])
617  workT[low_indx] = 1.e20;
618 
619  for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
620  if (chctx->CWlengthT[j] > 0) {
621  chctx->CWlengthT[j]--;
622  summer--;
623  }
624  }
625  }
626  }
627  return 0;
628 }
629 
630 static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
631 {
632  int i, j;
633 
634  memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
635  memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
636  for (i = 0; i < BANDS; i++) {
637  if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
638  continue;
639 
640  if (!chctx->skipFlagRaw[i]) {
641  chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
642 
643  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
644  chctx->skipFlags[j] = get_bits1(&q->gb);
645  if (chctx->skipFlags[j])
646  chctx->skipFlagCount[i]++;
647  }
648  } else {
649  for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
650  if (!get_bits1(&q->gb)) { // 0
651  chctx->skipFlagBits[i]++;
652  chctx->skipFlags[j] = 1;
653  chctx->skipFlags[j + 1] = 1;
654  chctx->skipFlagCount[i] += 2;
655  } else {
656  if (get_bits1(&q->gb)) { // 11
657  chctx->skipFlagBits[i] += 2;
658  chctx->skipFlags[j] = 0;
659  chctx->skipFlags[j + 1] = 1;
660  chctx->skipFlagCount[i]++;
661  } else {
662  chctx->skipFlagBits[i] += 3;
663  chctx->skipFlags[j + 1] = 0;
664  if (!get_bits1(&q->gb)) { // 100
665  chctx->skipFlags[j] = 1;
666  chctx->skipFlagCount[i]++;
667  } else { // 101
668  chctx->skipFlags[j] = 0;
669  }
670  }
671  }
672  }
673 
674  if (j < band_tab[i + 1]) {
675  chctx->skipFlagBits[i]++;
676  if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
677  chctx->skipFlagCount[i]++;
678  }
679  }
680  }
681 }
682 
683 /**
684  * Increase highest' band coefficient sizes as some bits won't be used
685  */
687  int summer)
688 {
689  float workT[32];
690  int corrected = 0;
691  int i, j;
692  float highest = 0;
693  int found_indx = 0;
694 
695  for (i = 0; i < BANDS; i++) {
696  workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
697  : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
698  }
699 
700  while (corrected < summer) {
701  if (highest <= -1.e20)
702  break;
703 
704  highest = -1.e20;
705 
706  for (i = 0; i < BANDS; i++) {
707  if (workT[i] > highest) {
708  highest = workT[i];
709  found_indx = i;
710  }
711  }
712 
713  if (highest > -1.e20) {
714  workT[found_indx] -= 2.0;
715  if (++(chctx->bitsBandT[found_indx]) == 6)
716  workT[found_indx] = -1.e20;
717 
718  for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
719  if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
720  chctx->CWlengthT[j]++;
721  corrected++;
722  }
723  }
724  }
725  }
726 }
727 
728 static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
729 {
730  int i;
731  float re, im;
732  float *dst1 = q->out_samples;
733  float *dst2 = q->out_samples + (COEFFS - 1);
734 
735  /* prerotation */
736  for (i = 0; i < COEFFS / 2; i++) {
737  q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
738  (q->pre_coef2[i] * chctx->CWdecoded[i * 2]);
739  q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
740  (q->pre_coef1[i] * chctx->CWdecoded[i * 2]);
741  }
742 
743  /* FFT */
744  q->fft.fft_permute(&q->fft, q->samples);
745  q->fft.fft_calc(&q->fft, q->samples);
746 
747  /* postrotation, window and reorder */
748  for (i = 0; i < COEFFS / 2; i++) {
749  re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
750  im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]);
751  *dst1 = (q->mdct_sine_window[COEFFS - 1 - i * 2] * chctx->last_fft_im[i])
752  + (q->mdct_sine_window[i * 2] * re);
753  *dst2 = (q->mdct_sine_window[i * 2] * chctx->last_fft_im[i])
754  - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re);
755  dst1 += 2;
756  dst2 -= 2;
757  chctx->last_fft_im[i] = im;
758  }
759 }
760 
762  int stream_format_code)
763 {
764  int i, j;
765  int middle_value, cw_len, max_size;
766  const float *quantizer;
767 
768  for (i = 0; i < BANDS; i++) {
769  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
770  chctx->CWdecoded[j] = 0;
771  cw_len = chctx->CWlengthT[j];
772 
773  if (cw_len <= 0 || chctx->skipFlags[j])
774  continue;
775 
776  max_size = 1 << cw_len;
777  middle_value = max_size >> 1;
778 
779  if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
780  return AVERROR_INVALIDDATA;
781 
782  if (cw_len >= 4) {
783  quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
784  if (chctx->codewords[j] >= middle_value)
785  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
786  else
787  chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
788  }else{
789  quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
790  if (chctx->codewords[j] >= middle_value)
791  chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
792  else
793  chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
794  }
795  }
796  }
797  return 0;
798 }
799 
800 
801 static void imc_get_coeffs(AVCodecContext *avctx,
802  IMCContext *q, IMCChannel *chctx)
803 {
804  int i, j, cw_len, cw;
805 
806  for (i = 0; i < BANDS; i++) {
807  if (!chctx->sumLenArr[i])
808  continue;
809  if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
810  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
811  cw_len = chctx->CWlengthT[j];
812  cw = 0;
813 
814  if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) {
815  if (get_bits_count(&q->gb) + cw_len > 512) {
816  av_log(avctx, AV_LOG_WARNING,
817  "Potential problem on band %i, coefficient %i"
818  ": cw_len=%i\n", i, j, cw_len);
819  } else
820  cw = get_bits(&q->gb, cw_len);
821  }
822 
823  chctx->codewords[j] = cw;
824  }
825  }
826  }
827 }
828 
830 {
831  int i, j;
832  int summer;
833 
834  for (i = 0; i < BANDS; i++) {
835  chctx->sumLenArr[i] = 0;
836  chctx->skipFlagRaw[i] = 0;
837  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
838  chctx->sumLenArr[i] += chctx->CWlengthT[j];
839  if (chctx->bandFlagsBuf[i])
840  if (((int)((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
841  chctx->skipFlagRaw[i] = 1;
842  }
843 
844  imc_get_skip_coeff(q, chctx);
845 
846  for (i = 0; i < BANDS; i++) {
847  chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
848  /* band has flag set and at least one coded coefficient */
849  if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
850  chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
851  q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
852  }
853  }
854 
855  /* calculate bits left, bits needed and adjust bit allocation */
856  summer = 0;
857 
858  for (i = 0; i < BANDS; i++) {
859  if (chctx->bandFlagsBuf[i]) {
860  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
861  if (chctx->skipFlags[j]) {
862  summer += chctx->CWlengthT[j];
863  chctx->CWlengthT[j] = 0;
864  }
865  }
866  summer -= chctx->skipFlagBits[i];
867  }
868  }
869  imc_adjust_bit_allocation(q, chctx, summer);
870 }
871 
872 static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
873 {
874  int stream_format_code;
875  int imc_hdr, i, j, ret;
876  int flag;
877  int bits;
878  int counter, bitscount;
879  IMCChannel *chctx = q->chctx + ch;
880 
881 
882  /* Check the frame header */
883  imc_hdr = get_bits(&q->gb, 9);
884  if (imc_hdr & 0x18) {
885  av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
886  av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
887  return AVERROR_INVALIDDATA;
888  }
889  stream_format_code = get_bits(&q->gb, 3);
890 
891  if (stream_format_code & 0x04)
892  chctx->decoder_reset = 1;
893 
894  if (chctx->decoder_reset) {
895  for (i = 0; i < BANDS; i++)
896  chctx->old_floor[i] = 1.0;
897  for (i = 0; i < COEFFS; i++)
898  chctx->CWdecoded[i] = 0;
899  chctx->decoder_reset = 0;
900  }
901 
902  flag = get_bits1(&q->gb);
903  if (stream_format_code & 0x1)
904  imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
905  else
906  imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
907 
908  if (stream_format_code & 0x1)
910  chctx->flcoeffs1, chctx->flcoeffs2);
911  else if (stream_format_code & 0x4)
913  chctx->flcoeffs1, chctx->flcoeffs2);
914  else
916  chctx->flcoeffs1, chctx->flcoeffs2);
917 
918  for(i=0; i<BANDS; i++) {
919  if(chctx->flcoeffs1[i] > INT_MAX) {
920  av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
921  return AVERROR_INVALIDDATA;
922  }
923  }
924 
925  memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
926 
927  counter = 0;
928  if (stream_format_code & 0x1) {
929  for (i = 0; i < BANDS; i++) {
930  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
931  chctx->bandFlagsBuf[i] = 0;
932  chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
933  chctx->flcoeffs5[i] = 1.0;
934  }
935  } else {
936  for (i = 0; i < BANDS; i++) {
937  if (chctx->levlCoeffBuf[i] == 16) {
938  chctx->bandWidthT[i] = 0;
939  counter++;
940  } else
941  chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
942  }
943 
944  memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
945  for (i = 0; i < BANDS - 1; i++)
946  if (chctx->bandWidthT[i])
947  chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
948 
949  imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
950  chctx->bandWidthT, chctx->flcoeffs3,
951  chctx->flcoeffs5);
952  }
953 
954  bitscount = 0;
955  /* first 4 bands will be assigned 5 bits per coefficient */
956  if (stream_format_code & 0x2) {
957  bitscount += 15;
958 
959  chctx->bitsBandT[0] = 5;
960  chctx->CWlengthT[0] = 5;
961  chctx->CWlengthT[1] = 5;
962  chctx->CWlengthT[2] = 5;
963  for (i = 1; i < 4; i++) {
964  if (stream_format_code & 0x1)
965  bits = 5;
966  else
967  bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
968  chctx->bitsBandT[i] = bits;
969  for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
970  chctx->CWlengthT[j] = bits;
971  bitscount += bits;
972  }
973  }
974  }
975  if (avctx->codec_id == AV_CODEC_ID_IAC) {
976  bitscount += !!chctx->bandWidthT[BANDS - 1];
977  if (!(stream_format_code & 0x2))
978  bitscount += 16;
979  }
980 
981  if ((ret = bit_allocation(q, chctx, stream_format_code,
982  512 - bitscount - get_bits_count(&q->gb),
983  flag)) < 0) {
984  av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
985  chctx->decoder_reset = 1;
986  return ret;
987  }
988 
989  if (stream_format_code & 0x1) {
990  for (i = 0; i < BANDS; i++)
991  chctx->skipFlags[i] = 0;
992  } else {
993  imc_refine_bit_allocation(q, chctx);
994  }
995 
996  for (i = 0; i < BANDS; i++) {
997  chctx->sumLenArr[i] = 0;
998 
999  for (j = band_tab[i]; j < band_tab[i + 1]; j++)
1000  if (!chctx->skipFlags[j])
1001  chctx->sumLenArr[i] += chctx->CWlengthT[j];
1002  }
1003 
1004  memset(chctx->codewords, 0, sizeof(chctx->codewords));
1005 
1006  imc_get_coeffs(avctx, q, chctx);
1007 
1008  if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
1009  av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
1010  chctx->decoder_reset = 1;
1011  return AVERROR_INVALIDDATA;
1012  }
1013 
1014  memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
1015 
1016  imc_imdct256(q, chctx, avctx->channels);
1017 
1018  return 0;
1019 }
1020 
1021 static int imc_decode_frame(AVCodecContext *avctx, void *data,
1022  int *got_frame_ptr, AVPacket *avpkt)
1023 {
1024  AVFrame *frame = data;
1025  const uint8_t *buf = avpkt->data;
1026  int buf_size = avpkt->size;
1027  int ret, i;
1028 
1029  IMCContext *q = avctx->priv_data;
1030 
1031  LOCAL_ALIGNED_16(uint16_t, buf16, [(IMC_BLOCK_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / 2]);
1032 
1033  q->avctx = avctx;
1034 
1035  if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
1036  av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
1037  return AVERROR_INVALIDDATA;
1038  }
1039 
1040  /* get output buffer */
1041  frame->nb_samples = COEFFS;
1042  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1043  return ret;
1044 
1045  for (i = 0; i < avctx->channels; i++) {
1046  q->out_samples = (float *)frame->extended_data[i];
1047 
1048  q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
1049 
1050  init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
1051 
1052  buf += IMC_BLOCK_SIZE;
1053 
1054  if ((ret = imc_decode_block(avctx, q, i)) < 0)
1055  return ret;
1056  }
1057 
1058  if (avctx->channels == 2) {
1059  q->butterflies_float((float *)frame->extended_data[0],
1060  (float *)frame->extended_data[1], COEFFS);
1061  }
1062 
1063  *got_frame_ptr = 1;
1064 
1065  return IMC_BLOCK_SIZE * avctx->channels;
1066 }
1067 
1069 {
1070  IMCContext *q = avctx->priv_data;
1071 
1072  ff_fft_end(&q->fft);
1073 
1074  return 0;
1075 }
1076 
1077 static av_cold void flush(AVCodecContext *avctx)
1078 {
1079  IMCContext *q = avctx->priv_data;
1080 
1081  q->chctx[0].decoder_reset =
1082  q->chctx[1].decoder_reset = 1;
1083 }
1084 
1085 #if CONFIG_IMC_DECODER
1086 const AVCodec ff_imc_decoder = {
1087  .name = "imc",
1088  .long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"),
1089  .type = AVMEDIA_TYPE_AUDIO,
1090  .id = AV_CODEC_ID_IMC,
1091  .priv_data_size = sizeof(IMCContext),
1092  .init = imc_decode_init,
1093  .close = imc_decode_close,
1095  .flush = flush,
1096  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1097  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1099  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1100 };
1101 #endif
1102 #if CONFIG_IAC_DECODER
1103 const AVCodec ff_iac_decoder = {
1104  .name = "iac",
1105  .long_name = NULL_IF_CONFIG_SMALL("IAC (Indeo Audio Coder)"),
1106  .type = AVMEDIA_TYPE_AUDIO,
1107  .id = AV_CODEC_ID_IAC,
1108  .priv_data_size = sizeof(IMCContext),
1109  .init = imc_decode_init,
1110  .close = imc_decode_close,
1112  .flush = flush,
1113  .capabilities = AV_CODEC_CAP_DR1,
1114  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1116  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1117 };
1118 #endif
ff_fft_init
#define ff_fft_init
Definition: fft.h:135
AVCodec
AVCodec.
Definition: codec.h:202
bswapdsp.h
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
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:108
level
uint8_t level
Definition: svq3.c:204
flush
static av_cold void flush(AVCodecContext *avctx)
Definition: imc.c:1077
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:70
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1043
mem_internal.h
IMCContext::coef0_pos
int coef0_pos
Definition: imc.c:106
imc_exp_tab
static const float imc_exp_tab[32]
Definition: imcdata.h:87
IMCChannel::flcoeffs3
float flcoeffs3[BANDS]
Definition: imc.c:62
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:992
imc_huffman_lens
static const uint8_t imc_huffman_lens[4][4][18]
Definition: imcdata.h:115
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
log2f
#define log2f(x)
Definition: libm.h:409
thread.h
IMCChannel::skipFlagCount
int skipFlagCount[BANDS]
skipped coefficients per band
Definition: imc.c:76
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:90
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:220
imc_quantizer2
static const float imc_quantizer2[2][56]
Definition: imcdata.h:66
IMCChannel::CWdecoded
float CWdecoded[COEFFS]
Definition: imc.c:66
IMCContext::cyclTab
int8_t cyclTab[32]
Definition: imc.c:108
im
float im
Definition: fft.c:78
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
IMCContext::post_cos
float post_cos[COEFFS]
Definition: imc.c:91
IMCContext::post_sin
float post_sin[COEFFS]
Definition: imc.c:92
iac_generate_tabs
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
Definition: imc.c:126
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
data
const char data[16]
Definition: mxf.c:143
COEFFS
#define COEFFS
Definition: imc.c:56
IMCChannel::old_floor
float old_floor[BANDS]
Definition: imc.c:59
get_vlc2
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:798
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:450
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:660
imc_calculate_coeffs
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
Definition: imc.c:281
imc_read_level_coeffs_raw
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:364
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
init
static int init
Definition: av_tx.c:47
imc_read_level_coeffs
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
Definition: imc.c:336
IMCChannel::flcoeffs4
float flcoeffs4[BANDS]
Definition: imc.c:63
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:380
IMCChannel::skipFlagRaw
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
Definition: imc.c:74
VLC_TYPE
#define VLC_TYPE
Definition: vlc.h:24
cyclTab
static const int8_t cyclTab[32]
Definition: imcdata.h:36
IMCContext::butterflies_float
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Definition: imc.c:101
imc_init_static
static av_cold void imc_init_static(void)
Definition: imc.c:177
GetBitContext
Definition: get_bits.h:62
imc_imdct256
static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
Definition: imc.c:728
imc_weights2
static const float imc_weights2[31]
Definition: imcdata.h:53
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:463
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1388
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:91
ff_init_vlc_from_lengths
int ff_init_vlc_from_lengths(VLC *vlc_arg, 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: bitstream.c:381
IMCContext::sqrt_tab
float sqrt_tab[30]
Definition: imc.c:97
IMC_BLOCK_SIZE
#define IMC_BLOCK_SIZE
Definition: imc.c:53
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
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
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
imc_decode_close
static av_cold int imc_decode_close(AVCodecContext *avctx)
Definition: imc.c:1068
s
#define s(width, name)
Definition: cbs_vp9.c:257
IMCChannel
Definition: imc.c:58
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_fft_end
#define ff_fft_end
Definition: fft.h:136
bits
uint8_t bits
Definition: vp3data.h:141
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
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:630
ff_iac_decoder
const AVCodec ff_iac_decoder
channels
channels
Definition: aptx.h:33
IMCChannel::flcoeffs5
float flcoeffs5[BANDS]
Definition: imc.c:64
get_bits.h
BswapDSPContext::bswap16_buf
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
Definition: bswapdsp.h:26
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:393
IMCChannel::bandFlagsBuf
int bandFlagsBuf[BANDS]
flags for each band
Definition: imc.c:72
imc_decode_level_coefficients2
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:409
if
if(ret)
Definition: filter_design.txt:179
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:173
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:100
IMCChannel::flcoeffs6
float flcoeffs6[BANDS]
Definition: imc.c:65
av_clipf
#define av_clipf
Definition: common.h:144
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:499
band_tab
static const uint16_t band_tab[33]
Definition: imcdata.h:29
huffman_vlc
static VLC huffman_vlc[4][4]
Definition: imc.c:114
IMCContext::weights1
float weights1[31]
Definition: imc.c:109
IMCContext::samples
FFTComplex samples[COEFFS/2]
Definition: imc.c:103
AVOnce
#define AVOnce
Definition: thread.h:172
cyclTab2
static const int8_t cyclTab2[32]
Definition: imcdata.h:42
float_dsp.h
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
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:109
IMCChannel::bandWidthT
int bandWidthT[BANDS]
codewords per band
Definition: imc.c:68
IMCChannel::last_fft_im
float last_fft_im[COEFFS]
Definition: imc.c:80
VLC::table_allocated
int table_allocated
Definition: vlc.h:29
imc_decode_level_coefficients_raw
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
Definition: imc.c:429
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:117
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1652
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:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
powf
#define powf(x, y)
Definition: libm.h:50
vlc_tables
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]
Definition: imc.c:119
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1000
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
imc_quantizer1
static const float imc_quantizer1[4][8]
Definition: imcdata.h:59
FFTContext::fft_permute
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
Definition: fft.h:88
FFTComplex::im
FFTSample im
Definition: avfft.h:38
AVFloatDSPContext
Definition: float_dsp.h:24
FFTComplex::re
FFTSample re
Definition: avfft.h:38
ff_imc_decoder
const AVCodec ff_imc_decoder
FFTContext::fft_calc
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
Definition: fft.h:93
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
M_PI
#define M_PI
Definition: mathematics.h:52
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
ff_sine_window_init
void ff_sine_window_init(float *window, int n)
Generate a sine window.
Definition: sinewin_tablegen.h:59
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:993
flag
#define flag(name)
Definition: cbs_av1.c:553
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:116
FFTContext
Definition: fft.h:75
imc_refine_bit_allocation
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
Definition: imc.c:829
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
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:454
internal.h
inverse_quant_coeff
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
Definition: imc.c:761
IMCChannel::bitsBandT
int bitsBandT[BANDS]
how many bits per codeword in band
Definition: imc.c:69
BANDS
#define BANDS
Definition: imc.c:55
xTab
static const float xTab[14]
Definition: imcdata.h:84
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
imc_decode_frame
static int imc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: imc.c:1021
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:209
len
int len
Definition: vorbis_enc_data.h:426
imc_decode_init
static av_cold int imc_decode_init(AVCodecContext *avctx)
Definition: imc.c:193
IMCChannel::levlCoeffBuf
int levlCoeffBuf[BANDS]
Definition: imc.c:71
IMCContext
Definition: imc.c:85
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:128
AV_CODEC_ID_IAC
@ AV_CODEC_ID_IAC
Definition: codec_id.h:481
ret
ret
Definition: filter_design.txt:187
IMCContext::pre_coef2
float pre_coef2[COEFFS]
Definition: imc.c:94
INIT_VLC_STATIC_OVERLONG
#define INIT_VLC_STATIC_OVERLONG
Definition: vlc.h:96
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:412
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
fft.h
AVCodecContext
main external API structure.
Definition: avcodec.h:383
IMCContext::out_samples
float * out_samples
Definition: imc.c:104
IMC_VLC_BITS
#define IMC_VLC_BITS
Definition: imc.c:116
channel_layout.h
t2
#define t2
Definition: regdef.h:30
IMCChannel::skipFlagBits
int skipFlagBits[BANDS]
bits used to code skip flags
Definition: imc.c:75
IMCContext::weights2
float weights2[31]
Definition: imc.c:109
VLC
Definition: vlc.h:26
IMCContext::avctx
AVCodecContext * avctx
Definition: imc.c:111
IMCChannel::flcoeffs2
float flcoeffs2[BANDS]
Definition: imc.c:61
IMCContext::fft
FFTContext fft
Definition: imc.c:102
imcdata.h
tf
#define tf
Definition: regdef.h:73
ffmath.h
IMCChannel::skipFlags
int skipFlags[COEFFS]
skip coefficient decoding or not
Definition: imc.c:77
IMCContext::chctx
IMCChannel chctx[2]
Definition: imc.c:86
VLC::table_size
int table_size
Definition: vlc.h:29
imc_decode_block
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
Definition: imc.c:872
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:272
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
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:375
freq2bark
static double freq2bark(double freq)
Definition: imc.c:121
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
IMCContext::mdct_sine_window
float mdct_sine_window[COEFFS]
MDCT tables.
Definition: imc.c:90
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
IMCContext::gb
GetBitContext gb
Definition: imc.c:98
BswapDSPContext
Definition: bswapdsp.h:24
IMCChannel::decoder_reset
int decoder_reset
Definition: imc.c:82
imc_get_coeffs
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
Definition: imc.c:801
IMCContext::pre_coef1
float pre_coef1[COEFFS]
Definition: imc.c:93
VLC::table
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
FFTComplex
Definition: avfft.h:37
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:686
IMCChannel::flcoeffs1
float flcoeffs1[BANDS]
Definition: imc.c:60
re
float re
Definition: fft.c:78
IMCChannel::codewords
int codewords[COEFFS]
raw codewords read from bitstream
Definition: imc.c:78
IMCChannel::sumLenArr
int sumLenArr[BANDS]
bits for all coeffs in band
Definition: imc.c:73