Commit e6f0bb65 authored by Maxim Polijakowski's avatar Maxim Polijakowski Committed by Kostya Shishkov

ATRAC3+ decoder

Cleanup by Diego Biurrun.
Signed-off-by: default avatarKostya Shishkov <kostya.shishkov@gmail.com>
parent 4c642d8d
......@@ -53,6 +53,7 @@ version 10:
- stereoscopic 3d metadata handling
- png standalone parser
- WebP encoding via libwebp
- ATRAC3+ decoder
version 9:
......
......@@ -1630,6 +1630,7 @@ asv2_decoder_select="dsputil"
asv2_encoder_select="dsputil"
atrac1_decoder_select="mdct sinewin"
atrac3_decoder_select="mdct"
atrac3p_decoder_select="mdct sinewin"
bink_decoder_select="dsputil hpeldsp"
binkaudio_dct_decoder_select="mdct rdft dct sinewin"
binkaudio_rdft_decoder_select="mdct rdft sinewin"
......
......@@ -729,6 +729,7 @@ following image formats are supported:
@tab QuickTime fourcc 'alac'
@item ATRAC1 @tab @tab X
@item ATRAC3 @tab @tab X
@item ATRAC3+ @tab @tab X
@item Bink Audio @tab @tab X
@tab Used in Bink and Smacker files in many games.
@item Delphine Software International CIN audio @tab @tab X
......
......@@ -107,6 +107,8 @@ OBJS-$(CONFIG_ASV2_DECODER) += asvdec.o asv.o mpeg12data.o
OBJS-$(CONFIG_ASV2_ENCODER) += asvenc.o asv.o mpeg12data.o
OBJS-$(CONFIG_ATRAC1_DECODER) += atrac1.o atrac.o
OBJS-$(CONFIG_ATRAC3_DECODER) += atrac3.o atrac.o
OBJS-$(CONFIG_ATRAC3P_DECODER) += atrac3plusdec.o atrac3plus.o \
atrac3plusdsp.o atrac.o
OBJS-$(CONFIG_AURA_DECODER) += cyuv.o
OBJS-$(CONFIG_AURA2_DECODER) += aura.o
OBJS-$(CONFIG_AVS_DECODER) += avs.o
......
......@@ -287,6 +287,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(APE, ape);
REGISTER_DECODER(ATRAC1, atrac1);
REGISTER_DECODER(ATRAC3, atrac3);
REGISTER_DECODER(ATRAC3P, atrac3p);
REGISTER_DECODER(BINKAUDIO_DCT, binkaudio_dct);
REGISTER_DECODER(BINKAUDIO_RDFT, binkaudio_rdft);
REGISTER_DECODER(BMV_AUDIO, bmv_audio);
......
This diff is collapsed.
/*
* ATRAC3+ compatible decoder
*
* Copyright (c) 2010-2013 Maxim Poliakovski
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Global structures, constants and data for ATRAC3+ decoder.
*/
#ifndef AVCODEC_ATRAC3PLUS_H
#define AVCODEC_ATRAC3PLUS_H
#include <stdint.h>
#include "libavutil/float_dsp.h"
#include "atrac.h"
#include "avcodec.h"
#include "fft.h"
#include "get_bits.h"
/** Global unit sizes */
#define ATRAC3P_SUBBANDS 16 ///< number of PQF subbands
#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband
#define ATRAC3P_FRAME_SAMPLES (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
#define ATRAC3P_PQF_FIR_LEN 12 ///< length of the prototype FIR of the PQF
/** Global constants */
#define ATRAC3P_POWER_COMP_OFF 15 ///< disable power compensation
/** ATRAC3+ channel unit types */
enum Atrac3pChannelUnitTypes {
CH_UNIT_MONO = 0, ///< unit containing one coded channel
CH_UNIT_STEREO = 1, ///< unit containing two jointly-coded channels
CH_UNIT_EXTENSION = 2, ///< unit containing extension information
CH_UNIT_TERMINATOR = 3 ///< unit sequence terminator
};
/** Per-channel IPQF history */
typedef struct Atrac3pIPQFChannelCtx {
DECLARE_ALIGNED(32, float, buf1)[ATRAC3P_PQF_FIR_LEN * 2][8];
DECLARE_ALIGNED(32, float, buf2)[ATRAC3P_PQF_FIR_LEN * 2][8];
int pos;
} Atrac3pIPQFChannelCtx;
/** Amplitude envelope of a group of sine waves */
typedef struct Atrac3pWaveEnvelope {
int has_start_point; ///< indicates start point within the GHA window
int has_stop_point; ///< indicates stop point within the GHA window
int start_pos; ///< start position expressed in n*4 samples
int stop_pos; ///< stop position expressed in n*4 samples
} Atrac3pWaveEnvelope;
/** Parameters of a group of sine waves */
typedef struct Atrac3pWavesData {
Atrac3pWaveEnvelope pend_env; ///< pending envelope from the previous frame
Atrac3pWaveEnvelope curr_env; ///< group envelope from the current frame
int num_wavs; ///< number of sine waves in the group
int start_index; ///< start index into global tones table for that subband
} Atrac3pWavesData;
/** Parameters of a single sine wave */
typedef struct Atrac3pWaveParam {
int freq_index; ///< wave frequency index
int amp_sf; ///< quantized amplitude scale factor
int amp_index; ///< quantized amplitude index
int phase_index; ///< quantized phase index
} Atrac3pWaveParam;
/** Sound channel parameters */
typedef struct Atrac3pChanParams {
int ch_num;
int num_coded_vals; ///< number of transmitted quant unit values
int fill_mode;
int split_point;
int table_type; ///< table type: 0 - tone?, 1- noise?
int qu_wordlen[32]; ///< array of word lengths for each quant unit
int qu_sf_idx[32]; ///< array of scale factor indexes for each quant unit
int qu_tab_idx[32]; ///< array of code table indexes for each quant unit
int16_t spectrum[2048]; ///< decoded IMDCT spectrum
uint8_t power_levs[5]; ///< power compensation levels
/* imdct window shape history (2 frames) for overlapping. */
uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]; ///< IMDCT window shape, 0=sine/1=steep
uint8_t *wnd_shape; ///< IMDCT window shape for current frame
uint8_t *wnd_shape_prev; ///< IMDCT window shape for previous frame
/* gain control data history (2 frames) for overlapping. */
AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]; ///< gain control data for all subbands
AtracGainInfo *gain_data; ///< gain control data for next frame
AtracGainInfo *gain_data_prev; ///< gain control data for previous frame
int num_gain_subbands; ///< number of subbands with gain control data
/* tones data history (2 frames) for overlapping. */
Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS];
Atrac3pWavesData *tones_info;
Atrac3pWavesData *tones_info_prev;
} Atrac3pChanParams;
/* Per-unit sine wave parameters */
typedef struct Atrac3pWaveSynthParams {
int tones_present; ///< 1 - tones info present
int amplitude_mode; ///< 1 - low range, 0 - high range
int num_tone_bands; ///< number of PQF bands with tones
uint8_t tone_sharing[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone sharing flags
uint8_t tone_master[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone channel swapping
uint8_t phase_shift[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise 180° phase shifting
int tones_index; ///< total sum of tones in this unit
Atrac3pWaveParam waves[48];
} Atrac3pWaveSynthParams;
/** Channel unit parameters */
typedef struct Atrac3pChanUnitCtx {
/* channel unit variables */
int unit_type; ///< unit type (mono/stereo)
int num_quant_units;
int num_subbands;
int used_quant_units; ///< number of quant units with coded spectrum
int num_coded_subbands; ///< number of subbands with coded spectrum
int mute_flag; ///< mute flag
int use_full_table; ///< 1 - full table list, 0 - restricted one
int noise_present; ///< 1 - global noise info present
int noise_level_index; ///< global noise level index
int noise_table_index; ///< global noise RNG table index
uint8_t swap_channels[ATRAC3P_SUBBANDS]; ///< 1 - perform subband-wise channel swapping
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise IMDCT coefficients negation
Atrac3pChanParams channels[2];
/* Variables related to GHA tones */
Atrac3pWaveSynthParams wave_synth_hist[2]; ///< waves synth history for two frames
Atrac3pWaveSynthParams *waves_info;
Atrac3pWaveSynthParams *waves_info_prev;
Atrac3pIPQFChannelCtx ipqf_ctx[2];
DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< overlapping buffer
} Atrac3pChanUnitCtx;
/**
* Initialize VLC tables for bitstream parsing.
*
* @param[in] codec ptr to the AVCodec
*/
void ff_atrac3p_init_vlcs(AVCodec *codec);
/**
* Decode bitstream data of a channel unit.
*
* @param[in] gb the GetBit context
* @param[in,out] ctx ptr to the channel unit context
* @param[in] num_channels number of channels to process
* @param[in] avctx ptr to the AVCodecContext
* @return result code: 0 = OK, otherwise - error code
*/
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
int num_channels, AVCodecContext *avctx);
/**
* Initialize IMDCT transform.
*
* @param[in] avctx ptr to the AVCodecContext
* @param[in] mdct_ctx pointer to MDCT transform context
*/
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
/**
* Initialize sine waves synthesizer.
*/
void ff_atrac3p_init_wave_synth(void);
/**
* Synthesize sine waves for a particular subband.
*
* @param[in] ch_unit pointer to the channel unit context
* @param[in] fdsp pointer to float DSP context
* @param[in] ch_num which channel to process
* @param[in] sb which subband to process
* @param[out] out receives processed data
*/
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp,
int ch_num, int sb, float *out);
/**
* Perform power compensation aka noise dithering.
*
* @param[in] ctx ptr to the channel context
* @param[in] ch_index which channel to process
* @param[in,out] sp ptr to channel spectrum to process
* @param[in] rng_index indicates which RNG table to use
* @param[in] sb_num which subband to process
*/
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,
float *sp, int rng_index, int sb_num);
/**
* Regular IMDCT and windowing without overlapping,
* with spectrum reversal in the odd subbands.
*
* @param[in] fdsp pointer to float DSP context
* @param[in] mdct_ctx pointer to MDCT transform context
* @param[in] pIn float input
* @param[out] pOut float output
* @param[in] wind_id which MDCT window to apply
* @param[in] sb subband number
*/
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
float *pOut, int wind_id, int sb);
/**
* Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)
* filter bank.
*
* @param[in] dct_ctx ptr to the pre-initialized IDCT context
* @param[in,out] hist ptr to the filter history
* @param[in] in input data to process
* @param[out] out receives processed data
*/
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
const float *in, float *out);
extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
extern const float ff_atrac3p_sf_tab[64];
extern const float ff_atrac3p_mant_tab[8];
#endif /* AVCODEC_ATRAC3PLUS_H */
This diff is collapsed.
/*
* ATRAC3+ compatible decoder
*
* Copyright (c) 2010-2013 Maxim Poliakovski
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Sony ATRAC3+ compatible decoder.
*
* Container formats used to store its data:
* RIFF WAV (.at3) and Sony OpenMG (.oma, .aa3).
*
* Technical description of this codec can be found here:
* http://wiki.multimedia.cx/index.php?title=ATRAC3plus
*
* Kudos to Benjamin Larsson and Michael Karcher
* for their precious technical help!
*/
#include <stdint.h>
#include <string.h>
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "get_bits.h"
#include "internal.h"
#include "atrac.h"
#include "atrac3plus.h"
typedef struct ATRAC3PContext {
GetBitContext gb;
AVFloatDSPContext fdsp;
DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES]; ///< quantized MDCT spectrum
DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
DECLARE_ALIGNED(32, float, time_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the gain compensation
DECLARE_ALIGNED(32, float, outp_buf)[2][ATRAC3P_FRAME_SAMPLES];
AtracGCContext gainc_ctx; ///< gain compensation context
FFTContext mdct_ctx;
FFTContext ipqf_dct_ctx; ///< IDCT context used by IPQF
Atrac3pChanUnitCtx *ch_units; ///< global channel units
int num_channel_blocks; ///< number of channel blocks
uint8_t channel_blocks[5]; ///< channel configuration descriptor
uint64_t my_channel_layout; ///< current channel layout
} ATRAC3PContext;
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
{
av_free(((ATRAC3PContext *)(avctx->priv_data))->ch_units);
return 0;
}
static av_cold int set_channel_params(ATRAC3PContext *ctx,
AVCodecContext *avctx)
{
memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
switch (avctx->channel_layout) {
case AV_CH_FRONT_LEFT:
case AV_CH_LAYOUT_MONO:
ctx->num_channel_blocks = 1;
ctx->channel_blocks[0] = CH_UNIT_MONO;
break;
case AV_CH_LAYOUT_STEREO:
ctx->num_channel_blocks = 1;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
break;
case AV_CH_LAYOUT_SURROUND:
ctx->num_channel_blocks = 2;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
break;
case AV_CH_LAYOUT_4POINT0:
ctx->num_channel_blocks = 3;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
ctx->channel_blocks[2] = CH_UNIT_MONO;
break;
case AV_CH_LAYOUT_5POINT1_BACK:
ctx->num_channel_blocks = 4;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
ctx->channel_blocks[2] = CH_UNIT_STEREO;
ctx->channel_blocks[3] = CH_UNIT_MONO;
break;
case AV_CH_LAYOUT_6POINT1_BACK:
ctx->num_channel_blocks = 5;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
ctx->channel_blocks[2] = CH_UNIT_STEREO;
ctx->channel_blocks[3] = CH_UNIT_MONO;
ctx->channel_blocks[4] = CH_UNIT_MONO;
break;
case AV_CH_LAYOUT_7POINT1:
ctx->num_channel_blocks = 5;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
ctx->channel_blocks[2] = CH_UNIT_STEREO;
ctx->channel_blocks[3] = CH_UNIT_STEREO;
ctx->channel_blocks[4] = CH_UNIT_MONO;
break;
default:
av_log(avctx, AV_LOG_ERROR,
"Unsupported channel layout: %"PRIx64"!\n", avctx->channel_layout);
return AVERROR_INVALIDDATA;
}
return 0;
}
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
{
ATRAC3PContext *ctx = avctx->priv_data;
int i, ch, ret;
if (!avctx->block_align) {
av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
return AVERROR(EINVAL);
}
avpriv_float_dsp_init(&ctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
/* initialize IPQF */
ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx);
ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
ff_atrac3p_init_wave_synth();
if ((ret = set_channel_params(ctx, avctx)) < 0)
return ret;
ctx->my_channel_layout = avctx->channel_layout;
ctx->ch_units = av_mallocz(sizeof(*ctx->ch_units) *
ctx->num_channel_blocks);
if (!ctx->ch_units) {
atrac3p_decode_close(avctx);
return AVERROR(ENOMEM);
}
for (i = 0; i < ctx->num_channel_blocks; i++) {
for (ch = 0; ch < 2; ch++) {
ctx->ch_units[i].channels[ch].ch_num = ch;
ctx->ch_units[i].channels[ch].wnd_shape = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
ctx->ch_units[i].channels[ch].wnd_shape_prev = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
ctx->ch_units[i].channels[ch].gain_data = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
ctx->ch_units[i].channels[ch].gain_data_prev = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
ctx->ch_units[i].channels[ch].tones_info = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
}
ctx->ch_units[i].waves_info = &ctx->ch_units[i].wave_synth_hist[0];
ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
}
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
return 0;
}
static void decode_residual_spectrum(Atrac3pChanUnitCtx *ctx,
float out[2][ATRAC3P_FRAME_SAMPLES],
int num_channels,
AVCodecContext *avctx)
{
int i, sb, ch, qu, nspeclines, RNG_index;
float *dst, q;
int16_t *src;
/* calculate RNG table index for each subband */
int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
if (ctx->mute_flag) {
for (ch = 0; ch < num_channels; ch++)
memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
return;
}
for (qu = 0, RNG_index = 0; qu < ctx->used_quant_units; qu++)
RNG_index += ctx->channels[0].qu_sf_idx[qu] +
ctx->channels[1].qu_sf_idx[qu];
for (sb = 0; sb < ctx->num_coded_subbands; sb++, RNG_index += 128)
sb_RNG_index[sb] = RNG_index & 0x3FC;
/* inverse quant and power compensation */
for (ch = 0; ch < num_channels; ch++) {
/* clear channel's residual spectrum */
memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
for (qu = 0; qu < ctx->used_quant_units; qu++) {
src = &ctx->channels[ch].spectrum[ff_atrac3p_qu_to_spec_pos[qu]];
dst = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
ff_atrac3p_qu_to_spec_pos[qu];
if (ctx->channels[ch].qu_wordlen[qu] > 0) {
q = ff_atrac3p_sf_tab[ctx->channels[ch].qu_sf_idx[qu]] *
ff_atrac3p_mant_tab[ctx->channels[ch].qu_wordlen[qu]];
for (i = 0; i < nspeclines; i++)
dst[i] = src[i] * q;
}
}
for (sb = 0; sb < ctx->num_coded_subbands; sb++)
ff_atrac3p_power_compensation(ctx, ch, &out[ch][0],
sb_RNG_index[sb], sb);
}
if (ctx->unit_type == CH_UNIT_STEREO) {
for (sb = 0; sb < ctx->num_coded_subbands; sb++) {
if (ctx->swap_channels[sb]) {
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
}
/* flip coefficients' sign if requested */
if (ctx->negate_coeffs[sb])
for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
}
}
}
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit,
int num_channels, AVCodecContext *avctx)
{
int ch, sb;
for (ch = 0; ch < num_channels; ch++) {
for (sb = 0; sb < ch_unit->num_subbands; sb++) {
/* inverse transform and windowing */
ff_atrac3p_imdct(&ctx->fdsp, &ctx->mdct_ctx,
&ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
&ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
(ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
ch_unit->channels[ch].wnd_shape[sb], sb);
/* gain compensation and overlapping */
ff_atrac_gain_compensation(&ctx->gainc_ctx,
&ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
&ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
&ch_unit->channels[ch].gain_data_prev[sb],
&ch_unit->channels[ch].gain_data[sb],
ATRAC3P_SUBBAND_SAMPLES,
&ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
}
/* zero unused subbands in both output and overlapping buffers */
memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
0,
(ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
ATRAC3P_SUBBAND_SAMPLES *
sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
0,
(ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
ATRAC3P_SUBBAND_SAMPLES *
sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
/* resynthesize and add tonal signal */
if (ch_unit->waves_info->tones_present ||
ch_unit->waves_info_prev->tones_present) {
for (sb = 0; sb < ch_unit->num_subbands; sb++)
if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
ff_atrac3p_generate_tones(ch_unit, &ctx->fdsp, ch, sb,
&ctx->time_buf[ch][sb * 128]);
}
}
/* subband synthesis and acoustic signal output */
ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch],
&ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]);
}
/* swap window shape and gain control buffers. */
for (ch = 0; ch < num_channels; ch++) {
FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
ch_unit->channels[ch].wnd_shape_prev);
FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
ch_unit->channels[ch].gain_data_prev);
FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
ch_unit->channels[ch].tones_info_prev);
}
FFSWAP(Atrac3pWaveSynthParams *, ch_unit->waves_info, ch_unit->waves_info_prev);
}
static int atrac3p_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{