140 "Unsupported channel count: %d!\n", avctx->
channels);
182 for (ch = 0; ch < 2; ch++) {
206 int i, sb,
ch,
qu, nspeclines, RNG_index;
213 for (ch = 0; ch < num_channels; ch++)
214 memset(
out[ch], 0, ATRAC3P_FRAME_SAMPLES *
sizeof(*
out[ch]));
223 sb_RNG_index[sb] = RNG_index & 0x3FC;
226 for (ch = 0; ch < num_channels; ch++) {
228 memset(
out[ch], 0, ATRAC3P_FRAME_SAMPLES *
sizeof(*
out[ch]));
233 nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
234 ff_atrac3p_qu_to_spec_pos[
qu];
239 for (i = 0; i < nspeclines; i++)
246 sb_RNG_index[sb], sb);
253 FFSWAP(
float,
out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
254 out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
260 out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(
out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
270 for (ch = 0; ch < num_channels; ch++) {
275 &ctx->
mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
281 &ctx->
mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
282 &ch_unit->
prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
285 ATRAC3P_SUBBAND_SAMPLES,
286 &ctx->
time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
293 ATRAC3P_SUBBAND_SAMPLES *
298 ATRAC3P_SUBBAND_SAMPLES *
318 for (ch = 0; ch < num_channels; ch++) {
331 int *got_frame_ptr,
AVPacket *avpkt)
335 int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
359 "Frame data doesn't match channel configuration!\n");
364 channels_to_process = ch_unit_id + 1;
373 channels_to_process, avctx);
375 channels_to_process, avctx);
377 for (i = 0; i < channels_to_process; i++)
378 memcpy(samples_p[out_ch_index + i], ctx->
outp_buf[i],
382 out_ch_index += channels_to_process;
391 .
name =
"atrac3plus",
403 .
name =
"atrac3plusal",
404 .long_name =
NULL_IF_CONFIG_SMALL(
"ATRAC3+ AL (Adaptive TRansform Acoustic Coding 3+ Advanced Lossless)"),
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
const float ff_atrac3p_sf_tab[64]
#define AV_CH_LAYOUT_7POINT1
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
Atrac3pWaveSynthParams wave_synth_hist[2]
waves synth history for two frames
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Atrac3pChanUnitCtx * ch_units
global channel units
#define AV_CH_LAYOUT_SURROUND
void ff_atrac3p_init_wave_synth(void)
Initialize sine waves synthesizer.
static av_cold int init(AVCodecContext *avctx)
Atrac3pWavesData * tones_info_prev
int num_coded_subbands
number of subbands with coded spectrum
#define AV_CH_LAYOUT_4POINT0
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
int num_wavs
number of sine waves in the group
#define AV_CH_LAYOUT_STEREO
int used_quant_units
number of quant units with coded spectrum
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
#define ATRAC3P_SUBBANDS
Global unit sizes.
AtracGCContext gainc_ctx
gain compensation context
AtracGainInfo * gain_data_prev
gain control data for previous frame
enum AVSampleFormat sample_fmt
audio sample format
int16_t spectrum[2048]
decoded IMDCT spectrum
float mdct_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the IMDCT
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int num_channels, AVCodecContext *avctx)
#define ATRAC3P_FRAME_SAMPLES
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
bitstream reader API header.
static void decode_residual_spectrum(Atrac3pChanUnitCtx *ctx, float out[2][ATRAC3P_FRAME_SAMPLES], int num_channels, AVCodecContext *avctx)
uint8_t * wnd_shape
IMDCT window shape for current frame.
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...
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int num_channel_blocks
number of channel blocks
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
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.
Parameters of a group of sine waves.
static av_cold int set_channel_params(ATRAC3PContext *ctx, AVCodecContext *avctx)
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
Gain compensation context structure.
int qu_wordlen[32]
array of word lengths for each quant unit
static void * av_mallocz_array(size_t nmemb, size_t size)
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
uint64_t channel_layout
Audio channel layout.
#define ATRAC3P_SUBBAND_SAMPLES
number of samples per subband
float samples[2][ATRAC3P_FRAME_SAMPLES]
quantized MDCT spectrum
unit containing one coded channel
audio channel layout utility functions
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
float time_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the gain compensation
Atrac3pWavesData * tones_info
int unit_type
unit type (mono/stereo)
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
av_cold void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
#define AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_6POINT1_BACK
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
uint8_t channel_blocks[5]
channel configuration descriptor
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
Initialize IMDCT transform.
Gain control parameters for one subband.
Libavcodec external API header.
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
float outp_buf[2][ATRAC3P_FRAME_SAMPLES]
AVCodec ff_atrac3p_decoder
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int atrac3p_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
main external API structure.
Atrac3pIPQFChannelCtx ipqf_ctx[2]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
AVCodec ff_atrac3pal_decoder
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
const float ff_atrac3p_mant_tab[8]
Atrac3pWaveSynthParams * waves_info_prev
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]
IMDCT window shape, 0=sine/1=steep.
common internal api header.
AtracGainInfo * gain_data
gain control data for next frame
unit containing two jointly-coded channels
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(A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C(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Atrac3pWaveSynthParams * waves_info
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index, float *sp, int rng_index, int sb_num)
Perform power compensation aka noise dithering.
int channels
number of audio channels
Atrac3pChanParams channels[2]
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.
uint64_t my_channel_layout
current channel layout
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
#define FFSWAP(type, a, b)
int tones_present
1 - tones info present
FFTContext ipqf_dct_ctx
IDCT context used by IPQF.
unit containing extension information
Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Global structures, constants and data for ATRAC3+ decoder.
AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]
gain control data for all subbands