50 #define IMC_BLOCK_SIZE 64 51 #define IMC_FRAME_ID 0x21 106 float weights1[31], weights2[31];
111 #define VLC_TABLES_SIZE 9512 114 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
122 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
127 double freqmin[32], freqmid[32], freqmax[32];
128 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
129 double nyquist_freq = sampling_rate * 0.5;
130 double freq, bark, prev_bark = 0, tf, tb;
133 for (i = 0; i < 32; i++) {
138 tb = bark - prev_bark;
139 q->
weights1[i - 1] = pow(10.0, -1.0 * tb);
140 q->
weights2[i - 1] = pow(10.0, -2.7 * tb);
147 while (tf < nyquist_freq) {
159 if (tb <= bark - 0.5)
165 for (i = 0; i < 32; i++) {
167 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
171 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
190 for (j = 0; j < avctx->
channels; j++) {
193 for (i = 0; i <
BANDS; i++)
202 for (i = 0; i <
COEFFS; i++)
204 for (i = 0; i < COEFFS / 2; i++) {
205 q->
post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);
206 q->
post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);
208 r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
209 r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
213 q->
pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
215 q->
pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
222 for (i = 0; i < 30; i++)
226 for (i = 0; i < 4 ; i++) {
227 for (j = 0; j < 4; j++) {
229 huffman_vlc[i][j].
table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
265 float snr_limit = 1.e-30;
269 for (i = 0; i <
BANDS; i++) {
270 flcoeffs5[i] = workT2[i] = 0.0;
272 workT1[i] = flcoeffs1[i] * flcoeffs1[i];
273 flcoeffs3[i] = 2.0 * flcoeffs2[i];
276 flcoeffs3[i] = -30000.0;
278 workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
279 if (workT3[i] <= snr_limit)
283 for (i = 0; i <
BANDS; i++) {
284 for (cnt2 = i; cnt2 < q->
cyclTab[i]; cnt2++)
285 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
286 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
289 for (i = 1; i <
BANDS; i++) {
290 accum = (workT2[i - 1] + accum) * q->
weights1[i - 1];
291 flcoeffs5[i] += accum;
294 for (i = 0; i <
BANDS; i++)
297 for (i = 0; i <
BANDS; i++) {
298 for (cnt2 = i - 1; cnt2 > q->
cyclTab2[i]; cnt2--)
299 flcoeffs5[cnt2] += workT3[i];
300 workT2[cnt2+1] += workT3[i];
305 for (i = BANDS-2; i >= 0; i--) {
306 accum = (workT2[i+1] + accum) * q->
weights2[i];
307 flcoeffs5[i] += accum;
322 s = stream_format_code >> 1;
323 hufftab[0] = &huffman_vlc[s][0];
324 hufftab[1] = &huffman_vlc[s][1];
325 hufftab[2] = &huffman_vlc[s][2];
326 hufftab[3] = &huffman_vlc[s][3];
329 if (stream_format_code & 4)
333 for (i = start; i <
BANDS; i++) {
335 hufftab[cb_sel[i]]->
bits, 2);
336 if (levlCoeffs[i] == 17)
348 for (i = 1; i <
BANDS; i++)
359 flcoeffs1[0] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
360 flcoeffs2[0] =
log2f(flcoeffs1[0]);
364 for (i = 1; i <
BANDS; i++) {
365 level = levlCoeffBuf[i];
372 else if (level <= 24)
378 tmp2 += 0.83048 *
level;
395 for (i = 0; i <
BANDS; i++) {
397 if (levlCoeffBuf[i] < 16) {
398 flcoeffs1[i] =
imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
399 flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i];
401 flcoeffs1[i] = old_floor[i];
413 flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
414 flcoeffs2[pos] =
log2f(flcoeffs1[0]);
415 tmp = flcoeffs1[pos];
416 tmp2 = flcoeffs2[pos];
419 for (i = 0; i <
BANDS; i++) {
422 level = *levlCoeffBuf++;
423 flcoeffs1[i] = tmp *
powf(10.0, -level * 0.4375);
424 flcoeffs2[i] = tmp2 - 1.4533435415 *
level;
432 int stream_format_code,
int freebits,
int flag)
435 const float limit = -1.e20;
444 float lowest = 1.e10;
450 for (i = 0; i <
BANDS; i++)
453 for (i = 0; i < BANDS - 1; i++)
457 highest = highest * 0.25;
459 for (i = 0; i <
BANDS; i++) {
476 if (stream_format_code & 0x2) {
483 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
492 summa = (summa * 0.5 - freebits) / iacc;
495 for (i = 0; i < BANDS / 2; i++) {
496 rres = summer - freebits;
497 if ((rres >= -8) && (rres <= 8))
503 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
504 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
515 if (freebits < summer)
522 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
525 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
530 if (freebits > summer) {
531 for (i = 0; i <
BANDS; i++) {
532 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
539 if (highest <= -1.e20)
545 for (i = 0; i <
BANDS; i++) {
546 if (workT[i] > highest) {
552 if (highest > -1.e20) {
553 workT[found_indx] -= 2.0;
555 workT[found_indx] = -1.e20;
557 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
562 }
while (freebits > summer);
564 if (freebits < summer) {
565 for (i = 0; i <
BANDS; i++) {
569 if (stream_format_code & 0x2) {
575 while (freebits < summer) {
578 for (i = 0; i <
BANDS; i++) {
579 if (workT[i] < lowest) {
586 workT[low_indx] = lowest + 2.0;
589 workT[low_indx] = 1.e20;
591 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
608 for (i = 0; i <
BANDS; i++) {
615 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
646 if (j < band_tab[i + 1]) {
667 for (i = 0; i <
BANDS; i++) {
668 workT[i] = (chctx->
bitsBandT[i] == 6) ? -1.e20
672 while (corrected < summer) {
673 if (highest <= -1.e20)
678 for (i = 0; i <
BANDS; i++) {
679 if (workT[i] > highest) {
685 if (highest > -1.e20) {
686 workT[found_indx] -= 2.0;
687 if (++(chctx->
bitsBandT[found_indx]) == 6)
688 workT[found_indx] = -1.e20;
690 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
708 for (i = 0; i <
COEFFS / 2; i++) {
720 for (i = 0; i <
COEFFS / 2; i++) {
734 int stream_format_code)
737 int middle_value, cw_len, max_size;
738 const float *quantizer;
740 for (i = 0; i <
BANDS; i++) {
748 max_size = 1 << cw_len;
749 middle_value = max_size >> 1;
775 int i, j, cw_len, cw;
777 for (i = 0; i <
BANDS; i++) {
786 av_dlog(
NULL,
"Band %i coeff %i cw_len %i\n", i, j, cw_len);
805 for (i = 0; i <
BANDS; i++) {
811 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
817 for (i = 0; i <
BANDS; i++) {
829 for (i = 0; i <
BANDS; i++) {
846 int stream_format_code;
847 int imc_hdr, i, j, ret;
850 int counter, bitscount;
856 if (imc_hdr & 0x18) {
863 if (stream_format_code & 0x04)
867 for (i = 0; i <
BANDS; i++)
875 if (stream_format_code & 0x1)
880 if (stream_format_code & 0x1)
883 else if (stream_format_code & 0x4)
893 if (stream_format_code & 0x1) {
894 for (i = 0; i <
BANDS; i++) {
901 for (i = 0; i <
BANDS; i++) {
910 for (i = 0; i < BANDS - 1; i++)
921 if (stream_format_code & 0x2) {
928 for (i = 1; i < 4; i++) {
929 if (stream_format_code & 0x1)
942 if (!(stream_format_code & 0x2))
954 if (stream_format_code & 0x1) {
955 for (i = 0; i <
BANDS; i++)
961 for (i = 0; i <
BANDS; i++) {
991 int *got_frame_ptr,
AVPacket *avpkt)
995 int buf_size = avpkt->
size;
1002 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
1014 for (i = 0; i < avctx->
channels; i++) {
int skipFlags[COEFFS]
skip coefficient decoding or not
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
int codewords[COEFFS]
raw codewords read from bitstream
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
static const int vlc_offsets[17]
float mdct_sine_window[COEFFS]
MDCT tables.
#define DECLARE_ALIGNED(n, t, v)
static const uint8_t imc_huffman_lens[4][4][18]
int skipFlagCount[BANDS]
skipped coeffients per band
static const float imc_weights2[31]
#define AV_CH_LAYOUT_STEREO
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
enum AVSampleFormat sample_fmt
audio sample format
int bandFlagsBuf[BANDS]
flags for each band
static av_cold int imc_decode_close(AVCodecContext *avctx)
static const int8_t cyclTab[32]
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int get_bits_count(const GetBitContext *s)
static const float imc_weights1[31]
bitstream reader API header.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
static const float *const imc_exp_tab2
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
void av_log(void *avcl, int level, const char *fmt,...)
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
const char * name
Name of the codec implementation.
uint64_t channel_layout
Audio channel layout.
static const int8_t cyclTab2[32]
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
static int imc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
audio channel layout utility functions
static const uint16_t band_tab[33]
static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx)
int bitsBandT[BANDS]
how many bits per codeword in band
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define INIT_VLC_USE_NEW_STATIC
float last_fft_im[COEFFS]
if(ac->has_optimized_func)
void ff_sine_window_init(float *window, int n)
Generate a sine window.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
#define AV_LOG_INFO
Standard information.
static const float xTab[14]
FFTComplex samples[COEFFS/2]
Libavcodec external API header.
AVSampleFormat
Audio Sample Formats.
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static double freq2bark(double freq)
static unsigned int get_bits1(GetBitContext *s)
int bandWidthT[BANDS]
codewords per band
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static VLC huffman_vlc[4][4]
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]
static const float imc_quantizer1[4][8]
av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
common internal api header.
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
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 init(AVCodecParserContext *s)
static const uint8_t imc_cb_select[4][32]
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
#define LOCAL_ALIGNED_16(t, v,...)
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 const float imc_quantizer2[2][56]
int sumLenArr[BANDS]
bits for all coeffs in band
static const uint8_t imc_huffman_sizes[4]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
This structure stores compressed data.
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
int skipFlagBits[BANDS]
bits used to code skip flags
static av_cold int imc_decode_init(AVCodecContext *avctx)
int nb_samples
number of audio samples (per channel) described by this frame
static const float imc_exp_tab[32]
static const uint16_t imc_huffman_bits[4][4][18]
int CWlengthT[COEFFS]
how many bits in each codeword