32 #define ATRAC9_SF_VLC_BITS 8 33 #define ATRAC9_COEFF_VLC_BITS 9 125 grad_range[1] =
get_bits(gb, 6) + 1;
131 if (grad_range[0] >= grad_range[1] || grad_range[1] > 31)
137 values = grad_value[1] - grad_value[0];
138 sign = 1 - 2*(values < 0);
139 base = grad_value[0] + sign;
140 scale = (
FFABS(values) - 1) / 31.0
f;
141 curve = s->
alloc_curve[grad_range[1] - grad_range[0] - 1];
144 b->
gradient[
i] = grad_value[
i >= grad_range[0]];
146 for (
int i = grad_range[0];
i < grad_range[1];
i++)
147 b->
gradient[
i] = base + sign*((
int)(scale*curve[
i - grad_range[0]]));
234 for (
int i = 0;
i <= stereo;
i++) {
237 for (
int j = 0; j <
count; j++) {
246 for (
int i = 0;
i <= stereo;
i++) {
249 for (
int j = 0; j <
count; j++) {
260 int channel_idx,
int first_in_pkt)
262 static const uint8_t mode_map[2][4] = { { 0, 1, 2, 3 }, { 0, 2, 3, 4 } };
263 const int mode = mode_map[channel_idx][
get_bits(gb, 2)];
267 if (first_in_pkt && (mode == 4 || ((mode == 3) && !channel_idx))) {
312 for (
int i = 0;
i < unit_cnt;
i++) {
335 for (
int i = 1;
i < unit_cnt;
i++) {
341 for (
int i = 0;
i < unit_cnt;
i++)
375 for (
int i = 0;
i < 12;
i++)
377 avg = (avg + 6) / 12;
385 if ((cur - min >= 3 || 2*cur - prev - next >= 3))
415 if (prec <= max_prec) {
418 const VLC *
tab = &coeff_vlc[
cb][prec][cbi];
422 for (
int j = 0; j <
groups; j++) {
425 for (
int k = 0; k < huff->
value_cnt; k++) {
433 for (
int j = 0; j <
bands; j++)
452 for (
int j = start; j < end; j++)
469 for (
int j = start; j < end; j++) {
493 for (
int j = start; j < end; j++)
494 dst[j] = sign*src[j];
501 for (
int i = 0;
i <= stereo;
i++) {
508 for (
int k = start; k < end; k++)
515 int start,
int count)
518 for (
int i = 0;
i <
count;
i += 2) {
521 c->
coeffs[start +
i + 0] = tmp[0];
522 c->
coeffs[start +
i + 1] = tmp[1];
527 c->
coeffs[start +
i] /= maxval;
531 const int s_unit,
const int e_unit)
533 for (
int i = s_unit;
i < e_unit;
i++) {
536 for (
int j = start; j < end; j++)
537 c->
coeffs[j] *= sf[
i - s_unit];
544 const int g_units[4] = {
548 FFMAX(g_units[2], 22),
551 const int g_bins[4] = {
558 for (
int ch = 0; ch <= stereo; ch++) {
562 for (
int i = 0;
i < 3;
i++)
563 for (
int j = 0; j < (g_bins[
i + 1] - g_bins[
i + 0]); j++)
568 float sf[6] = { 0.0f };
569 const int l = g_units[3] - g_units[0] - 1;
602 for (
int i = g_units[0];
i < g_units[3];
i++)
610 const float g_sf[2] = {
615 for (
int i = 0;
i < 2;
i++)
616 for (
int j = g_bins[
i + 0]; j < g_bins[
i + 1]; j++)
624 for (
int i = g_bins[0];
i < g_bins[3];
i++) {
632 const float g_sf[3] = { 0.7079468f*m, 0.5011902f*m, 0.3548279f*m };
634 for (
int i = 0;
i < 3;
i++)
635 for (
int j = g_bins[
i + 0]; j < g_bins[
i + 1]; j++)
645 int frame_idx,
int block_idx)
653 const int precision = reuse_params ? 8 : 4;
669 for (
int j = start; j < end; j++)
679 if (first_in_pkt && reuse_params) {
686 int stereo_band, ext_band;
701 stereo_band =
get_bits(gb, 4) + min_band_count;
712 ext_band =
get_bits(gb, 4) + min_band_count;
713 if (ext_band < b->band_count) {
749 for (
int i = 0;
i <= stereo;
i++) {
772 for (
int i = 0;
i <= stereo;
i++) {
776 const ptrdiff_t
offset = wsize*frame_idx*
sizeof(float);
777 float *dst = (
float *)(frame->
extended_data[dst_idx] + offset);
782 memcpy(c->
prev_win, s->
temp + (wsize >> 1),
sizeof(
float)*wsize >> 1);
789 int *got_frame_ptr,
AVPacket *avpkt)
825 for (
int i = 0;
i <= stereo;
i++) {
844 unsigned *buf_offset,
int offset)
848 vlc->
table = &vlc_buf[*buf_offset];
851 &(*
tab)[0][1], 2, &(*
tab)[0][0], 2, 1,
864 for (
int i = 1;
i < 7;
i++) {
873 for (
int i = 2;
i < 6;
i++) {
885 for (
int i = 0;
i < 2;
i++) {
886 for (
int j = 2; j < 8; j++) {
887 for (
int k =
i; k < 4; k++) {
901 int version, block_config_idx, superframe_idx, alloc_c_len;
933 block_config_idx =
get_bits(&gb, 3);
934 if (block_config_idx > 5) {
953 if (superframe_idx & 1) {
971 const float sidx = (
i + 0.5f) / len;
972 const float eidx = (len -
i - 0.5f) / len;
975 s->
imdct_win[
i] = s_c / ((s_c * s_c) + (e_c * e_c));
980 for (
int i = 1;
i <= alloc_c_len;
i++)
981 for (
int j = 0; j <
i; j++)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Context structure for the Lagged Fibonacci PRNG.
static const uint8_t at9_tab_sri_max_bands[]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVCodec ff_atrac9_decoder
static const uint8_t at9_coeffs_tab[][2]
This structure describes decoded (raw) audio or video data.
static void apply_band_extension(ATRAC9Context *s, ATRAC9BlockData *b, const int stereo)
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void dequantize(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static av_cold int init(AVCodecContext *avctx)
#define ATRAC9_SF_VLC_BITS
static const uint8_t at9_sfb_a_tab[][2]
static const uint8_t at9_sfb_b_tab[][2]
static void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c, GetBitContext *gb)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define FF_ARRAY_ELEMS(a)
static av_cold void atrac9_init_static(void)
if it could not because there are no more frames
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static const float at9_band_ext_scales_m4[]
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
static const HuffmanCodebook at9_huffman_coeffs[][8][4]
static double cb(void *priv, double x, double y)
static const int at9_tab_samplerates[]
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
ATRAC9ChannelData channel[2]
enum AVSampleFormat sample_fmt
audio sample format
The exact code depends on how similar the blocks are and how related they are to the block
static const OptionGroupDef groups[]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
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
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
bitstream reader API header.
static void fill_with_noise(ATRAC9Context *s, ATRAC9ChannelData *c, int start, int count)
static int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c, GetBitContext *gb, int channel_idx, int first_in_pkt)
void av_bmg_get(AVLFG *lfg, double out[2])
Get the next two numbers generated by a Box-Muller Gaussian generator using the random numbers issued...
static void apply_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, const int stereo)
static const uint8_t at9_tab_sf_weights[][32]
int32_t q_coeffs_coarse[256]
static void calc_precision(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c)
static int atrac9_decode_block(ATRAC9Context *s, GetBitContext *gb, ATRAC9BlockData *b, AVFrame *frame, int frame_idx, int block_idx)
static const float at9_quant_step_fine[]
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void read_coeffs_fine(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c, GetBitContext *gb)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static const uint8_t at9_tab_band_q_unit_map[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const uint8_t at9_q_unit_to_codebookidx[]
int flags
AV_CODEC_FLAG_*.
static int parse_band_ext(ATRAC9Context *s, ATRAC9BlockData *b, GetBitContext *gb, int stereo)
const char * name
Name of the codec implementation.
static void calc_codebook_idx(ATRAC9Context *s, ATRAC9BlockData *b, ATRAC9ChannelData *c)
uint64_t channel_layout
Audio channel layout.
enum ATRAC9BlockType type[5]
static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes, const uint8_t(**tab)[2], unsigned *buf_offset, int offset)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int32_t scalefactors_prev[31]
static VLC coeff_vlc[2][8][4]
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 values
static const float at9_band_ext_scales_m0[][5][32]
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
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static const float at9_scalefactor_c[]
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int parse_gradient(ATRAC9Context *s, ATRAC9BlockData *b, GetBitContext *gb)
static av_cold int atrac9_decode_init(AVCodecContext *avctx)
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
static const float bands[]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void apply_intensity_stereo(ATRAC9Context *s, ATRAC9BlockData *b, const int stereo)
static unsigned int get_bits1(GetBitContext *s)
static const uint8_t at9_q_unit_to_coeff_cnt[]
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
uint8_t alloc_curve[48][48]
int ff_init_vlc_from_lengths(VLC *vlc_arg, 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()
static av_cold int atrac9_decode_close(AVCodecContext *avctx)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static const uint8_t at9_tab_band_ext_group[][3]
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static const uint8_t at9_tab_band_ext_cnt[][6]
#define ATRAC9_COEFF_VLC_BITS
static av_const int sign_extend(int val, unsigned bits)
static const float at9_band_ext_scales_m2[]
static void scale_band_ext_coeffs(ATRAC9ChannelData *c, float sf[6], const int s_unit, const int e_unit)
static const float at9_quant_step_coarse[]
static int atrac9_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static const HuffmanCodebook at9_huffman_sf_unsigned[]
common internal api header.
const ATRAC9BlockConfig * block_config
channel
Use these values when setting the channel map with ebur128_set_channel().
static const uint8_t at9_tab_sri_frame_log2[]
static const float at9_band_ext_scales_m3[][2]
static const HuffmanCodebook at9_huffman_sf_signed[]
int channels
number of audio channels
static int ff_thread_once(char *control, void(*routine)(void))
VLC_TYPE(* table)[2]
code, bits
static const uint8_t * align_get_bits(GetBitContext *s)
static const struct twinvq_data tab
static const ATRAC9BlockConfig at9_block_layout[]
static VLC_TYPE vlc_buf[16716][2]
static const uint8_t at9_tab_b_dist[]
static void atrac9_decode_flush(AVCodecContext *avctx)
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
uint8_t ** extended_data
pointers to the data planes/channels.
#define INIT_VLC_STATIC_OVERLONG
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static double val(void *priv, double ch)
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
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.
static const int at9_q_unit_to_coeff_idx[]
int32_t q_coeffs_fine[256]
static const uint8_t at9_tab_band_ext_lengths[][6][4]
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.