45 #define AT1_MAX_BFU 52
46 #define AT1_SU_SIZE 212
47 #define AT1_SU_SAMPLES 512
48 #define AT1_FRAME_SIZE AT1_SU_SIZE * 2
49 #define AT1_SU_MAX_BITS AT1_SU_SIZE * 8
50 #define AT1_MAX_CHANNELS 2
52 #define AT1_QMF_BANDS 3
53 #define IDX_LOW_BAND 0
54 #define IDX_MID_BAND 1
55 #define IDX_HIGH_BAND 2
95 int transf_size = 1 << nbits;
99 for (i = 0; i < transf_size / 2; i++)
100 FFSWAP(
float, spec[i], spec[transf_size - 1 - i]);
102 mdct_context->
imdct_half(mdct_context, out, spec);
108 int band_num, band_samples, log2_block_count, nbits, num_blocks, block_size;
109 unsigned int start_pos, ref_pos = 0, pos = 0;
120 num_blocks = 1 << log2_block_count;
122 if (num_blocks == 1) {
125 block_size = band_samples >> log2_block_count;
130 if (nbits != 5 && nbits != 7 && nbits != 8)
138 prev_buf = &su->
spectrum[1][ref_pos + band_samples - 16];
139 for (j=0; j < num_blocks; j++) {
144 &su->
spectrum[0][ref_pos + start_pos], ff_sine_32, 16);
146 prev_buf = &su->
spectrum[0][ref_pos+start_pos + 16];
147 start_pos += block_size;
152 memcpy(q->
bands[band_num] + 32, &su->
spectrum[0][ref_pos + 16], 240 *
sizeof(
float));
154 ref_pos += band_samples;
169 int log2_block_count_tmp, i;
171 for (i = 0; i < 2; i++) {
173 log2_block_count_tmp =
get_bits(gb, 2);
174 if (log2_block_count_tmp & 1)
176 log2_block_cnt[i] = 2 - log2_block_count_tmp;
180 log2_block_count_tmp =
get_bits(gb, 2);
181 if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3)
193 int bits_used, band_num, bfu_num, i;
203 bits_used = su->
num_bfus * 10 + 32 +
217 idwls[i] = idsfs[i] = 0;
225 int word_len = !!idwls[bfu_num] + idwls[bfu_num];
227 bits_used += word_len * num_specs;
237 float max_quant = 1.0 / (float)((1 << (word_len - 1)) - 1);
239 for (i = 0; i < num_specs; i++) {
243 spec[pos+i] =
get_sbits(gb, word_len) * scale_factor * max_quant;
246 memset(&spec[pos], 0, num_specs *
sizeof(
float));
258 float iqmf_temp[512 + 46];
273 int *got_frame_ptr,
AVPacket *avpkt)
277 int buf_size = avpkt->
size;
283 if (buf_size < 212 * avctx->channels) {
293 for (ch = 0; ch < avctx->
channels; ch++) {
385 .priv_data_size =
sizeof(
AT1Ctx),
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
float snd_qmf_delay[46]
delay line for the 2nd stacked QMF filter
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
AVCodec ff_atrac1_decoder
Sound unit struct, one unit is used per channel.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int at1_unpack_dequant(GetBitContext *gb, AT1SUCtx *su, float spec[AT1_SU_SAMPLES])
AT1SUCtx SUs[AT1_MAX_CHANNELS]
channel sound unit
static av_cold int init(AVCodecContext *avctx)
static av_cold int atrac1_decode_init(AVCodecContext *avctx)
static av_cold int atrac1_decode_end(AVCodecContext *avctx)
static const uint8_t bfu_amount_tab2[4]
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
Quadrature mirror synthesis filter.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static int get_sbits(GetBitContext *s, int n)
static void at1_subband_synthesis(AT1Ctx *q, AT1SUCtx *su, float *pOut)
static const uint8_t specs_per_bfu[52]
number of spectral lines in each BFU block floating unit = group of spectral frequencies having the s...
float ff_atrac_sf_table[64]
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
enum AVSampleFormat sample_fmt
audio sample format
static const uint16_t samples_per_band[3]
size of the transform in samples in the long mode for each QMF band
The atrac1 context, holds all needed parameters for decoding.
float spec2[AT1_SU_SAMPLES]
mdct buffer
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define AT1_SU_SAMPLES
number of samples in a sound unit
bitstream reader API header.
static int at1_parse_bsm(GetBitContext *gb, int log2_block_cnt[AT1_QMF_BANDS])
Parse the block size mode byte.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void at1_imdct(AT1Ctx *q, float *spec, float *out, int nbits, int rev_spec)
static const uint16_t bfu_start_short[52]
start position of each BFU in the MDCT spectrum for the short mode
static const uint8_t bfu_amount_tab1[8]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
float spec1[AT1_SU_SAMPLES]
mdct buffer
int log2_block_count[AT1_QMF_BANDS]
log2 number of blocks in a band
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
float fst_qmf_delay[46]
delay line for the 1st stacked QMF filter
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static int atrac1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static const uint8_t mdct_long_nbits[3]
#define AT1_MAX_BFU
max number of block floating units in a sound unit
static const uint8_t bfu_bands_t[4]
number of BFUs in each QMF band
float spec[AT1_SU_SAMPLES]
the mdct spectrum buffer
common internal api header.
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(AV_SAMPLE_FMT_S32,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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
ATRAC1 compatible decoder data.
float last_qmf_delay[256+39]
delay line for the last stacked QMF filter
int channels
number of audio channels
av_cold void ff_atrac_generate_tables(void)
Generate common tables.
static enum AVSampleFormat sample_fmts[]
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
#define FFSWAP(type, a, b)
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
static const uint8_t bfu_amount_tab3[8]
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.
int num_bfus
number of Block Floating Units
static int at1_imdct_block(AT1SUCtx *su, AT1Ctx *q)
void AAC_RENAME() ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
static const uint16_t bfu_start_long[52]
start position of each BFU in the MDCT spectrum for the long mode