51 #define IMC_BLOCK_SIZE 64 52 #define IMC_FRAME_ID 0x21 105 float weights1[31], weights2[31];
110 #define VLC_TABLES_SIZE 9512 113 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
121 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
126 double freqmin[32], freqmid[32], freqmax[32];
127 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
128 double nyquist_freq = sampling_rate * 0.5;
129 double freq, bark, prev_bark = 0,
tf,
tb;
132 for (i = 0; i < 32; i++) {
137 tb = bark - prev_bark;
138 q->weights1[i - 1] = pow(10.0, -1.0 * tb);
139 q->weights2[i - 1] = pow(10.0, -2.7 * tb);
146 while (
tf < nyquist_freq) {
158 if (tb <= bark - 0.5)
164 for (i = 0; i < 32; i++) {
166 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
167 q->cyclTab[
i] = j + 1;
170 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
171 q->cyclTab2[
i] = j - 1;
189 for (j = 0; j < avctx->
channels; j++) {
192 for (i = 0; i <
BANDS; i++)
201 for (i = 0; i <
COEFFS; i++)
203 for (i = 0; i < COEFFS / 2; i++) {
207 r1 = sin((i * 4.0 + 1.0) / 1024.0 *
M_PI);
208 r2 = cos((i * 4.0 + 1.0) / 1024.0 *
M_PI);
221 for (i = 0; i < 30; i++)
225 for (i = 0; i < 4 ; i++) {
226 for (j = 0; j < 4; j++) {
228 huffman_vlc[
i][j].
table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
264 float snr_limit = 1.e-30;
268 for (i = 0; i <
BANDS; i++) {
269 flcoeffs5[
i] = workT2[
i] = 0.0;
271 workT1[
i] = flcoeffs1[
i] * flcoeffs1[
i];
272 flcoeffs3[
i] = 2.0 * flcoeffs2[
i];
275 flcoeffs3[
i] = -30000.0;
277 workT3[
i] = bandWidthT[
i] * workT1[
i] * 0.01;
278 if (workT3[i] <= snr_limit)
282 for (i = 0; i <
BANDS; i++) {
283 for (cnt2 = i; cnt2 < q->cyclTab[
i]; cnt2++)
284 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
285 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[
i];
288 for (i = 1; i <
BANDS; i++) {
289 accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
290 flcoeffs5[i] += accum;
293 for (i = 0; i <
BANDS; i++)
296 for (i = 0; i <
BANDS; i++) {
297 for (cnt2 = i - 1; cnt2 > q->cyclTab2[
i]; cnt2--)
298 flcoeffs5[cnt2] += workT3[i];
299 workT2[cnt2+1] += workT3[
i];
304 for (i = BANDS-2; i >= 0; i--) {
305 accum = (workT2[i+1] + accum) * q->weights2[i];
306 flcoeffs5[i] += accum;
321 s = stream_format_code >> 1;
322 hufftab[0] = &huffman_vlc[
s][0];
323 hufftab[1] = &huffman_vlc[
s][1];
324 hufftab[2] = &huffman_vlc[
s][2];
325 hufftab[3] = &huffman_vlc[
s][3];
328 if (stream_format_code & 4)
332 for (i = start; i <
BANDS; i++) {
334 hufftab[cb_sel[i]]->
bits, 2);
335 if (levlCoeffs[i] == 17)
347 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
348 flcoeffs2[0] =
log2f(flcoeffs1[0]);
352 for (i = 1; i <
BANDS; i++) {
353 level = levlCoeffBuf[
i];
360 else if (level <= 24)
366 tmp2 += 0.83048 *
level;
383 for (i = 0; i <
BANDS; i++) {
385 if (levlCoeffBuf[i] < 16) {
387 flcoeffs2[
i] = (levlCoeffBuf[
i] - 7) * 0.83048 + flcoeffs2[i];
389 flcoeffs1[
i] = old_floor[
i];
398 int stream_format_code,
int freebits,
int flag)
401 const float limit = -1.e20;
410 float lowest = 1.e10;
416 for (i = 0; i <
BANDS; i++)
419 for (i = 0; i < BANDS - 1; i++)
423 highest = highest * 0.25;
425 for (i = 0; i <
BANDS; i++) {
442 if (stream_format_code & 0
x2) {
449 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
454 summa = (summa * 0.5 - freebits) / iacc;
457 for (i = 0; i < BANDS / 2; i++) {
458 rres = summer - freebits;
459 if ((rres >= -8) && (rres <= 8))
465 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
466 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
477 if (freebits < summer)
484 summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
487 for (i = (stream_format_code & 0x2) ? 4 : 0; i <
BANDS; i++) {
492 if (freebits > summer) {
493 for (i = 0; i <
BANDS; i++) {
501 if (highest <= -1.e20)
507 for (i = 0; i <
BANDS; i++) {
508 if (workT[i] > highest) {
514 if (highest > -1.e20) {
515 workT[found_indx] -= 2.0;
517 workT[found_indx] = -1.e20;
519 for (j =
band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
524 }
while (freebits > summer);
526 if (freebits < summer) {
527 for (i = 0; i <
BANDS; i++) {
531 if (stream_format_code & 0x2) {
537 while (freebits < summer) {
540 for (i = 0; i <
BANDS; i++) {
541 if (workT[i] < lowest) {
548 workT[low_indx] = lowest + 2.0;
551 workT[low_indx] = 1.e20;
553 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
570 for (i = 0; i <
BANDS; i++) {
577 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
608 if (j < band_tab[i + 1]) {
629 for (i = 0; i <
BANDS; i++) {
634 while (corrected < summer) {
635 if (highest <= -1.e20)
640 for (i = 0; i <
BANDS; i++) {
641 if (workT[i] > highest) {
647 if (highest > -1.e20) {
648 workT[found_indx] -= 2.0;
649 if (++(chctx->
bitsBandT[found_indx]) == 6)
650 workT[found_indx] = -1.e20;
652 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
666 float *dst1 = q->out_samples;
667 float *dst2 = q->out_samples + (
COEFFS - 1);
670 for (i = 0; i <
COEFFS / 2; i++) {
682 for (i = 0; i <
COEFFS / 2; i++) {
696 int stream_format_code)
699 int middle_value, cw_len, max_size;
700 const float *quantizer;
702 for (i = 0; i <
BANDS; i++) {
710 max_size = 1 << cw_len;
711 middle_value = max_size >> 1;
737 int i, j, cw_len, cw;
739 for (i = 0; i <
BANDS; i++) {
748 av_dlog(
NULL,
"Band %i coeff %i cw_len %i\n", i, j, cw_len);
764 int stream_format_code;
765 int imc_hdr,
i, j,
ret;
768 int counter, bitscount;
774 if (imc_hdr & 0x18) {
781 if (stream_format_code & 1) {
786 if (stream_format_code & 0x04)
790 for (i = 0; i <
BANDS; i++)
800 if (stream_format_code & 0
x4)
807 for(i=0; i<
BANDS; i++) {
817 for (i = 0; i <
BANDS; i++) {
825 for (i = 0; i < BANDS - 1; i++) {
834 if (stream_format_code & 0
x2) {
841 for (i = 1; i < 4; i++) {
852 if (!(stream_format_code & 0x2))
864 for (i = 0; i <
BANDS; i++) {
870 if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->
sumLenArr[i]) && (chctx->
sumLenArr[i] > 0))
876 for (i = 0; i <
BANDS; i++) {
888 for (i = 0; i <
BANDS; i++) {
902 for (i = 0; i <
BANDS; i++) {
932 int *got_frame_ptr,
AVPacket *avpkt)
936 int buf_size = avpkt->
size;
943 if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
953 for (i = 0; i < avctx->
channels; i++) {
994 #if CONFIG_IMC_DECODER 1010 #if CONFIG_IAC_DECODER int skipFlags[COEFFS]
skip coefficient decoding or not
struct IMCChannel IMCChannel
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
#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
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 av_cold int init(AVCodecContext *avctx)
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]
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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)
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
#define AV_CH_LAYOUT_STEREO
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
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)
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
static const float *const imc_exp_tab2
#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]
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
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.
FIXME Range Coding of cr are level
#define INIT_VLC_USE_NEW_STATIC
float last_fft_im[COEFFS]
void ff_sine_window_init(float *window, int n)
Generate a sine window.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static const float xTab[14]
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static double freq2bark(double freq)
Replacements for frequently missing libm functions.
static unsigned int get_bits1(GetBitContext *s)
int bandWidthT[BANDS]
codewords per band
static av_cold void flush(AVCodecContext *avctx)
synthesis window for stochastic i
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]
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)
AVSampleFormat
Audio Sample Formats.
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 const uint8_t imc_cb_select[4][32]
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
Filter the word “frame” indicates either a video frame or a group of audio samples
#define LOCAL_ALIGNED_16(t, v,...)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static const uint8_t imc_huffman_sizes[4]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
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