FFmpeg
atrac3plusdec.c
Go to the documentation of this file.
1 /*
2  * ATRAC3+ compatible decoder
3  *
4  * Copyright (c) 2010-2013 Maxim Poliakovski
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  * Sony ATRAC3+ compatible decoder.
26  *
27  * Container formats used to store its data:
28  * RIFF WAV (.at3) and Sony OpenMG (.oma, .aa3).
29  *
30  * Technical description of this codec can be found here:
31  * http://wiki.multimedia.cx/index.php?title=ATRAC3plus
32  *
33  * Kudos to Benjamin Larsson and Michael Karcher
34  * for their precious technical help!
35  */
36 
37 #include <stdint.h>
38 #include <string.h>
39 
41 #include "libavutil/float_dsp.h"
42 #include "avcodec.h"
43 #include "get_bits.h"
44 #include "internal.h"
45 #include "atrac.h"
46 #include "atrac3plus.h"
47 
48 typedef struct ATRAC3PContext {
51 
52  DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES]; ///< quantized MDCT spectrum
53  DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
54  DECLARE_ALIGNED(32, float, time_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the gain compensation
56 
57  AtracGCContext gainc_ctx; ///< gain compensation context
59  FFTContext ipqf_dct_ctx; ///< IDCT context used by IPQF
60 
61  Atrac3pChanUnitCtx *ch_units; ///< global channel units
62 
63  int num_channel_blocks; ///< number of channel blocks
64  uint8_t channel_blocks[5]; ///< channel configuration descriptor
65  uint64_t my_channel_layout; ///< current channel layout
67 
69 {
70  ATRAC3PContext *ctx = avctx->priv_data;
71 
72  av_freep(&ctx->ch_units);
73  av_freep(&ctx->fdsp);
74 
75  ff_mdct_end(&ctx->mdct_ctx);
76  ff_mdct_end(&ctx->ipqf_dct_ctx);
77 
78  return 0;
79 }
80 
82  AVCodecContext *avctx)
83 {
84  memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
85 
86  switch (avctx->channels) {
87  case 1:
88  if (avctx->channel_layout != AV_CH_FRONT_LEFT)
90 
91  ctx->num_channel_blocks = 1;
92  ctx->channel_blocks[0] = CH_UNIT_MONO;
93  break;
94  case 2:
96  ctx->num_channel_blocks = 1;
97  ctx->channel_blocks[0] = CH_UNIT_STEREO;
98  break;
99  case 3:
101  ctx->num_channel_blocks = 2;
102  ctx->channel_blocks[0] = CH_UNIT_STEREO;
103  ctx->channel_blocks[1] = CH_UNIT_MONO;
104  break;
105  case 4:
107  ctx->num_channel_blocks = 3;
108  ctx->channel_blocks[0] = CH_UNIT_STEREO;
109  ctx->channel_blocks[1] = CH_UNIT_MONO;
110  ctx->channel_blocks[2] = CH_UNIT_MONO;
111  break;
112  case 6:
114  ctx->num_channel_blocks = 4;
115  ctx->channel_blocks[0] = CH_UNIT_STEREO;
116  ctx->channel_blocks[1] = CH_UNIT_MONO;
117  ctx->channel_blocks[2] = CH_UNIT_STEREO;
118  ctx->channel_blocks[3] = CH_UNIT_MONO;
119  break;
120  case 7:
122  ctx->num_channel_blocks = 5;
123  ctx->channel_blocks[0] = CH_UNIT_STEREO;
124  ctx->channel_blocks[1] = CH_UNIT_MONO;
125  ctx->channel_blocks[2] = CH_UNIT_STEREO;
126  ctx->channel_blocks[3] = CH_UNIT_MONO;
127  ctx->channel_blocks[4] = CH_UNIT_MONO;
128  break;
129  case 8:
131  ctx->num_channel_blocks = 5;
132  ctx->channel_blocks[0] = CH_UNIT_STEREO;
133  ctx->channel_blocks[1] = CH_UNIT_MONO;
134  ctx->channel_blocks[2] = CH_UNIT_STEREO;
135  ctx->channel_blocks[3] = CH_UNIT_STEREO;
136  ctx->channel_blocks[4] = CH_UNIT_MONO;
137  break;
138  default:
139  av_log(avctx, AV_LOG_ERROR,
140  "Unsupported channel count: %d!\n", avctx->channels);
141  return AVERROR_INVALIDDATA;
142  }
143 
144  return 0;
145 }
146 
148 {
149  ATRAC3PContext *ctx = avctx->priv_data;
150  int i, ch, ret;
151 
152  if (!avctx->block_align) {
153  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
154  return AVERROR(EINVAL);
155  }
156 
158 
159  /* initialize IPQF */
160  ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
161 
162  ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx);
163 
164  ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
165 
167 
168  if ((ret = set_channel_params(ctx, avctx)) < 0)
169  return ret;
170 
171  ctx->my_channel_layout = avctx->channel_layout;
172 
173  ctx->ch_units = av_mallocz_array(ctx->num_channel_blocks, sizeof(*ctx->ch_units));
175 
176  if (!ctx->ch_units || !ctx->fdsp) {
177  return AVERROR(ENOMEM);
178  }
179 
180  for (i = 0; i < ctx->num_channel_blocks; i++) {
181  for (ch = 0; ch < 2; ch++) {
182  ctx->ch_units[i].channels[ch].ch_num = ch;
183  ctx->ch_units[i].channels[ch].wnd_shape = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
184  ctx->ch_units[i].channels[ch].wnd_shape_prev = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
185  ctx->ch_units[i].channels[ch].gain_data = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
186  ctx->ch_units[i].channels[ch].gain_data_prev = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
187  ctx->ch_units[i].channels[ch].tones_info = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
188  ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
189  }
190 
191  ctx->ch_units[i].waves_info = &ctx->ch_units[i].wave_synth_hist[0];
192  ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
193  }
194 
196 
197  return 0;
198 }
199 
201  float out[2][ATRAC3P_FRAME_SAMPLES],
202  int num_channels,
203  AVCodecContext *avctx)
204 {
205  int i, sb, ch, qu, nspeclines, RNG_index;
206  float *dst, q;
207  int16_t *src;
208  /* calculate RNG table index for each subband */
209  int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
210 
211  if (ch_unit->mute_flag) {
212  for (ch = 0; ch < num_channels; ch++)
213  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
214  return;
215  }
216 
217  for (qu = 0, RNG_index = 0; qu < ch_unit->used_quant_units; qu++)
218  RNG_index += ch_unit->channels[0].qu_sf_idx[qu] +
219  ch_unit->channels[1].qu_sf_idx[qu];
220 
221  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++, RNG_index += 128)
222  sb_RNG_index[sb] = RNG_index & 0x3FC;
223 
224  /* inverse quant and power compensation */
225  for (ch = 0; ch < num_channels; ch++) {
226  /* clear channel's residual spectrum */
227  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
228 
229  for (qu = 0; qu < ch_unit->used_quant_units; qu++) {
231  dst = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
232  nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
234 
235  if (ch_unit->channels[ch].qu_wordlen[qu] > 0) {
236  q = ff_atrac3p_sf_tab[ch_unit->channels[ch].qu_sf_idx[qu]] *
237  ff_atrac3p_mant_tab[ch_unit->channels[ch].qu_wordlen[qu]];
238  for (i = 0; i < nspeclines; i++)
239  dst[i] = src[i] * q;
240  }
241  }
242 
243  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++)
244  ff_atrac3p_power_compensation(ch_unit, ctx->fdsp, ch, &out[ch][0],
245  sb_RNG_index[sb], sb);
246  }
247 
248  if (ch_unit->unit_type == CH_UNIT_STEREO) {
249  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++) {
250  if (ch_unit->swap_channels[sb]) {
251  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
252  FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
253  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
254  }
255 
256  /* flip coefficients' sign if requested */
257  if (ch_unit->negate_coeffs[sb])
258  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
259  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
260  }
261  }
262 }
263 
265  int num_channels, AVCodecContext *avctx)
266 {
267  int ch, sb;
268 
269  for (ch = 0; ch < num_channels; ch++) {
270  for (sb = 0; sb < ch_unit->num_subbands; sb++) {
271  /* inverse transform and windowing */
272  ff_atrac3p_imdct(ctx->fdsp, &ctx->mdct_ctx,
273  &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
274  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
275  (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
276  ch_unit->channels[ch].wnd_shape[sb], sb);
277 
278  /* gain compensation and overlapping */
279  ff_atrac_gain_compensation(&ctx->gainc_ctx,
280  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
281  &ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
282  &ch_unit->channels[ch].gain_data_prev[sb],
283  &ch_unit->channels[ch].gain_data[sb],
285  &ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
286  }
287 
288  /* zero unused subbands in both output and overlapping buffers */
289  memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
290  0,
291  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
293  sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
294  memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
295  0,
296  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
298  sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
299 
300  /* resynthesize and add tonal signal */
301  if (ch_unit->waves_info->tones_present ||
302  ch_unit->waves_info_prev->tones_present) {
303  for (sb = 0; sb < ch_unit->num_subbands; sb++)
304  if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
305  ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
306  ff_atrac3p_generate_tones(ch_unit, ctx->fdsp, ch, sb,
307  &ctx->time_buf[ch][sb * 128]);
308  }
309  }
310 
311  /* subband synthesis and acoustic signal output */
312  ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch],
313  &ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]);
314  }
315 
316  /* swap window shape and gain control buffers. */
317  for (ch = 0; ch < num_channels; ch++) {
318  FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
319  ch_unit->channels[ch].wnd_shape_prev);
320  FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
321  ch_unit->channels[ch].gain_data_prev);
322  FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
323  ch_unit->channels[ch].tones_info_prev);
324  }
325 
327 }
328 
329 static int atrac3p_decode_frame(AVCodecContext *avctx, void *data,
330  int *got_frame_ptr, AVPacket *avpkt)
331 {
332  ATRAC3PContext *ctx = avctx->priv_data;
333  AVFrame *frame = data;
334  int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
335  float **samples_p = (float **)frame->extended_data;
336 
337  frame->nb_samples = ATRAC3P_FRAME_SAMPLES;
338  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
339  return ret;
340 
341  if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0)
342  return ret;
343 
344  if (get_bits1(&ctx->gb)) {
345  av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n");
346  return AVERROR_INVALIDDATA;
347  }
348 
349  while (get_bits_left(&ctx->gb) >= 2 &&
350  (ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) {
351  if (ch_unit_id == CH_UNIT_EXTENSION) {
352  avpriv_report_missing_feature(avctx, "Channel unit extension");
353  return AVERROR_PATCHWELCOME;
354  }
355  if (ch_block >= ctx->num_channel_blocks ||
356  ctx->channel_blocks[ch_block] != ch_unit_id) {
357  av_log(avctx, AV_LOG_ERROR,
358  "Frame data doesn't match channel configuration!\n");
359  return AVERROR_INVALIDDATA;
360  }
361 
362  ctx->ch_units[ch_block].unit_type = ch_unit_id;
363  channels_to_process = ch_unit_id + 1;
364 
366  &ctx->ch_units[ch_block],
367  channels_to_process,
368  avctx)) < 0)
369  return ret;
370 
371  decode_residual_spectrum(ctx, &ctx->ch_units[ch_block], ctx->samples,
372  channels_to_process, avctx);
373  reconstruct_frame(ctx, &ctx->ch_units[ch_block],
374  channels_to_process, avctx);
375 
376  for (i = 0; i < channels_to_process; i++)
377  memcpy(samples_p[out_ch_index + i], ctx->outp_buf[i],
378  ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p));
379 
380  ch_block++;
381  out_ch_index += channels_to_process;
382  }
383 
384  *got_frame_ptr = 1;
385 
386  return avctx->codec_id == AV_CODEC_ID_ATRAC3P ? FFMIN(avctx->block_align, avpkt->size) : avpkt->size;
387 }
388 
390  .name = "atrac3plus",
391  .long_name = NULL_IF_CONFIG_SMALL("ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)"),
392  .type = AVMEDIA_TYPE_AUDIO,
393  .id = AV_CODEC_ID_ATRAC3P,
394  .capabilities = AV_CODEC_CAP_DR1,
395  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
396  .priv_data_size = sizeof(ATRAC3PContext),
398  .close = atrac3p_decode_close,
400 };
401 
403  .name = "atrac3plusal",
404  .long_name = NULL_IF_CONFIG_SMALL("ATRAC3+ AL (Adaptive TRansform Acoustic Coding 3+ Advanced Lossless)"),
405  .type = AVMEDIA_TYPE_AUDIO,
406  .id = AV_CODEC_ID_ATRAC3PAL,
407  .capabilities = AV_CODEC_CAP_DR1,
408  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
409  .priv_data_size = sizeof(ATRAC3PContext),
411  .close = atrac3p_decode_close,
413 };
Atrac3pChanUnitCtx::waves_info
Atrac3pWaveSynthParams * waves_info
Definition: atrac3plus.h:149
AVCodec
AVCodec.
Definition: codec.h:190
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
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
Atrac3pChanParams::tones_info_prev
Atrac3pWavesData * tones_info_prev
Definition: atrac3plus.h:115
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1237
out
FILE * out
Definition: movenc.c:54
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
Atrac3pWavesData::num_wavs
int num_wavs
number of sine waves in the group
Definition: atrac3plus.h:76
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
ATRAC3PContext::gainc_ctx
AtracGCContext gainc_ctx
gain compensation context
Definition: atrac3plusdec.c:57
atrac3p_decode_close
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
Definition: atrac3plusdec.c:68
reconstruct_frame
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int num_channels, AVCodecContext *avctx)
Definition: atrac3plusdec.c:264
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
data
const char data[16]
Definition: mxf.c:91
ff_mdct_init
#define ff_mdct_init
Definition: fft.h:169
Atrac3pChanUnitCtx::ipqf_ctx
Atrac3pIPQFChannelCtx ipqf_ctx[2]
Definition: atrac3plus.h:152
ff_atrac3p_generate_tones
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
Definition: atrac3plusdsp.c:184
ATRAC3PContext::ch_units
Atrac3pChanUnitCtx * ch_units
global channel units
Definition: atrac3plusdec.c:61
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:190
ff_atrac3p_power_compensation
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, AVFloatDSPContext *fdsp, int ch_index, float *sp, int rng_index, int sb_num)
Perform power compensation aka noise dithering.
Definition: atrac3plusdsp.c:418
ATRAC3PContext
Definition: atrac3plusdec.c:48
ff_atrac3p_ipqf
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank.
Definition: atrac3plusdsp.c:605
AV_CODEC_ID_ATRAC3PAL
@ AV_CODEC_ID_ATRAC3PAL
Definition: codec_id.h:494
Atrac3pChanUnitCtx::negate_coeffs
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
Definition: atrac3plus.h:144
ATRAC3PContext::mdct_buf
float mdct_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the IMDCT
Definition: atrac3plusdec.c:53
ATRAC3P_FRAME_SAMPLES
#define ATRAC3P_FRAME_SAMPLES
Definition: atrac3plus.h:42
CH_UNIT_EXTENSION
@ CH_UNIT_EXTENSION
unit containing extension information
Definition: atrac3plus.h:53
Atrac3pChanParams::wnd_shape
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition: atrac3plus.h:103
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
ATRAC3PContext::gb
GetBitContext gb
Definition: atrac3plusdec.c:49
decode_residual_spectrum
static void decode_residual_spectrum(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, float out[2][ATRAC3P_FRAME_SAMPLES], int num_channels, AVCodecContext *avctx)
Definition: atrac3plusdec.c:200
GetBitContext
Definition: get_bits.h:61
set_channel_params
static av_cold int set_channel_params(ATRAC3PContext *ctx, AVCodecContext *avctx)
Definition: atrac3plusdec.c:81
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:606
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:66
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
Atrac3pWaveSynthParams
Definition: atrac3plus.h:119
atrac3p_decode_init
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
Definition: atrac3plusdec.c:147
ff_atrac3p_sf_tab
const float ff_atrac3p_sf_tab[64]
Definition: atrac3plusdsp.c:52
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AV_CODEC_ID_ATRAC3P
@ AV_CODEC_ID_ATRAC3P
Definition: codec_id.h:449
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:677
ATRAC3PContext::outp_buf
float outp_buf[2][ATRAC3P_FRAME_SAMPLES]
Definition: atrac3plusdec.c:55
Atrac3pChanUnitCtx::used_quant_units
int used_quant_units
number of quant units with coded spectrum
Definition: atrac3plus.h:136
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
CH_UNIT_MONO
@ CH_UNIT_MONO
unit containing one coded channel
Definition: atrac3plus.h:51
Atrac3pChanUnitCtx::num_coded_subbands
int num_coded_subbands
number of subbands with coded spectrum
Definition: atrac3plus.h:137
atrac.h
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AtracGCContext
Gain compensation context structure.
Definition: atrac.h:44
get_bits.h
ff_atrac3p_qu_to_spec_pos
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
Definition: atrac3plusdsp.c:42
Atrac3pChanUnitCtx::waves_info_prev
Atrac3pWaveSynthParams * waves_info_prev
Definition: atrac3plus.h:150
ATRAC3PContext::my_channel_layout
uint64_t my_channel_layout
current channel layout
Definition: atrac3plusdec.c:65
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:536
ff_atrac3p_mant_tab
const float ff_atrac3p_mant_tab[8]
Definition: atrac3plusdsp.c:67
if
if(ret)
Definition: filter_design.txt:179
CH_UNIT_TERMINATOR
@ CH_UNIT_TERMINATOR
unit sequence terminator
Definition: atrac3plus.h:54
ATRAC3PContext::num_channel_blocks
int num_channel_blocks
number of channel blocks
Definition: atrac3plusdec.c:63
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
src
#define src
Definition: vp8dsp.c:254
Atrac3pChanParams::gain_data_prev
AtracGainInfo * gain_data_prev
gain control data for previous frame
Definition: atrac3plus.h:109
Atrac3pChanParams::spectrum
int16_t spectrum[2048]
decoded IMDCT spectrum
Definition: atrac3plus.h:98
ff_atrac3p_decoder
AVCodec ff_atrac3p_decoder
Definition: atrac3plusdec.c:389
ATRAC3PContext::channel_blocks
uint8_t channel_blocks[5]
channel configuration descriptor
Definition: atrac3plusdec.c:64
AtracGainInfo
Gain control parameters for one subband.
Definition: atrac.h:35
Atrac3pChanParams::tones_info
Atrac3pWavesData * tones_info
Definition: atrac3plus.h:114
atrac3plus.h
ATRAC3PContext::fdsp
AVFloatDSPContext * fdsp
Definition: atrac3plusdec.c:50
float_dsp.h
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
Atrac3pChanUnitCtx::channels
Atrac3pChanParams channels[2]
Definition: atrac3plus.h:145
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1854
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
AVPacket::size
int size
Definition: packet.h:356
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:188
ff_atrac3p_init_vlcs
av_cold void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
Definition: atrac3plus.c:80
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1194
Atrac3pChanParams::qu_sf_idx
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
Definition: atrac3plus.h:96
CH_UNIT_STEREO
@ CH_UNIT_STEREO
unit containing two jointly-coded channels
Definition: atrac3plus.h:52
ff_mdct_end
#define ff_mdct_end
Definition: fft.h:170
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AVFloatDSPContext
Definition: float_dsp.h:24
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
ATRAC3PContext::time_buf
float time_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the gain compensation
Definition: atrac3plusdec.c:54
AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:98
ATRAC3PContext::ipqf_dct_ctx
FFTContext ipqf_dct_ctx
IDCT context used by IPQF.
Definition: atrac3plusdec.c:59
ff_atrac3p_decode_channel_unit
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
Definition: atrac3plus.c:1761
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:1187
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:112
FFTContext
Definition: fft.h:88
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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: internal.h:48
ff_atrac3p_imdct
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn, float *pOut, int wind_id, int sb)
Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands.
Definition: atrac3plusdsp.c:464
atrac3p_decode_frame
static int atrac3p_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3plusdec.c:329
ATRAC3PContext::mdct_ctx
FFTContext mdct_ctx
Definition: atrac3plusdec.c:58
Atrac3pChanUnitCtx::unit_type
int unit_type
unit type (mono/stereo)
Definition: atrac3plus.h:133
AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_7POINT1
Definition: channel_layout.h:107
ff_atrac3p_init_imdct
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
Initialize IMDCT transform.
Definition: atrac3plusdsp.c:80
AV_CH_FRONT_LEFT
#define AV_CH_FRONT_LEFT
Definition: channel_layout.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
avcodec.h
ff_atrac3pal_decoder
AVCodec ff_atrac3pal_decoder
Definition: atrac3plusdec.c:402
ret
ret
Definition: filter_design.txt:187
Atrac3pChanUnitCtx
Channel unit parameters.
Definition: atrac3plus.h:131
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:1223
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
AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_SURROUND
Definition: channel_layout.h:89
ff_atrac3p_init_wave_synth
void ff_atrac3p_init_wave_synth(void)
Initialize sine waves synthesizer.
Definition: atrac3plusdsp.c:97
Atrac3pChanUnitCtx::prev_buf
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
Definition: atrac3plus.h:153
Atrac3pChanUnitCtx::mute_flag
int mute_flag
mute flag
Definition: atrac3plus.h:138
Atrac3pWaveSynthParams::tones_present
int tones_present
1 - tones info present
Definition: atrac3plus.h:120
Atrac3pChanUnitCtx::swap_channels
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
Definition: atrac3plus.h:143
AVCodecContext
main external API structure.
Definition: avcodec.h:526
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:84
channel_layout.h
Atrac3pWavesData
Parameters of a group of sine waves.
Definition: atrac3plus.h:73
Atrac3pChanUnitCtx::num_subbands
int num_subbands
Definition: atrac3plus.h:135
Atrac3pChanParams::wnd_shape_prev
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
Definition: atrac3plus.h:104
qu
static const float qu[2]
Definition: sipr16kdata.h:28
ATRAC3P_SUBBAND_SAMPLES
#define ATRAC3P_SUBBAND_SAMPLES
number of samples per subband
Definition: atrac3plus.h:41
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:333
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
ATRAC3P_SUBBANDS
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition: atrac3plus.h:40
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_4POINT0
Definition: channel_layout.h:91
AV_CH_LAYOUT_6POINT1_BACK
#define AV_CH_LAYOUT_6POINT1_BACK
Definition: channel_layout.h:103
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
Atrac3pChanParams::qu_wordlen
int qu_wordlen[32]
array of word lengths for each quant unit
Definition: atrac3plus.h:95
Atrac3pChanParams::gain_data
AtracGainInfo * gain_data
gain control data for next frame
Definition: atrac3plus.h:108
ATRAC3PContext::samples
float samples[2][ATRAC3P_FRAME_SAMPLES]
quantized MDCT spectrum
Definition: atrac3plusdec.c:52