FFmpeg
atrac3.c
Go to the documentation of this file.
1 /*
2  * ATRAC3 compatible decoder
3  * Copyright (c) 2006-2008 Maxim Poliakovski
4  * Copyright (c) 2006-2008 Benjamin Larsson
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * ATRAC3 compatible decoder.
26  * This decoder handles Sony's ATRAC3 data.
27  *
28  * Container formats used to store ATRAC3 data:
29  * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3).
30  *
31  * To use this decoder, a calling application must supply the extradata
32  * bytes provided in the containers above.
33  */
34 
35 #include <math.h>
36 #include <stddef.h>
37 
38 #include "libavutil/attributes.h"
39 #include "libavutil/float_dsp.h"
40 #include "libavutil/libm.h"
41 #include "libavutil/mem.h"
42 #include "libavutil/mem_internal.h"
43 #include "libavutil/thread.h"
44 #include "libavutil/tx.h"
45 
46 #include "avcodec.h"
47 #include "bytestream.h"
48 #include "codec_internal.h"
49 #include "decode.h"
50 #include "get_bits.h"
51 
52 #include "atrac.h"
53 #include "atrac3data.h"
54 
55 #define MIN_CHANNELS 1
56 #define MAX_CHANNELS 8
57 #define MAX_JS_PAIRS 8 / 2
58 
59 #define JOINT_STEREO 0x12
60 #define SINGLE 0x2
61 
62 #define SAMPLES_PER_FRAME 1024
63 #define MDCT_SIZE 512
64 
65 #define ATRAC3_VLC_BITS 8
66 
67 typedef struct GainBlock {
69 } GainBlock;
70 
71 typedef struct TonalComponent {
72  int pos;
73  int num_coefs;
74  float coef[8];
76 
77 typedef struct ChannelUnit {
84 
87 
88  float delay_buf1[46]; ///<qmf delay buffers
89  float delay_buf2[46];
90  float delay_buf3[46];
91 } ChannelUnit;
92 
93 typedef struct ATRAC3Context {
95  //@{
96  /** stream data */
98 
100  //@}
101  //@{
102  /** joint-stereo related variables */
107  //@}
108  //@{
109  /** data buffers */
111  float temp_buf[1070];
112  //@}
113  //@{
114  /** extradata */
116  //@}
117 
121  void (*vector_fmul)(float *dst, const float *src0, const float *src1,
122  int len);
123 } ATRAC3Context;
124 
128 
129 /**
130  * Regular 512 points IMDCT without overlapping, with the exception of the
131  * swapping of odd bands caused by the reverse spectra of the QMF.
132  *
133  * @param odd_band 1 if the band is an odd band
134  */
135 static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
136 {
137  int i;
138 
139  if (odd_band) {
140  /**
141  * Reverse the odd bands before IMDCT, this is an effect of the QMF
142  * transform or it gives better compression to do it this way.
143  * FIXME: It should be possible to handle this in imdct_calc
144  * for that to happen a modification of the prerotation step of
145  * all SIMD code and C code is needed.
146  * Or fix the functions before so they generate a pre reversed spectrum.
147  */
148  for (i = 0; i < 128; i++)
149  FFSWAP(float, input[i], input[255 - i]);
150  }
151 
152  q->mdct_fn(q->mdct_ctx, output, input, sizeof(float));
153 
154  /* Perform windowing on the output. */
156 }
157 
158 /*
159  * indata descrambling, only used for data coming from the rm container
160  */
161 static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
162 {
163  int i, off;
164  uint32_t c;
165  const uint32_t *buf;
166  uint32_t *output = (uint32_t *)out;
167 
168  off = (intptr_t)input & 3;
169  buf = (const uint32_t *)(input - off);
170  if (off)
171  c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
172  else
173  c = av_be2ne32(0x537F6103U);
174  bytes += 3 + off;
175  for (i = 0; i < bytes / 4; i++)
176  output[i] = c ^ buf[i];
177 
178  if (off)
179  avpriv_request_sample(NULL, "Offset of %d", off);
180 
181  return off;
182 }
183 
184 static av_cold void init_imdct_window(void)
185 {
186  int i, j;
187 
188  /* generate the mdct window, for details see
189  * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */
190  for (i = 0, j = 255; i < 128; i++, j--) {
191  float wi = sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
192  float wj = sin(((j + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
193  float w = 0.5 * (wi * wi + wj * wj);
194  mdct_window[i] = mdct_window[511 - i] = wi / w;
195  mdct_window[j] = mdct_window[511 - j] = wj / w;
196  }
197 }
198 
200 {
201  ATRAC3Context *q = avctx->priv_data;
202 
203  av_freep(&q->units);
205 
206  av_tx_uninit(&q->mdct_ctx);
207 
208  return 0;
209 }
210 
211 /**
212  * Mantissa decoding
213  *
214  * @param selector which table the output values are coded with
215  * @param coding_flag constant length coding or variable length coding
216  * @param mantissas mantissa output table
217  * @param num_codes number of values to get
218  */
219 static void read_quant_spectral_coeffs(GetBitContext *gb, int selector,
220  int coding_flag, int *mantissas,
221  int num_codes)
222 {
223  int i, code, huff_symb;
224 
225  if (selector == 1)
226  num_codes /= 2;
227 
228  if (coding_flag != 0) {
229  /* constant length coding (CLC) */
230  int num_bits = clc_length_tab[selector];
231 
232  if (selector > 1) {
233  for (i = 0; i < num_codes; i++) {
234  if (num_bits)
235  code = get_sbits(gb, num_bits);
236  else
237  code = 0;
238  mantissas[i] = code;
239  }
240  } else {
241  for (i = 0; i < num_codes; i++) {
242  if (num_bits)
243  code = get_bits(gb, num_bits); // num_bits is always 4 in this case
244  else
245  code = 0;
246  mantissas[i * 2 ] = mantissa_clc_tab[code >> 2];
247  mantissas[i * 2 + 1] = mantissa_clc_tab[code & 3];
248  }
249  }
250  } else {
251  /* variable length coding (VLC) */
252  if (selector != 1) {
253  for (i = 0; i < num_codes; i++) {
254  mantissas[i] = get_vlc2(gb, spectral_coeff_tab[selector-1].table,
255  ATRAC3_VLC_BITS, 1);
256  }
257  } else {
258  for (i = 0; i < num_codes; i++) {
259  huff_symb = get_vlc2(gb, spectral_coeff_tab[selector - 1].table,
260  ATRAC3_VLC_BITS, 1);
261  mantissas[i * 2 ] = mantissa_vlc_tab[huff_symb * 2 ];
262  mantissas[i * 2 + 1] = mantissa_vlc_tab[huff_symb * 2 + 1];
263  }
264  }
265  }
266 }
267 
268 /**
269  * Restore the quantized band spectrum coefficients
270  *
271  * @return subband count, fix for broken specification/files
272  */
273 static int decode_spectrum(GetBitContext *gb, float *output)
274 {
275  int num_subbands, coding_mode, i, j, first, last, subband_size;
276  int subband_vlc_index[32], sf_index[32];
277  int mantissas[128];
278  float scale_factor;
279 
280  num_subbands = get_bits(gb, 5); // number of coded subbands
281  coding_mode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
282 
283  /* get the VLC selector table for the subbands, 0 means not coded */
284  for (i = 0; i <= num_subbands; i++)
285  subband_vlc_index[i] = get_bits(gb, 3);
286 
287  /* read the scale factor indexes from the stream */
288  for (i = 0; i <= num_subbands; i++) {
289  if (subband_vlc_index[i] != 0)
290  sf_index[i] = get_bits(gb, 6);
291  }
292 
293  for (i = 0; i <= num_subbands; i++) {
294  first = subband_tab[i ];
295  last = subband_tab[i + 1];
296 
297  subband_size = last - first;
298 
299  if (subband_vlc_index[i] != 0) {
300  /* decode spectral coefficients for this subband */
301  /* TODO: This can be done faster is several blocks share the
302  * same VLC selector (subband_vlc_index) */
303  read_quant_spectral_coeffs(gb, subband_vlc_index[i], coding_mode,
304  mantissas, subband_size);
305 
306  /* decode the scale factor for this subband */
307  scale_factor = ff_atrac_sf_table[sf_index[i]] *
308  inv_max_quant[subband_vlc_index[i]];
309 
310  /* inverse quantize the coefficients */
311  for (j = 0; first < last; first++, j++)
312  output[first] = mantissas[j] * scale_factor;
313  } else {
314  /* this subband was not coded, so zero the entire subband */
315  memset(output + first, 0, subband_size * sizeof(*output));
316  }
317  }
318 
319  /* clear the subbands that were not coded */
320  first = subband_tab[i];
321  memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(*output));
322  return num_subbands;
323 }
324 
325 /**
326  * Restore the quantized tonal components
327  *
328  * @param components tonal components
329  * @param num_bands number of coded bands
330  */
332  TonalComponent *components, int num_bands)
333 {
334  int i, b, c, m;
335  int nb_components, coding_mode_selector, coding_mode;
336  int band_flags[4], mantissa[8];
337  int component_count = 0;
338 
339  nb_components = get_bits(gb, 5);
340 
341  /* no tonal components */
342  if (nb_components == 0)
343  return 0;
344 
345  coding_mode_selector = get_bits(gb, 2);
346  if (coding_mode_selector == 2)
347  return AVERROR_INVALIDDATA;
348 
349  coding_mode = coding_mode_selector & 1;
350 
351  for (i = 0; i < nb_components; i++) {
352  int coded_values_per_component, quant_step_index;
353 
354  for (b = 0; b <= num_bands; b++)
355  band_flags[b] = get_bits1(gb);
356 
357  coded_values_per_component = get_bits(gb, 3);
358 
359  quant_step_index = get_bits(gb, 3);
360  if (quant_step_index <= 1)
361  return AVERROR_INVALIDDATA;
362 
363  if (coding_mode_selector == 3)
364  coding_mode = get_bits1(gb);
365 
366  for (b = 0; b < (num_bands + 1) * 4; b++) {
367  int coded_components;
368 
369  if (band_flags[b >> 2] == 0)
370  continue;
371 
372  coded_components = get_bits(gb, 3);
373 
374  for (c = 0; c < coded_components; c++) {
375  TonalComponent *cmp = &components[component_count];
376  int sf_index, coded_values, max_coded_values;
377  float scale_factor;
378 
379  sf_index = get_bits(gb, 6);
380  if (component_count >= 64)
381  return AVERROR_INVALIDDATA;
382 
383  cmp->pos = b * 64 + get_bits(gb, 6);
384 
385  max_coded_values = SAMPLES_PER_FRAME - cmp->pos;
386  coded_values = coded_values_per_component + 1;
387  coded_values = FFMIN(max_coded_values, coded_values);
388 
389  scale_factor = ff_atrac_sf_table[sf_index] *
390  inv_max_quant[quant_step_index];
391 
392  read_quant_spectral_coeffs(gb, quant_step_index, coding_mode,
393  mantissa, coded_values);
394 
395  cmp->num_coefs = coded_values;
396 
397  /* inverse quant */
398  for (m = 0; m < coded_values; m++)
399  cmp->coef[m] = mantissa[m] * scale_factor;
400 
401  component_count++;
402  }
403  }
404  }
405 
406  return component_count;
407 }
408 
409 /**
410  * Decode gain parameters for the coded bands
411  *
412  * @param block the gainblock for the current band
413  * @param num_bands amount of coded bands
414  */
416  int num_bands)
417 {
418  int b, j;
419  int *level, *loc;
420 
421  AtracGainInfo *gain = block->g_block;
422 
423  for (b = 0; b <= num_bands; b++) {
424  gain[b].num_points = get_bits(gb, 3);
425  level = gain[b].lev_code;
426  loc = gain[b].loc_code;
427 
428  for (j = 0; j < gain[b].num_points; j++) {
429  level[j] = get_bits(gb, 4);
430  loc[j] = get_bits(gb, 5);
431  if (j && loc[j] <= loc[j - 1])
432  return AVERROR_INVALIDDATA;
433  }
434  }
435 
436  /* Clear the unused blocks. */
437  for (; b < 4 ; b++)
438  gain[b].num_points = 0;
439 
440  return 0;
441 }
442 
443 /**
444  * Combine the tonal band spectrum and regular band spectrum
445  *
446  * @param spectrum output spectrum buffer
447  * @param num_components number of tonal components
448  * @param components tonal components for this band
449  * @return position of the last tonal coefficient
450  */
451 static int add_tonal_components(float *spectrum, int num_components,
452  TonalComponent *components)
453 {
454  int i, j, last_pos = -1;
455  float *input, *output;
456 
457  for (i = 0; i < num_components; i++) {
458  last_pos = FFMAX(components[i].pos + components[i].num_coefs, last_pos);
459  input = components[i].coef;
460  output = &spectrum[components[i].pos];
461 
462  for (j = 0; j < components[i].num_coefs; j++)
463  output[j] += input[j];
464  }
465 
466  return last_pos;
467 }
468 
469 #define INTERPOLATE(old, new, nsample) \
470  ((old) + (nsample) * 0.125 * ((new) - (old)))
471 
472 static void reverse_matrixing(float *su1, float *su2, int *prev_code,
473  int *curr_code)
474 {
475  int i, nsample, band;
476  float mc1_l, mc1_r, mc2_l, mc2_r;
477 
478  for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
479  int s1 = prev_code[i];
480  int s2 = curr_code[i];
481  nsample = band;
482 
483  if (s1 != s2) {
484  /* Selector value changed, interpolation needed. */
485  mc1_l = matrix_coeffs[s1 * 2 ];
486  mc1_r = matrix_coeffs[s1 * 2 + 1];
487  mc2_l = matrix_coeffs[s2 * 2 ];
488  mc2_r = matrix_coeffs[s2 * 2 + 1];
489 
490  /* Interpolation is done over the first eight samples. */
491  for (; nsample < band + 8; nsample++) {
492  float c1 = su1[nsample];
493  float c2 = su2[nsample];
494  c2 = c1 * INTERPOLATE(mc1_l, mc2_l, nsample - band) +
495  c2 * INTERPOLATE(mc1_r, mc2_r, nsample - band);
496  su1[nsample] = c2;
497  su2[nsample] = c1 * 2.0 - c2;
498  }
499  }
500 
501  /* Apply the matrix without interpolation. */
502  switch (s2) {
503  case 0: /* M/S decoding */
504  for (; nsample < band + 256; nsample++) {
505  float c1 = su1[nsample];
506  float c2 = su2[nsample];
507  su1[nsample] = c2 * 2.0;
508  su2[nsample] = (c1 - c2) * 2.0;
509  }
510  break;
511  case 1:
512  for (; nsample < band + 256; nsample++) {
513  float c1 = su1[nsample];
514  float c2 = su2[nsample];
515  su1[nsample] = (c1 + c2) * 2.0;
516  su2[nsample] = c2 * -2.0;
517  }
518  break;
519  case 2:
520  case 3:
521  for (; nsample < band + 256; nsample++) {
522  float c1 = su1[nsample];
523  float c2 = su2[nsample];
524  su1[nsample] = c1 + c2;
525  su2[nsample] = c1 - c2;
526  }
527  break;
528  default:
529  av_assert1(0);
530  }
531  }
532 }
533 
534 static void get_channel_weights(int index, int flag, float ch[2])
535 {
536  if (index == 7) {
537  ch[0] = 1.0;
538  ch[1] = 1.0;
539  } else {
540  ch[0] = (index & 7) / 7.0;
541  ch[1] = sqrt(2 - ch[0] * ch[0]);
542  if (flag)
543  FFSWAP(float, ch[0], ch[1]);
544  }
545 }
546 
547 static void channel_weighting(float *su1, float *su2, int *p3)
548 {
549  int band, nsample;
550  /* w[x][y] y=0 is left y=1 is right */
551  float w[2][2];
552 
553  if (p3[1] != 7 || p3[3] != 7) {
554  get_channel_weights(p3[1], p3[0], w[0]);
555  get_channel_weights(p3[3], p3[2], w[1]);
556 
557  for (band = 256; band < 4 * 256; band += 256) {
558  for (nsample = band; nsample < band + 8; nsample++) {
559  su1[nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample - band);
560  su2[nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample - band);
561  }
562  for(; nsample < band + 256; nsample++) {
563  su1[nsample] *= w[1][0];
564  su2[nsample] *= w[1][1];
565  }
566  }
567  }
568 }
569 
570 /**
571  * Decode a Sound Unit
572  *
573  * @param snd the channel unit to be used
574  * @param output the decoded samples before IQMF in float representation
575  * @param channel_num channel number
576  * @param coding_mode the coding mode (JOINT_STEREO or single channels)
577  */
579  ChannelUnit *snd, float *output,
580  int channel_num, int coding_mode)
581 {
582  int band, ret, num_subbands, last_tonal, num_bands;
583  GainBlock *gain1 = &snd->gain_block[ snd->gc_blk_switch];
584  GainBlock *gain2 = &snd->gain_block[1 - snd->gc_blk_switch];
585 
586  if (coding_mode == JOINT_STEREO && (channel_num % 2) == 1) {
587  if (get_bits(gb, 2) != 3) {
588  av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
589  return AVERROR_INVALIDDATA;
590  }
591  } else {
592  if (get_bits(gb, 6) != 0x28) {
593  av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n");
594  return AVERROR_INVALIDDATA;
595  }
596  }
597 
598  /* number of coded QMF bands */
599  snd->bands_coded = get_bits(gb, 2);
600 
601  ret = decode_gain_control(gb, gain2, snd->bands_coded);
602  if (ret)
603  return ret;
604 
606  snd->bands_coded);
607  if (snd->num_components < 0)
608  return snd->num_components;
609 
610  num_subbands = decode_spectrum(gb, snd->spectrum);
611 
612  /* Merge the decoded spectrum and tonal components. */
613  last_tonal = add_tonal_components(snd->spectrum, snd->num_components,
614  snd->components);
615 
616 
617  /* calculate number of used MLT/QMF bands according to the amount of coded
618  spectral lines */
619  num_bands = (subband_tab[num_subbands] - 1) >> 8;
620  if (last_tonal >= 0)
621  num_bands = FFMAX((last_tonal + 256) >> 8, num_bands);
622 
623 
624  /* Reconstruct time domain samples. */
625  for (band = 0; band < 4; band++) {
626  /* Perform the IMDCT step without overlapping. */
627  if (band <= num_bands)
628  imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1);
629  else
630  memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf));
631 
632  /* gain compensation and overlapping */
634  &snd->prev_frame[band * 256],
635  &gain1->g_block[band], &gain2->g_block[band],
636  256, &output[band * 256]);
637  }
638 
639  /* Swap the gain control buffers for the next frame. */
640  snd->gc_blk_switch ^= 1;
641 
642  return 0;
643 }
644 
645 static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
646  float **out_samples)
647 {
648  ATRAC3Context *q = avctx->priv_data;
649  int ret, i, ch;
650  uint8_t *ptr1;
651  int channels = avctx->ch_layout.nb_channels;
652 
653  if (q->coding_mode == JOINT_STEREO) {
654  /* channel coupling mode */
655 
656  /* Decode sound unit pairs (channels are expected to be even).
657  * Multichannel joint stereo interleaves pairs (6ch: 2ch + 2ch + 2ch) */
658  const uint8_t *js_databuf;
659  int js_pair, js_block_align;
660 
661  js_block_align = (avctx->block_align / channels) * 2; /* block pair */
662 
663  for (ch = 0; ch < channels; ch = ch + 2) {
664  js_pair = ch/2;
665  js_databuf = databuf + js_pair * js_block_align; /* align to current pair */
666 
667  /* Set the bitstream reader at the start of first channel sound unit. */
668  init_get_bits(&q->gb,
669  js_databuf, js_block_align * 8);
670 
671  /* decode Sound Unit 1 */
672  ret = decode_channel_sound_unit(q, &q->gb, &q->units[ch],
673  out_samples[ch], ch, JOINT_STEREO);
674  if (ret != 0)
675  return ret;
676 
677  /* Framedata of the su2 in the joint-stereo mode is encoded in
678  * reverse byte order so we need to swap it first. */
679  if (js_databuf == q->decoded_bytes_buffer) {
680  uint8_t *ptr2 = q->decoded_bytes_buffer + js_block_align - 1;
681  ptr1 = q->decoded_bytes_buffer;
682  for (i = 0; i < js_block_align / 2; i++, ptr1++, ptr2--)
683  FFSWAP(uint8_t, *ptr1, *ptr2);
684  } else {
685  const uint8_t *ptr2 = js_databuf + js_block_align - 1;
686  for (i = 0; i < js_block_align; i++)
687  q->decoded_bytes_buffer[i] = *ptr2--;
688  }
689 
690  /* Skip the sync codes (0xF8). */
691  ptr1 = q->decoded_bytes_buffer;
692  for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
693  if (i >= js_block_align)
694  return AVERROR_INVALIDDATA;
695  }
696 
697 
698  /* set the bitstream reader at the start of the second Sound Unit */
699  ret = init_get_bits8(&q->gb,
700  ptr1, q->decoded_bytes_buffer + js_block_align - ptr1);
701  if (ret < 0)
702  return ret;
703 
704  /* Fill the Weighting coeffs delay buffer */
705  memmove(q->weighting_delay[js_pair], &q->weighting_delay[js_pair][2],
706  4 * sizeof(*q->weighting_delay[js_pair]));
707  q->weighting_delay[js_pair][4] = get_bits1(&q->gb);
708  q->weighting_delay[js_pair][5] = get_bits(&q->gb, 3);
709 
710  for (i = 0; i < 4; i++) {
711  q->matrix_coeff_index_prev[js_pair][i] = q->matrix_coeff_index_now[js_pair][i];
712  q->matrix_coeff_index_now[js_pair][i] = q->matrix_coeff_index_next[js_pair][i];
713  q->matrix_coeff_index_next[js_pair][i] = get_bits(&q->gb, 2);
714  }
715 
716  /* Decode Sound Unit 2. */
717  ret = decode_channel_sound_unit(q, &q->gb, &q->units[ch+1],
718  out_samples[ch+1], ch+1, JOINT_STEREO);
719  if (ret != 0)
720  return ret;
721 
722  /* Reconstruct the channel coefficients. */
723  reverse_matrixing(out_samples[ch], out_samples[ch+1],
724  q->matrix_coeff_index_prev[js_pair],
725  q->matrix_coeff_index_now[js_pair]);
726 
727  channel_weighting(out_samples[ch], out_samples[ch+1], q->weighting_delay[js_pair]);
728  }
729  } else {
730  /* single channels */
731  /* Decode the channel sound units. */
732  for (i = 0; i < channels; i++) {
733  /* Set the bitstream reader at the start of a channel sound unit. */
734  init_get_bits(&q->gb,
735  databuf + i * avctx->block_align / channels,
736  avctx->block_align * 8 / channels);
737 
738  ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
739  out_samples[i], i, q->coding_mode);
740  if (ret != 0)
741  return ret;
742  }
743  }
744 
745  /* Apply the iQMF synthesis filter. */
746  for (i = 0; i < channels; i++) {
747  float *p1 = out_samples[i];
748  float *p2 = p1 + 256;
749  float *p3 = p2 + 256;
750  float *p4 = p3 + 256;
751  ff_atrac_iqmf(p1, p2, 256, p1, q->units[i].delay_buf1, q->temp_buf);
752  ff_atrac_iqmf(p4, p3, 256, p3, q->units[i].delay_buf2, q->temp_buf);
753  ff_atrac_iqmf(p1, p3, 512, p1, q->units[i].delay_buf3, q->temp_buf);
754  }
755 
756  return 0;
757 }
758 
759 static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
760  int size, float **out_samples)
761 {
762  ATRAC3Context *q = avctx->priv_data;
763  int channels = avctx->ch_layout.nb_channels;
764  int ret, i;
765 
766  /* Set the bitstream reader at the start of a channel sound unit. */
767  init_get_bits(&q->gb, databuf, size * 8);
768  /* single channels */
769  /* Decode the channel sound units. */
770  for (i = 0; i < channels; i++) {
771  ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
772  out_samples[i], i, q->coding_mode);
773  if (ret != 0)
774  return ret;
775  while (i < channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) {
776  skip_bits(&q->gb, 1);
777  }
778  }
779 
780  /* Apply the iQMF synthesis filter. */
781  for (i = 0; i < channels; i++) {
782  float *p1 = out_samples[i];
783  float *p2 = p1 + 256;
784  float *p3 = p2 + 256;
785  float *p4 = p3 + 256;
786  ff_atrac_iqmf(p1, p2, 256, p1, q->units[i].delay_buf1, q->temp_buf);
787  ff_atrac_iqmf(p4, p3, 256, p3, q->units[i].delay_buf2, q->temp_buf);
788  ff_atrac_iqmf(p1, p3, 512, p1, q->units[i].delay_buf3, q->temp_buf);
789  }
790 
791  return 0;
792 }
793 
795  int *got_frame_ptr, AVPacket *avpkt)
796 {
797  const uint8_t *buf = avpkt->data;
798  int buf_size = avpkt->size;
799  ATRAC3Context *q = avctx->priv_data;
800  int ret;
801  const uint8_t *databuf;
802 
803  if (buf_size < avctx->block_align) {
804  av_log(avctx, AV_LOG_ERROR,
805  "Frame too small (%d bytes). Truncated file?\n", buf_size);
806  return AVERROR_INVALIDDATA;
807  }
808 
809  /* get output buffer */
810  frame->nb_samples = SAMPLES_PER_FRAME;
811  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
812  return ret;
813 
814  /* Check if we need to descramble and what buffer to pass on. */
815  if (q->scrambled_stream) {
817  databuf = q->decoded_bytes_buffer;
818  } else {
819  databuf = buf;
820  }
821 
822  ret = decode_frame(avctx, databuf, (float **)frame->extended_data);
823  if (ret) {
824  av_log(avctx, AV_LOG_ERROR, "Frame decoding error!\n");
825  return ret;
826  }
827 
828  *got_frame_ptr = 1;
829 
830  return avctx->block_align;
831 }
832 
834  int *got_frame_ptr, AVPacket *avpkt)
835 {
836  int ret;
837 
838  frame->nb_samples = SAMPLES_PER_FRAME;
839  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
840  return ret;
841 
842  ret = al_decode_frame(avctx, avpkt->data, avpkt->size,
843  (float **)frame->extended_data);
844  if (ret) {
845  av_log(avctx, AV_LOG_ERROR, "Frame decoding error!\n");
846  return ret;
847  }
848 
849  *got_frame_ptr = 1;
850 
851  return avpkt->size;
852 }
853 
855 {
857  const uint8_t (*hufftabs)[2] = atrac3_hufftabs;
858  int i;
859 
862 
863  /* Initialize the VLC tables. */
864  for (i = 0; i < 7; i++) {
868  &hufftabs[0][1], 2,
869  &hufftabs[0][0], 2, 1,
870  -31, VLC_INIT_USE_STATIC, NULL);
871  hufftabs += huff_tab_sizes[i];
872  table += 256;
873  }
874 }
875 
877 {
878  static AVOnce init_static_once = AV_ONCE_INIT;
879  int i, js_pair, ret;
880  int version, delay, samples_per_frame, frame_factor;
881  const uint8_t *edata_ptr = avctx->extradata;
882  ATRAC3Context *q = avctx->priv_data;
883  AVFloatDSPContext *fdsp;
884  float scale = 1.0 / 32768;
885  int channels = avctx->ch_layout.nb_channels;
886 
888  av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
889  return AVERROR(EINVAL);
890  }
891 
892  /* Take care of the codec-specific extradata. */
893  if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) {
894  version = 4;
895  samples_per_frame = SAMPLES_PER_FRAME * channels;
896  delay = 0x88E;
897  q->coding_mode = SINGLE;
898  } else if (avctx->extradata_size == 14) {
899  /* Parse the extradata, WAV format */
900  av_log(avctx, AV_LOG_DEBUG, "[0-1] %d\n",
901  bytestream_get_le16(&edata_ptr)); // Unknown value always 1
902  edata_ptr += 4; // samples per channel
903  q->coding_mode = bytestream_get_le16(&edata_ptr);
904  av_log(avctx, AV_LOG_DEBUG,"[8-9] %d\n",
905  bytestream_get_le16(&edata_ptr)); //Dupe of coding mode
906  frame_factor = bytestream_get_le16(&edata_ptr); // Unknown always 1
907  av_log(avctx, AV_LOG_DEBUG,"[12-13] %d\n",
908  bytestream_get_le16(&edata_ptr)); // Unknown always 0
909 
910  /* setup */
911  samples_per_frame = SAMPLES_PER_FRAME * channels;
912  version = 4;
913  delay = 0x88E;
915  q->scrambled_stream = 0;
916 
917  if (avctx->block_align != 96 * channels * frame_factor &&
918  avctx->block_align != 152 * channels * frame_factor &&
919  avctx->block_align != 192 * channels * frame_factor) {
920  av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
921  "configuration %d/%d/%d\n", avctx->block_align,
922  channels, frame_factor);
923  return AVERROR_INVALIDDATA;
924  }
925  } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
926  /* Parse the extradata, RM format. */
927  version = bytestream_get_be32(&edata_ptr);
928  samples_per_frame = bytestream_get_be16(&edata_ptr);
929  delay = bytestream_get_be16(&edata_ptr);
930  q->coding_mode = bytestream_get_be16(&edata_ptr);
931  q->scrambled_stream = 1;
932 
933  } else {
934  av_log(avctx, AV_LOG_ERROR, "Unknown extradata size %d.\n",
935  avctx->extradata_size);
936  return AVERROR(EINVAL);
937  }
938 
939  /* Check the extradata */
940 
941  if (version != 4) {
942  av_log(avctx, AV_LOG_ERROR, "Version %d != 4.\n", version);
943  return AVERROR_INVALIDDATA;
944  }
945 
946  if (samples_per_frame != SAMPLES_PER_FRAME * channels) {
947  av_log(avctx, AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
948  samples_per_frame);
949  return AVERROR_INVALIDDATA;
950  }
951 
952  if (delay != 0x88E) {
953  av_log(avctx, AV_LOG_ERROR, "Unknown amount of delay %x != 0x88E.\n",
954  delay);
955  return AVERROR_INVALIDDATA;
956  }
957 
958  if (q->coding_mode == SINGLE)
959  av_log(avctx, AV_LOG_DEBUG, "Single channels detected.\n");
960  else if (q->coding_mode == JOINT_STEREO) {
961  if (channels % 2 == 1) { /* Joint stereo channels must be even */
962  av_log(avctx, AV_LOG_ERROR, "Invalid joint stereo channel configuration.\n");
963  return AVERROR_INVALIDDATA;
964  }
965  av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
966  } else {
967  av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
968  q->coding_mode);
969  return AVERROR_INVALIDDATA;
970  }
971 
972  if (avctx->block_align > 4096 || avctx->block_align <= 0)
973  return AVERROR(EINVAL);
974 
977  if (!q->decoded_bytes_buffer)
978  return AVERROR(ENOMEM);
979 
981 
982  /* initialize the MDCT transform */
983  if ((ret = av_tx_init(&q->mdct_ctx, &q->mdct_fn, AV_TX_FLOAT_MDCT, 1, 256,
984  &scale, AV_TX_FULL_IMDCT)) < 0) {
985  av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
986  return ret;
987  }
988 
989  /* init the joint-stereo decoding data */
990  for (js_pair = 0; js_pair < MAX_JS_PAIRS; js_pair++) {
991  q->weighting_delay[js_pair][0] = 0;
992  q->weighting_delay[js_pair][1] = 7;
993  q->weighting_delay[js_pair][2] = 0;
994  q->weighting_delay[js_pair][3] = 7;
995  q->weighting_delay[js_pair][4] = 0;
996  q->weighting_delay[js_pair][5] = 7;
997 
998  for (i = 0; i < 4; i++) {
999  q->matrix_coeff_index_prev[js_pair][i] = 3;
1000  q->matrix_coeff_index_now[js_pair][i] = 3;
1001  q->matrix_coeff_index_next[js_pair][i] = 3;
1002  }
1003  }
1004 
1007  if (!fdsp)
1008  return AVERROR(ENOMEM);
1009  q->vector_fmul = fdsp->vector_fmul;
1010  av_free(fdsp);
1011 
1012  q->units = av_calloc(channels, sizeof(*q->units));
1013  if (!q->units)
1014  return AVERROR(ENOMEM);
1015 
1016  ff_thread_once(&init_static_once, atrac3_init_static_data);
1017 
1018  return 0;
1019 }
1020 
1022  .p.name = "atrac3",
1023  CODEC_LONG_NAME("ATRAC3 (Adaptive TRansform Acoustic Coding 3)"),
1024  .p.type = AVMEDIA_TYPE_AUDIO,
1025  .p.id = AV_CODEC_ID_ATRAC3,
1026  .priv_data_size = sizeof(ATRAC3Context),
1028  .close = atrac3_decode_close,
1030  .p.capabilities =
1031 #if FF_API_SUBFRAMES
1032  AV_CODEC_CAP_SUBFRAMES |
1033 #endif
1035  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1037  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1038 };
1039 
1041  .p.name = "atrac3al",
1042  CODEC_LONG_NAME("ATRAC3 AL (Adaptive TRansform Acoustic Coding 3 Advanced Lossless)"),
1043  .p.type = AVMEDIA_TYPE_AUDIO,
1044  .p.id = AV_CODEC_ID_ATRAC3AL,
1045  .priv_data_size = sizeof(ATRAC3Context),
1047  .close = atrac3_decode_close,
1049  .p.capabilities =
1050 #if FF_API_SUBFRAMES
1051  AV_CODEC_CAP_SUBFRAMES |
1052 #endif
1054  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1056  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1057 };
mantissa_vlc_tab
static const int8_t mantissa_vlc_tab[18]
Definition: atrac3data.h:82
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
ff_vlc_init_from_lengths
int ff_vlc_init_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:306
level
uint8_t level
Definition: svq3.c:205
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
ff_atrac3_decoder
const FFCodec ff_atrac3_decoder
Definition: atrac3.c:1021
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
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
imlt
static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands caused ...
Definition: atrac3.c:135
JOINT_STEREO
#define JOINT_STEREO
Definition: atrac3.c:59
libm.h
mem_internal.h
out
FILE * out
Definition: movenc.c:55
GainBlock::g_block
AtracGainInfo g_block[4]
Definition: atrac3.c:68
thread.h
src1
const pixel * src1
Definition: h264pred_template.c:421
AVTXContext
Definition: tx_priv.h:235
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
ATRAC3Context::gb
GetBitContext gb
Definition: atrac3.c:94
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
SAMPLES_PER_FRAME
#define SAMPLES_PER_FRAME
Definition: atrac3.c:62
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:524
ChannelUnit::delay_buf1
float delay_buf1[46]
qmf delay buffers
Definition: atrac3.c:88
ChannelUnit::delay_buf3
float delay_buf3[46]
Definition: atrac3.c:90
b
#define b
Definition: input.c:41
channel_weighting
static void channel_weighting(float *su1, float *su2, int *p3)
Definition: atrac3.c:547
table
static const uint16_t table[]
Definition: prosumer.c:205
FFCodec
Definition: codec_internal.h:126
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
c1
static const uint64_t c1
Definition: murmur3.c:52
ATRAC3Context::matrix_coeff_index_now
int matrix_coeff_index_now[MAX_JS_PAIRS][4]
Definition: atrac3.c:104
atrac3al_decode_frame
static int atrac3al_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:833
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
clc_length_tab
static const uint8_t clc_length_tab[8]
Definition: atrac3data.h:78
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
ChannelUnit::components
TonalComponent components[64]
Definition: atrac3.c:82
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:903
ChannelUnit::spectrum
float spectrum[SAMPLES_PER_FRAME]
Definition: atrac3.c:85
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
MDCT_SIZE
#define MDCT_SIZE
Definition: atrac3.c:63
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:130
inv_max_quant
static const float inv_max_quant[8]
Definition: atrac3data.h:89
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
GetBitContext
Definition: get_bits.h:108
ATRAC3Context::mdct_fn
av_tx_fn mdct_fn
Definition: atrac3.c:120
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
atrac3_vlc_table
static VLCElem atrac3_vlc_table[7 *1<< ATRAC3_VLC_BITS]
Definition: atrac3.c:126
ff_atrac_init_gain_compensation
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
Definition: atrac.c:67
AV_CODEC_ID_ATRAC3
@ AV_CODEC_ID_ATRAC3
Definition: codec_id.h:471
first
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
Definition: rate_distortion.txt:12
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
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
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
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:151
mantissa_clc_tab
static const int8_t mantissa_clc_tab[4]
Definition: atrac3data.h:80
decode_tonal_components
static int decode_tonal_components(GetBitContext *gb, TonalComponent *components, int num_bands)
Restore the quantized tonal components.
Definition: atrac3.c:331
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
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
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:286
atrac.h
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
TonalComponent::coef
float coef[8]
Definition: atrac3.c:74
s1
#define s1
Definition: regdef.h:38
AtracGainInfo::num_points
int num_points
number of gain control points
Definition: atrac.h:36
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AtracGCContext
Gain compensation context structure.
Definition: atrac.h:44
channels
channels
Definition: aptx.h:31
decode.h
get_bits.h
atrac3data.h
decode_bytes
static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
Definition: atrac3.c:161
cmp
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Definition: motion_est.c:262
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:271
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
av_be2ne32
#define av_be2ne32(x)
Definition: bswap.h:95
add_tonal_components
static int add_tonal_components(float *spectrum, int num_components, TonalComponent *components)
Combine the tonal band spectrum and regular band spectrum.
Definition: atrac3.c:451
AV_TX_FULL_IMDCT
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
Definition: tx.h:175
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
ATRAC3Context::temp_buf
float temp_buf[1070]
Definition: atrac3.c:111
ChannelUnit::delay_buf2
float delay_buf2[46]
Definition: atrac3.c:89
NULL
#define NULL
Definition: coverity.c:32
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
ff_atrac_sf_table
float ff_atrac_sf_table[64]
Definition: atrac.c:36
GainBlock
Definition: atrac3.c:67
ATRAC3Context
Definition: atrac3.c:93
AtracGainInfo
Gain control parameters for one subband.
Definition: atrac.h:35
ChannelUnit::gain_block
GainBlock gain_block[2]
Definition: atrac3.c:83
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:652
ATRAC3Context::units
ChannelUnit * units
Definition: atrac3.c:99
AVOnce
#define AVOnce
Definition: thread.h:202
index
int index
Definition: gxfenc.c:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
read_quant_spectral_coeffs
static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, int coding_flag, int *mantissas, int num_codes)
Mantissa decoding.
Definition: atrac3.c:219
float_dsp.h
ATRAC3Context::matrix_coeff_index_next
int matrix_coeff_index_next[MAX_JS_PAIRS][4]
Definition: atrac3.c:105
AV_CODEC_ID_ATRAC3AL
@ AV_CODEC_ID_ATRAC3AL
Definition: codec_id.h:522
atrac3_decode_frame
static int atrac3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:794
VLC::table_allocated
int table_allocated
Definition: vlc.h:39
s2
#define s2
Definition: regdef.h:39
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1556
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
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:525
TonalComponent::num_coefs
int num_coefs
Definition: atrac3.c:73
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
AVFloatDSPContext::vector_fmul
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats.
Definition: float_dsp.h:36
ChannelUnit::num_components
int num_components
Definition: atrac3.c:79
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AtracGainInfo::loc_code
int loc_code[7]
location of gain control points
Definition: atrac.h:38
size
int size
Definition: twinvq_data.h:10344
VLCElem
Definition: vlc.h:32
AVFloatDSPContext
Definition: float_dsp.h:22
init_imdct_window
static av_cold void init_imdct_window(void)
Definition: atrac3.c:184
TonalComponent::pos
int pos
Definition: atrac3.c:72
ChannelUnit::imdct_buf
float imdct_buf[SAMPLES_PER_FRAME]
Definition: atrac3.c:86
decode_spectrum
static int decode_spectrum(GetBitContext *gb, float *output)
Restore the quantized band spectrum coefficients.
Definition: atrac3.c:273
get_channel_weights
static void get_channel_weights(int index, int flag, float ch[2])
Definition: atrac3.c:534
ff_atrac_generate_tables
av_cold void ff_atrac_generate_tables(void)
Generate common tables.
Definition: atrac.c:61
attributes.h
ChannelUnit::bands_coded
int bands_coded
Definition: atrac3.c:78
version
version
Definition: libkvazaar.c:321
MAX_JS_PAIRS
#define MAX_JS_PAIRS
Definition: atrac3.c:57
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
M_PI
#define M_PI
Definition: mathematics.h:67
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:295
ATRAC3_VLC_BITS
#define ATRAC3_VLC_BITS
Definition: atrac3.c:65
flag
#define flag(name)
Definition: cbs_av1.c:466
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
ATRAC3Context::coding_mode
int coding_mode
stream data
Definition: atrac3.c:97
ATRAC3Context::mdct_ctx
AVTXContext * mdct_ctx
Definition: atrac3.c:119
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
len
int len
Definition: vorbis_enc_data.h:426
atrac3_decode_close
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
Definition: atrac3.c:199
ATRAC3Context::scrambled_stream
int scrambled_stream
extradata
Definition: atrac3.c:115
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
decode_channel_sound_unit
static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, ChannelUnit *snd, float *output, int channel_num, int coding_mode)
Decode a Sound Unit.
Definition: atrac3.c:578
huff_tab_sizes
static const uint8_t huff_tab_sizes[7]
Definition: atrac3data.h:72
avcodec.h
decode_frame
static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, float **out_samples)
Definition: atrac3.c:645
atrac3_decode_init
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
Definition: atrac3.c:876
ret
ret
Definition: filter_design.txt:187
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1083
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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
pos
unsigned int pos
Definition: spdifenc.c:414
AtracGainInfo::lev_code
int lev_code[7]
level at corresponding control point
Definition: atrac.h:37
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:445
c2
static const uint64_t c2
Definition: murmur3.c:53
ff_atrac_gain_compensation
void ff_atrac_gain_compensation(AtracGCContext *gctx, float *in, float *prev, AtracGainInfo *gc_now, AtracGainInfo *gc_next, int num_samples, float *out)
Apply gain compensation and perform the MDCT overlapping part.
Definition: atrac.c:85
VLC
Definition: vlc.h:36
spectral_coeff_tab
static VLC spectral_coeff_tab[7]
Definition: atrac3.c:127
TonalComponent
Definition: atrac3.c:71
subband_tab
static const uint16_t subband_tab[33]
Definition: atrac3data.h:94
al_decode_frame
static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf, int size, float **out_samples)
Definition: atrac3.c:759
ChannelUnit::prev_frame
float prev_frame[SAMPLES_PER_FRAME]
Definition: atrac3.c:80
VLC::table
VLCElem * table
Definition: vlc.h:38
ChannelUnit::gc_blk_switch
int gc_blk_switch
Definition: atrac3.c:81
src0
const pixel *const src0
Definition: h264pred_template.c:420
ATRAC3Context::matrix_coeff_index_prev
int matrix_coeff_index_prev[MAX_JS_PAIRS][4]
joint-stereo related variables
Definition: atrac3.c:103
mem.h
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:501
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
ATRAC3Context::weighting_delay
int weighting_delay[MAX_JS_PAIRS][6]
Definition: atrac3.c:106
INTERPOLATE
#define INTERPOLATE(old, new, nsample)
Definition: atrac3.c:469
bytestream.h
reverse_matrixing
static void reverse_matrixing(float *su1, float *su2, int *prev_code, int *curr_code)
Definition: atrac3.c:472
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
VLC_INIT_USE_STATIC
#define VLC_INIT_USE_STATIC
Definition: vlc.h:182
matrix_coeffs
static const float matrix_coeffs[8]
Definition: atrac3data.h:103
atrac3_init_static_data
static av_cold void atrac3_init_static_data(void)
Definition: atrac3.c:854
ATRAC3Context::decoded_bytes_buffer
uint8_t * decoded_bytes_buffer
data buffers
Definition: atrac3.c:110
ff_atrac3al_decoder
const FFCodec ff_atrac3al_decoder
Definition: atrac3.c:1040
SINGLE
#define SINGLE
Definition: atrac3.c:60
ChannelUnit
Definition: atrac3.c:77
ATRAC3Context::vector_fmul
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Definition: atrac3.c:121
ff_atrac_iqmf
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
Quadrature mirror synthesis filter.
Definition: atrac.c:128
decode_gain_control
static int decode_gain_control(GetBitContext *gb, GainBlock *block, int num_bands)
Decode gain parameters for the coded bands.
Definition: atrac3.c:415
ATRAC3Context::gainc_ctx
AtracGCContext gainc_ctx
Definition: atrac3.c:118
mdct_window
static float mdct_window[MDCT_SIZE]
Definition: atrac3.c:125
tx.h
MAX_CHANNELS
#define MAX_CHANNELS
Definition: atrac3.c:56
atrac3_hufftabs
static const uint8_t atrac3_hufftabs[][2]
Definition: atrac3data.h:35