53 #define IMC_BLOCK_SIZE 64
54 #define IMC_FRAME_ID 0x21
116 #define IMC_VLC_BITS 9
117 #define VLC_TABLES_SIZE 9512
123 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
128 double freqmin[32], freqmid[32], freqmax[32];
129 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
130 double nyquist_freq = sampling_rate * 0.5;
131 double freq, bark, prev_bark = 0,
tf,
tb;
134 for (
i = 0;
i < 32;
i++) {
139 tb = bark - prev_bark;
148 while (
tf < nyquist_freq) {
160 if (
tb <= bark - 0.5)
166 for (
i = 0;
i < 32;
i++) {
168 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
172 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
180 for (
int i = 0,
offset = 0;
i < 4 ;
i++) {
181 for (
int j = 0; j < 4; j++) {
203 "Strange sample rate of %i, file likely corrupt or "
204 "needing a new table derivation method.\n",
217 for (j = 0; j < avctx->
channels; j++) {
235 r1 = sin((
i * 4.0 + 1.0) / 1024.0 *
M_PI);
236 r2 = cos((
i * 4.0 + 1.0) / 1024.0 *
M_PI);
249 for (
i = 0;
i < 30;
i++)
282 float *flcoeffs2,
int *bandWidthT,
283 float *flcoeffs3,
float *flcoeffs5)
288 float snr_limit = 1.e-30;
293 flcoeffs5[
i] = workT2[
i] = 0.0;
295 workT1[
i] = flcoeffs1[
i] * flcoeffs1[
i];
296 flcoeffs3[
i] = 2.0 * flcoeffs2[
i];
299 flcoeffs3[
i] = -30000.0;
301 workT3[
i] = bandWidthT[
i] * workT1[
i] * 0.01;
302 if (workT3[
i] <= snr_limit)
307 for (cnt2 =
i; cnt2 < q->
cyclTab[
i]; cnt2++)
308 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[
i];
309 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[
i];
313 accum = (workT2[
i - 1] + accum) * q->
weights1[
i - 1];
314 flcoeffs5[
i] += accum;
321 for (cnt2 =
i - 1; cnt2 > q->
cyclTab2[
i]; cnt2--)
322 flcoeffs5[cnt2] += workT3[
i];
323 workT2[cnt2+1] += workT3[
i];
329 accum = (workT2[
i+1] + accum) * q->
weights2[
i];
330 flcoeffs5[
i] += accum;
345 s = stream_format_code >> 1;
352 if (stream_format_code & 4)
359 if (levlCoeffs[
i] == 17)
376 float *flcoeffs1,
float *flcoeffs2)
382 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
383 flcoeffs2[0] =
log2f(flcoeffs1[0]);
395 else if (
level <= 24)
401 tmp2 += 0.83048 *
level;
410 float *old_floor,
float *flcoeffs1,
420 if (levlCoeffBuf[
i] < 16) {
422 flcoeffs2[
i] = (levlCoeffBuf[
i] - 7) * 0.83048 + flcoeffs2[
i];
424 flcoeffs1[
i] = old_floor[
i];
430 float *flcoeffs1,
float *flcoeffs2)
436 flcoeffs1[
pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
439 tmp2 = flcoeffs2[
pos];
445 level = *levlCoeffBuf++;
447 flcoeffs2[
i] = tmp2 - 1.4533435415 *
level;
455 int stream_format_code,
int freebits,
int flag)
458 const float limit = -1.e20;
467 float lowest = 1.e10;
485 highest = highest * 0.25;
504 if (stream_format_code & 0x2) {
511 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS - 1;
i++) {
520 summa = (summa * 0.5 - freebits) / iacc;
524 rres = summer - freebits;
525 if ((rres >= -8) && (rres <= 8))
531 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
543 if (freebits < summer)
550 summa = (float)(summer - freebits) / ((
t1 + 1) * iacc) + summa;
553 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS;
i++) {
558 if (freebits > summer) {
567 if (highest <= -1.e20)
574 if (workT[
i] > highest) {
580 if (highest > -1.e20) {
581 workT[found_indx] -= 2.0;
583 workT[found_indx] = -1.e20;
585 for (j =
band_tab[found_indx]; j <
band_tab[found_indx + 1] && (freebits > summer); j++) {
590 }
while (freebits > summer);
592 if (freebits < summer) {
597 if (stream_format_code & 0x2) {
603 while (freebits < summer) {
607 if (workT[
i] < lowest) {
614 workT[low_indx] = lowest + 2.0;
617 workT[low_indx] = 1.e20;
619 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
700 while (corrected < summer) {
701 if (highest <= -1.e20)
707 if (workT[
i] > highest) {
713 if (highest > -1.e20) {
714 workT[found_indx] -= 2.0;
715 if (++(chctx->
bitsBandT[found_indx]) == 6)
716 workT[found_indx] = -1.e20;
718 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
762 int stream_format_code)
765 int middle_value, cw_len, max_size;
766 const float *quantizer;
773 if (cw_len <= 0 || chctx->skipFlags[j])
776 max_size = 1 << cw_len;
777 middle_value = max_size >> 1;
804 int i, j, cw_len, cw;
817 "Potential problem on band %i, coefficient %i"
818 ": cw_len=%i\n",
i, j, cw_len);
875 int stream_format_code;
876 int imc_hdr,
i, j, ret;
879 int counter, bitscount;
885 if (imc_hdr & 0x18) {
892 if (stream_format_code & 0x04)
904 if (stream_format_code & 0x1)
909 if (stream_format_code & 0x1)
912 else if (stream_format_code & 0x4)
929 if (stream_format_code & 0x1) {
957 if (stream_format_code & 0x2) {
964 for (
i = 1;
i < 4;
i++) {
965 if (stream_format_code & 0x1)
978 if (!(stream_format_code & 0x2))
990 if (stream_format_code & 0x1) {
1023 int *got_frame_ptr,
AVPacket *avpkt)
1027 int buf_size = avpkt->
size;
1036 if (buf_size < IMC_BLOCK_SIZE * avctx->
channels) {
1086 #if CONFIG_IMC_DECODER
1103 #if CONFIG_IAC_DECODER
static enum AVSampleFormat sample_fmts[]
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
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()
audio channel layout utility functions
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)
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static unsigned int get_bits1(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#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.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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 int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
static VLC huffman_vlc[4][4]
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
static av_cold int imc_decode_close(AVCodecContext *avctx)
static int bit_allocation(IMCContext *q, IMCChannel *chctx, int stream_format_code, int freebits, int flag)
Perform bit allocation depending on bits available.
static av_cold int imc_decode_init(AVCodecContext *avctx)
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
static av_cold void flush(AVCodecContext *avctx)
static double freq2bark(double freq)
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
static av_cold void imc_init_static(void)
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, int summer)
Increase highest' band coefficient sizes as some bits won't be used.
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
static int imc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static const int8_t cyclTab[32]
static const float imc_quantizer2[2][56]
static const float xTab[14]
static const float *const imc_exp_tab2
static const float imc_quantizer1[4][8]
static const uint8_t imc_huffman_syms[4][4][18]
static const uint8_t imc_huffman_lens[4][4][18]
static const uint8_t imc_cb_select[4][32]
static const float imc_exp_tab[32]
static const float imc_weights2[31]
static const int8_t cyclTab2[32]
static const uint8_t imc_huffman_sizes[4]
static const uint16_t band_tab[33]
static const float imc_weights1[31]
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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.
static int ff_thread_once(char *control, void(*routine)(void))
#define LOCAL_ALIGNED_16(t, v,...)
typedef void(RENAME(mix_any_func_type))
void ff_sine_window_init(float *window, int n)
Generate a sine window.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int flags
AV_CODEC_FLAG_*.
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
const char * name
Name of the codec implementation.
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
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.
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
float last_fft_im[COEFFS]
int codewords[COEFFS]
raw codewords read from bitstream
int skipFlagBits[BANDS]
bits used to code skip flags
int CWlengthT[COEFFS]
how many bits in each codeword
int skipFlags[COEFFS]
skip coefficient decoding or not
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
int bandFlagsBuf[BANDS]
flags for each band
int bandWidthT[BANDS]
codewords per band
int skipFlagCount[BANDS]
skipped coefficients per band
int bitsBandT[BANDS]
how many bits per codeword in band
int sumLenArr[BANDS]
bits for all coeffs in band
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
FFTComplex samples[COEFFS/2]
float mdct_sine_window[COEFFS]
MDCT tables.
VLC_TYPE(* table)[2]
code, bits
#define avpriv_request_sample(...)
static const uint8_t offset[127][2]
#define INIT_VLC_STATIC_OVERLONG