71 for (
int i = 0;
i < 128;
i++) {
76 memset(
ath+
i, 0xFF, (128 -
i));
100 static inline unsigned ceil2(
unsigned a,
unsigned b)
102 return (
b > 0) ? (
a /
b + ((
a %
b) ? 1 : 0)) : 0;
109 int8_t
r[16] = { 0 };
110 float scale = 1.f / 8.f;
113 unsigned hfr_group_count;
128 c->ath_type =
version >= 0x200 ? 0 : 1;
137 if (chunk ==
MKBETAG(
'c',
'o',
'm',
'p')) {
146 c->bands_per_hfr_group =
get_bits(gb, 8);
147 }
else if (chunk ==
MKBETAG(
'd',
'e',
'c', 0)) {
151 c->total_band_count =
get_bits(gb, 8) + 1;
152 c->base_band_count =
get_bits(gb, 8) + 1;
156 c->base_band_count =
c->total_band_count;
157 c->stereo_band_count =
c->total_band_count -
c->base_band_count;
158 c->bands_per_hfr_group = 0;
168 if (chunk ==
MKBETAG(
'v',
'b',
'r', 0)) {
171 }
else if (chunk ==
MKBETAG(
'a',
't',
'h', 0)) {
173 }
else if (chunk ==
MKBETAG(
'r',
'v',
'a', 0)) {
175 }
else if (chunk ==
MKBETAG(
'c',
'o',
'm',
'm')) {
177 }
else if (chunk ==
MKBETAG(
'c',
'i',
'p',
'h')) {
179 }
else if (chunk ==
MKBETAG(
'l',
'o',
'o',
'p')) {
184 }
else if (chunk ==
MKBETAG(
'p',
'a',
'd', 0)) {
199 if (
c->stereo_band_count &&
b > 1) {
202 for (
int i = 0;
i <
c->track_count;
i++, x+=
b) {
211 if (
c->channel_config == 0) {
218 if (
c->channel_config <= 2) {
225 x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2;
228 x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2; x[6] = 1; x[7] = 2;
234 if (
c->total_band_count <
c->base_band_count)
237 hfr_group_count =
ceil2(
c->total_band_count - (
c->base_band_count +
c->stereo_band_count),
238 c->bands_per_hfr_group);
240 if (
c->base_band_count +
c->stereo_band_count + (uint64_t)hfr_group_count > 128ULL)
242 c->hfr_group_count = hfr_group_count;
245 c->ch[
i].chan_type =
r[
i];
246 c->ch[
i].count =
c->base_band_count + ((
r[
i] != 2) ?
c->stereo_band_count : 0);
247 c->ch[
i].hfr_scale = &
c->ch[
i].scale_factors[
c->base_band_count +
c->stereo_band_count];
248 if (
c->ch[
i].count > 128)
270 int index,
unsigned band_count,
unsigned base_band_count,
271 unsigned stereo_band_count)
274 float ratio_r = ratio_l - 2.0f;
278 if (ch1->
chan_type != 1 || !stereo_band_count)
281 for (
int i = 0;
i < band_count;
i++) {
282 *(
c2++) = *
c1 * ratio_r;
288 unsigned hfr_group_count,
289 unsigned bands_per_hfr_group,
290 unsigned start_band,
unsigned total_band_count)
292 if (ch->
chan_type == 2 || !bands_per_hfr_group)
295 for (
int i = 0, k = start_band, l = start_band - 1;
i < hfr_group_count;
i++){
296 for (
int j = 0; j < bands_per_hfr_group && k < total_band_count && l >= 0; j++, k++, l--){
309 for (
int i = 0;
i < ch->
count;
i++) {
310 unsigned scale = ch->
scale[
i];
332 unsigned hfr_group_count,
333 int packed_noise_level,
339 if (delta_bits > 5) {
342 }
else if (delta_bits) {
344 int max_value = (1 << delta_bits) - 1;
345 int half_max = max_value >> 1;
348 for (
int i = 1;
i < ch->
count;
i++){
351 if (
delta == max_value) {
367 for (
int i = 1;
i < 8;
i++)
371 for (
int i = 0;
i < hfr_group_count;
i++)
375 for (
int i = 0;
i < ch->
count;
i++) {
379 scale =
c->ath[
i] + ((packed_noise_level +
i) >> 8) - ((scale * 5) >> 1) + 2;
392 int *got_frame_ptr,
AVPacket *avpkt)
396 int ch, ret, packed_noise_level;
418 for (ch = 0; ch < avctx->
channels; ch++)
419 unpack(
c, &
c->ch[ch],
c->hfr_group_count, packed_noise_level,
c->ath);
421 for (
int i = 0;
i < 8;
i++) {
422 for (ch = 0; ch < avctx->
channels; ch++)
424 for (ch = 0; ch < avctx->
channels; ch++)
426 c->stereo_band_count +
c->base_band_count,
c->total_band_count);
427 for (ch = 0; ch < avctx->
channels - 1; ch++)
429 c->total_band_count -
c->base_band_count,
430 c->base_band_count,
c->stereo_band_count);
431 for (ch = 0; ch < avctx->
channels; ch++)
static av_cold float ath(float f, float add)
Calculate ATH value for given frequency.
static enum AVSampleFormat sample_fmts[]
Libavcodec external API header.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
static av_cold int init(AVCodecContext *avctx)
#define MKBETAG(a, b, c, d)
Public header for CRC hash function implementation.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static SDL_Window * window
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
static const int8_t quant_spectrum_value[]
static const float quant_step_size[]
static const uint8_t max_bits_table[]
static const int scale_conv_bias
static const uint8_t quant_spectrum_bits[]
static const float scale_conversion_table[]
static const uint8_t scale_table[]
static const uint8_t ath_base_curve[656]
static const float intensity_ratio_table[]
static const float dequantizer_scaling_table[]
static void dequantize_coefficients(HCAContext *c, ChannelContext *ch)
static void unpack(HCAContext *c, ChannelContext *ch, unsigned hfr_group_count, int packed_noise_level, const uint8_t *ath)
static void ath_init1(uint8_t *ath, int sample_rate)
static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
static av_cold int decode_close(AVCodecContext *avctx)
static av_cold int decode_init(AVCodecContext *avctx)
static unsigned ceil2(unsigned a, unsigned b)
static void apply_intensity_stereo(HCAContext *s, ChannelContext *ch1, ChannelContext *ch2, int index, unsigned band_count, unsigned base_band_count, unsigned stereo_band_count)
static int ath_init(uint8_t *ath, int type, int sample_rate)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void reconstruct_hfr(HCAContext *s, ChannelContext *ch, unsigned hfr_group_count, unsigned bands_per_hfr_group, unsigned start_band, unsigned total_band_count)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int8_t scale_factors[128]
uint8_t bands_per_hfr_group
uint8_t stereo_band_count
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets ctx to NULL, does nothing when ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_MDCT
Standard MDCT with sample data type of float and a scale type of float.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static const int factor[16]