2006-10-30 13:48:48 +00:00
|
|
|
/*
|
|
|
|
* IMC compatible decoder
|
|
|
|
* Copyright (c) 2002-2004 Maxim Poliakovski
|
|
|
|
* Copyright (c) 2006 Benjamin Larsson
|
|
|
|
* Copyright (c) 2006 Konstantin Shishkov
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
|
|
|
* IMC - Intel Music Coder
|
2006-10-30 13:48:48 +00:00
|
|
|
* A mdct based codec using a 256 points large transform
|
2012-05-20 11:55:33 +00:00
|
|
|
* divided into 32 bands with some mix of scale factors.
|
2006-10-30 13:48:48 +00:00
|
|
|
* Only mono is supported.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-10 15:00:00 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2013-01-20 23:41:14 +00:00
|
|
|
#include "libavutil/float_dsp.h"
|
2013-02-07 23:31:13 +00:00
|
|
|
#include "libavutil/internal.h"
|
2012-11-12 10:32:11 +00:00
|
|
|
#include "libavutil/libm.h"
|
2006-10-30 13:48:48 +00:00
|
|
|
#include "avcodec.h"
|
2014-02-13 16:57:05 +00:00
|
|
|
#include "bswapdsp.h"
|
2009-04-13 16:20:26 +00:00
|
|
|
#include "get_bits.h"
|
2010-03-06 14:34:46 +00:00
|
|
|
#include "fft.h"
|
2012-11-10 12:22:56 +00:00
|
|
|
#include "internal.h"
|
2011-03-19 23:44:00 +00:00
|
|
|
#include "sinewin.h"
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
#include "imcdata.h"
|
|
|
|
|
2008-02-02 08:26:49 +00:00
|
|
|
#define IMC_BLOCK_SIZE 64
|
2006-10-30 13:48:48 +00:00
|
|
|
#define IMC_FRAME_ID 0x21
|
|
|
|
#define BANDS 32
|
|
|
|
#define COEFFS 256
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
typedef struct IMCChannel {
|
2006-10-30 13:48:48 +00:00
|
|
|
float old_floor[BANDS];
|
|
|
|
float flcoeffs1[BANDS];
|
|
|
|
float flcoeffs2[BANDS];
|
|
|
|
float flcoeffs3[BANDS];
|
|
|
|
float flcoeffs4[BANDS];
|
|
|
|
float flcoeffs5[BANDS];
|
|
|
|
float flcoeffs6[BANDS];
|
|
|
|
float CWdecoded[COEFFS];
|
|
|
|
|
|
|
|
int bandWidthT[BANDS]; ///< codewords per band
|
|
|
|
int bitsBandT[BANDS]; ///< how many bits per codeword in band
|
|
|
|
int CWlengthT[COEFFS]; ///< how many bits in each codeword
|
|
|
|
int levlCoeffBuf[BANDS];
|
|
|
|
int bandFlagsBuf[BANDS]; ///< flags for each band
|
|
|
|
int sumLenArr[BANDS]; ///< bits for all coeffs in band
|
|
|
|
int skipFlagRaw[BANDS]; ///< skip flags are stored in raw form or not
|
|
|
|
int skipFlagBits[BANDS]; ///< bits used to code skip flags
|
|
|
|
int skipFlagCount[BANDS]; ///< skipped coeffients per band
|
|
|
|
int skipFlags[COEFFS]; ///< skip coefficient decoding or not
|
|
|
|
int codewords[COEFFS]; ///< raw codewords read from bitstream
|
2012-06-02 18:30:23 +00:00
|
|
|
|
|
|
|
float last_fft_im[COEFFS];
|
|
|
|
|
|
|
|
int decoder_reset;
|
|
|
|
} IMCChannel;
|
|
|
|
|
|
|
|
typedef struct {
|
2012-06-02 19:07:02 +00:00
|
|
|
IMCChannel chctx[2];
|
2012-06-02 18:30:23 +00:00
|
|
|
|
|
|
|
/** MDCT tables */
|
|
|
|
//@{
|
|
|
|
float mdct_sine_window[COEFFS];
|
|
|
|
float post_cos[COEFFS];
|
|
|
|
float post_sin[COEFFS];
|
|
|
|
float pre_coef1[COEFFS];
|
|
|
|
float pre_coef2[COEFFS];
|
|
|
|
//@}
|
|
|
|
|
2006-10-30 13:48:48 +00:00
|
|
|
float sqrt_tab[30];
|
|
|
|
GetBitContext gb;
|
|
|
|
|
2014-02-13 16:57:05 +00:00
|
|
|
BswapDSPContext bdsp;
|
2013-01-20 23:41:14 +00:00
|
|
|
AVFloatDSPContext fdsp;
|
2006-10-30 13:48:48 +00:00
|
|
|
FFTContext fft;
|
2012-05-22 17:45:00 +00:00
|
|
|
DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS / 2];
|
2010-07-16 16:50:56 +00:00
|
|
|
float *out_samples;
|
2012-06-02 19:07:02 +00:00
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
int coef0_pos;
|
|
|
|
|
2012-06-02 19:07:02 +00:00
|
|
|
int8_t cyclTab[32], cyclTab2[32];
|
|
|
|
float weights1[31], weights2[31];
|
2006-10-30 13:48:48 +00:00
|
|
|
} IMCContext;
|
|
|
|
|
2008-07-12 15:02:40 +00:00
|
|
|
static VLC huffman_vlc[4][4];
|
|
|
|
|
|
|
|
#define VLC_TABLES_SIZE 9512
|
|
|
|
|
|
|
|
static const int vlc_offsets[17] = {
|
|
|
|
0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
|
2012-05-22 17:45:00 +00:00
|
|
|
4452, 5220, 5860, 6628, 7268, 7908, 8424, 8936, VLC_TABLES_SIZE
|
|
|
|
};
|
2008-07-12 15:02:40 +00:00
|
|
|
|
|
|
|
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2];
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-08 17:34:46 +00:00
|
|
|
static inline double freq2bark(double freq)
|
|
|
|
{
|
|
|
|
return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
|
|
|
|
{
|
|
|
|
double freqmin[32], freqmid[32], freqmax[32];
|
|
|
|
double scale = sampling_rate / (256.0 * 2.0 * 2.0);
|
|
|
|
double nyquist_freq = sampling_rate * 0.5;
|
|
|
|
double freq, bark, prev_bark = 0, tf, tb;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
freq = (band_tab[i] + band_tab[i + 1] - 1) * scale;
|
|
|
|
bark = freq2bark(freq);
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
tb = bark - prev_bark;
|
|
|
|
q->weights1[i - 1] = pow(10.0, -1.0 * tb);
|
|
|
|
q->weights2[i - 1] = pow(10.0, -2.7 * tb);
|
|
|
|
}
|
|
|
|
prev_bark = bark;
|
|
|
|
|
|
|
|
freqmid[i] = freq;
|
|
|
|
|
|
|
|
tf = freq;
|
|
|
|
while (tf < nyquist_freq) {
|
|
|
|
tf += 0.5;
|
|
|
|
tb = freq2bark(tf);
|
|
|
|
if (tb > bark + 0.5)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
freqmax[i] = tf;
|
|
|
|
|
|
|
|
tf = freq;
|
|
|
|
while (tf > 0.0) {
|
|
|
|
tf -= 0.5;
|
|
|
|
tb = freq2bark(tf);
|
|
|
|
if (tb <= bark - 0.5)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
freqmin[i] = tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
freq = freqmax[i];
|
|
|
|
for (j = 31; j > 0 && freq <= freqmid[j]; j--);
|
|
|
|
q->cyclTab[i] = j + 1;
|
|
|
|
|
|
|
|
freq = freqmin[i];
|
|
|
|
for (j = 0; j < 32 && freq >= freqmid[j]; j++);
|
|
|
|
q->cyclTab2[i] = j - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
static av_cold int imc_decode_init(AVCodecContext *avctx)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
2011-10-28 22:25:49 +00:00
|
|
|
int i, j, ret;
|
2006-10-30 13:48:48 +00:00
|
|
|
IMCContext *q = avctx->priv_data;
|
|
|
|
double r1, r2;
|
|
|
|
|
2012-10-22 19:54:29 +00:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_IMC)
|
|
|
|
avctx->channels = 1;
|
|
|
|
|
|
|
|
if (avctx->channels > 2) {
|
2013-03-13 20:17:05 +00:00
|
|
|
avpriv_request_sample(avctx, "Number of channels > 2");
|
2011-10-28 22:31:21 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
for (j = 0; j < avctx->channels; j++) {
|
|
|
|
q->chctx[j].decoder_reset = 1;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
for (i = 0; i < BANDS; i++)
|
|
|
|
q->chctx[j].old_floor[i] = 1.0;
|
|
|
|
|
|
|
|
for (i = 0; i < COEFFS / 2; i++)
|
|
|
|
q->chctx[j].last_fft_im[i] = 0;
|
|
|
|
}
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
/* Build mdct window, a simple sine window normalized with sqrt(2) */
|
2008-06-22 15:12:27 +00:00
|
|
|
ff_sine_window_init(q->mdct_sine_window, COEFFS);
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < COEFFS; i++)
|
2008-06-22 15:12:27 +00:00
|
|
|
q->mdct_sine_window[i] *= sqrt(2.0);
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < COEFFS / 2; i++) {
|
2010-07-16 16:50:56 +00:00
|
|
|
q->post_cos[i] = (1.0f / 32768) * cos(i / 256.0 * M_PI);
|
|
|
|
q->post_sin[i] = (1.0f / 32768) * sin(i / 256.0 * M_PI);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
r1 = sin((i * 4.0 + 1.0) / 1024.0 * M_PI);
|
|
|
|
r2 = cos((i * 4.0 + 1.0) / 1024.0 * M_PI);
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
if (i & 0x1) {
|
2006-10-30 13:48:48 +00:00
|
|
|
q->pre_coef1[i] = (r1 + r2) * sqrt(2.0);
|
|
|
|
q->pre_coef2[i] = -(r1 - r2) * sqrt(2.0);
|
2012-05-22 17:45:00 +00:00
|
|
|
} else {
|
2006-10-30 13:48:48 +00:00
|
|
|
q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
|
|
|
|
q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate a square root table */
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < 30; i++)
|
2006-10-30 13:48:48 +00:00
|
|
|
q->sqrt_tab[i] = sqrt(i);
|
|
|
|
|
|
|
|
/* initialize the VLC tables */
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < 4 ; i++) {
|
|
|
|
for (j = 0; j < 4; j++) {
|
2008-11-16 10:16:07 +00:00
|
|
|
huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]];
|
2008-07-12 15:02:40 +00:00
|
|
|
huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
|
|
|
|
init_vlc(&huffman_vlc[i][j], 9, imc_huffman_sizes[i],
|
2006-10-30 13:48:48 +00:00
|
|
|
imc_huffman_lens[i][j], 1, 1,
|
2008-07-12 15:02:40 +00:00
|
|
|
imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 17:34:46 +00:00
|
|
|
|
2012-08-05 09:11:04 +00:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_IAC) {
|
2012-06-08 17:34:46 +00:00
|
|
|
iac_generate_tabs(q, avctx->sample_rate);
|
2012-06-02 19:07:02 +00:00
|
|
|
} else {
|
2012-06-08 17:34:46 +00:00
|
|
|
memcpy(q->cyclTab, cyclTab, sizeof(cyclTab));
|
|
|
|
memcpy(q->cyclTab2, cyclTab2, sizeof(cyclTab2));
|
2012-06-02 19:07:02 +00:00
|
|
|
memcpy(q->weights1, imc_weights1, sizeof(imc_weights1));
|
|
|
|
memcpy(q->weights2, imc_weights2, sizeof(imc_weights2));
|
|
|
|
}
|
|
|
|
|
2011-10-28 22:25:49 +00:00
|
|
|
if ((ret = ff_fft_init(&q->fft, 7, 1))) {
|
|
|
|
av_log(avctx, AV_LOG_INFO, "FFT init failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-13 16:57:05 +00:00
|
|
|
ff_bswapdsp_init(&q->bdsp);
|
2013-01-20 23:41:14 +00:00
|
|
|
avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
|
2012-08-27 16:58:25 +00:00
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
2012-06-02 18:30:23 +00:00
|
|
|
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
|
|
|
|
: AV_CH_LAYOUT_STEREO;
|
2011-09-06 16:17:45 +00:00
|
|
|
|
2006-10-30 13:48:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1,
|
|
|
|
float *flcoeffs2, int *bandWidthT,
|
|
|
|
float *flcoeffs3, float *flcoeffs5)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
|
|
|
float workT1[BANDS];
|
|
|
|
float workT2[BANDS];
|
|
|
|
float workT3[BANDS];
|
|
|
|
float snr_limit = 1.e-30;
|
|
|
|
float accum = 0.0;
|
|
|
|
int i, cnt2;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs5[i] = workT2[i] = 0.0;
|
2012-05-22 17:45:00 +00:00
|
|
|
if (bandWidthT[i]) {
|
2006-10-30 13:48:48 +00:00
|
|
|
workT1[i] = flcoeffs1[i] * flcoeffs1[i];
|
|
|
|
flcoeffs3[i] = 2.0 * flcoeffs2[i];
|
|
|
|
} else {
|
2012-05-22 17:45:00 +00:00
|
|
|
workT1[i] = 0.0;
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs3[i] = -30000.0;
|
|
|
|
}
|
|
|
|
workT3[i] = bandWidthT[i] * workT1[i] * 0.01;
|
|
|
|
if (workT3[i] <= snr_limit)
|
|
|
|
workT3[i] = 0.0;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 19:07:02 +00:00
|
|
|
for (cnt2 = i; cnt2 < q->cyclTab[i]; cnt2++)
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[i];
|
2012-05-22 17:45:00 +00:00
|
|
|
workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 1; i < BANDS; i++) {
|
2012-06-02 19:07:02 +00:00
|
|
|
accum = (workT2[i - 1] + accum) * q->weights1[i - 1];
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs5[i] += accum;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++)
|
2006-10-30 13:48:48 +00:00
|
|
|
workT2[i] = 0.0;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 19:07:02 +00:00
|
|
|
for (cnt2 = i - 1; cnt2 > q->cyclTab2[i]; cnt2--)
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs5[cnt2] += workT3[i];
|
|
|
|
workT2[cnt2+1] += workT3[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
accum = 0.0;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = BANDS-2; i >= 0; i--) {
|
2012-06-02 19:07:02 +00:00
|
|
|
accum = (workT2[i+1] + accum) * q->weights2[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs5[i] += accum;
|
2012-05-22 17:45:00 +00:00
|
|
|
// there is missing code here, but it seems to never be triggered
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code,
|
|
|
|
int *levlCoeffs)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
VLC *hufftab[4];
|
|
|
|
int start = 0;
|
|
|
|
const uint8_t *cb_sel;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = stream_format_code >> 1;
|
2008-07-12 15:02:40 +00:00
|
|
|
hufftab[0] = &huffman_vlc[s][0];
|
|
|
|
hufftab[1] = &huffman_vlc[s][1];
|
|
|
|
hufftab[2] = &huffman_vlc[s][2];
|
|
|
|
hufftab[3] = &huffman_vlc[s][3];
|
2006-10-30 13:48:48 +00:00
|
|
|
cb_sel = imc_cb_select[s];
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
if (stream_format_code & 4)
|
2006-10-30 13:48:48 +00:00
|
|
|
start = 1;
|
2012-05-22 17:45:00 +00:00
|
|
|
if (start)
|
2006-10-30 13:48:48 +00:00
|
|
|
levlCoeffs[0] = get_bits(&q->gb, 7);
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = start; i < BANDS; i++) {
|
|
|
|
levlCoeffs[i] = get_vlc2(&q->gb, hufftab[cb_sel[i]]->table,
|
|
|
|
hufftab[cb_sel[i]]->bits, 2);
|
|
|
|
if (levlCoeffs[i] == 17)
|
2006-10-30 13:48:48 +00:00
|
|
|
levlCoeffs[i] += get_bits(&q->gb, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code,
|
|
|
|
int *levlCoeffs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
q->coef0_pos = get_bits(&q->gb, 5);
|
|
|
|
levlCoeffs[0] = get_bits(&q->gb, 7);
|
|
|
|
for (i = 1; i < BANDS; i++)
|
|
|
|
levlCoeffs[i] = get_bits(&q->gb, 4);
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf,
|
|
|
|
float *flcoeffs1, float *flcoeffs2)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
|
|
|
int i, level;
|
|
|
|
float tmp, tmp2;
|
2012-05-22 17:45:00 +00:00
|
|
|
// maybe some frequency division thingy
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-09-09 10:58:43 +00:00
|
|
|
flcoeffs1[0] = 20000.0 / exp2 (levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
|
2012-08-05 21:22:10 +00:00
|
|
|
flcoeffs2[0] = log2f(flcoeffs1[0]);
|
2012-05-22 17:45:00 +00:00
|
|
|
tmp = flcoeffs1[0];
|
2006-10-30 13:48:48 +00:00
|
|
|
tmp2 = flcoeffs2[0];
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 1; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
level = levlCoeffBuf[i];
|
|
|
|
if (level == 16) {
|
|
|
|
flcoeffs1[i] = 1.0;
|
|
|
|
flcoeffs2[i] = 0.0;
|
|
|
|
} else {
|
|
|
|
if (level < 17)
|
2012-05-22 17:45:00 +00:00
|
|
|
level -= 7;
|
2006-10-30 13:48:48 +00:00
|
|
|
else if (level <= 24)
|
2012-05-22 17:45:00 +00:00
|
|
|
level -= 32;
|
2006-10-30 13:48:48 +00:00
|
|
|
else
|
2012-05-22 17:45:00 +00:00
|
|
|
level -= 16;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
tmp *= imc_exp_tab[15 + level];
|
2006-11-14 18:54:42 +00:00
|
|
|
tmp2 += 0.83048 * level; // 0.83048 = log2(10) * 0.25
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs1[i] = tmp;
|
|
|
|
flcoeffs2[i] = tmp2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf,
|
|
|
|
float *old_floor, float *flcoeffs1,
|
|
|
|
float *flcoeffs2)
|
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i;
|
2012-05-22 17:45:00 +00:00
|
|
|
/* FIXME maybe flag_buf = noise coding and flcoeffs1 = new scale factors
|
|
|
|
* and flcoeffs2 old scale factors
|
|
|
|
* might be incomplete due to a missing table that is in the binary code
|
|
|
|
*/
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs1[i] = 0;
|
2012-05-22 17:45:00 +00:00
|
|
|
if (levlCoeffBuf[i] < 16) {
|
2006-10-30 13:48:48 +00:00
|
|
|
flcoeffs1[i] = imc_exp_tab2[levlCoeffBuf[i]] * old_floor[i];
|
2012-05-22 17:45:00 +00:00
|
|
|
flcoeffs2[i] = (levlCoeffBuf[i] - 7) * 0.83048 + flcoeffs2[i]; // 0.83048 = log2(10) * 0.25
|
2006-10-30 13:48:48 +00:00
|
|
|
} else {
|
|
|
|
flcoeffs1[i] = old_floor[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf,
|
|
|
|
float *flcoeffs1, float *flcoeffs2)
|
|
|
|
{
|
|
|
|
int i, level, pos;
|
|
|
|
float tmp, tmp2;
|
|
|
|
|
|
|
|
pos = q->coef0_pos;
|
|
|
|
flcoeffs1[pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945); // 0.18945 = log2(10) * 0.05703125
|
|
|
|
flcoeffs2[pos] = log2f(flcoeffs1[0]);
|
|
|
|
tmp = flcoeffs1[pos];
|
|
|
|
tmp2 = flcoeffs2[pos];
|
|
|
|
|
|
|
|
levlCoeffBuf++;
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
if (i == pos)
|
|
|
|
continue;
|
|
|
|
level = *levlCoeffBuf++;
|
|
|
|
flcoeffs1[i] = tmp * powf(10.0, -level * 0.4375); //todo tab
|
|
|
|
flcoeffs2[i] = tmp2 - 1.4533435415 * level; // 1.4533435415 = log2(10) * 0.4375
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-30 13:48:48 +00:00
|
|
|
/**
|
|
|
|
* Perform bit allocation depending on bits available
|
|
|
|
*/
|
2012-06-02 18:30:23 +00:00
|
|
|
static int bit_allocation(IMCContext *q, IMCChannel *chctx,
|
|
|
|
int stream_format_code, int freebits, int flag)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i, j;
|
|
|
|
const float limit = -1.e20;
|
|
|
|
float highest = 0.0;
|
|
|
|
int indx;
|
|
|
|
int t1 = 0;
|
|
|
|
int t2 = 1;
|
|
|
|
float summa = 0.0;
|
|
|
|
int iacc = 0;
|
|
|
|
int summer = 0;
|
|
|
|
int rres, cwlen;
|
|
|
|
float lowest = 1.e10;
|
|
|
|
int low_indx = 0;
|
|
|
|
float workT[32];
|
|
|
|
int flg;
|
|
|
|
int found_indx = 0;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++)
|
2012-06-02 18:30:23 +00:00
|
|
|
highest = FFMAX(highest, chctx->flcoeffs1[i]);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2013-09-27 20:53:24 +00:00
|
|
|
for (i = 0; i < BANDS - 1; i++) {
|
|
|
|
if (chctx->flcoeffs5[i] <= 0) {
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "flcoeffs5 %f invalid\n", chctx->flcoeffs5[i]);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2012-08-05 21:22:10 +00:00
|
|
|
chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]);
|
2013-09-27 20:53:24 +00:00
|
|
|
}
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->flcoeffs4[BANDS - 1] = limit;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
highest = highest * 0.25;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
indx = -1;
|
2012-06-02 18:30:23 +00:00
|
|
|
if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i])
|
2006-10-30 13:48:48 +00:00
|
|
|
indx = 0;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
|
2006-10-30 13:48:48 +00:00
|
|
|
indx = 1;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i])
|
2006-10-30 13:48:48 +00:00
|
|
|
indx = 2;
|
|
|
|
|
|
|
|
if (indx == -1)
|
2011-10-28 22:36:28 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_format_code & 0x2) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->flcoeffs4[0] = limit;
|
|
|
|
chctx->flcoeffs4[1] = limit;
|
|
|
|
chctx->flcoeffs4[2] = limit;
|
|
|
|
chctx->flcoeffs4[3] = limit;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
iacc += chctx->bandWidthT[i];
|
|
|
|
summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
2013-07-09 07:19:30 +00:00
|
|
|
|
|
|
|
if (!iacc)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->bandWidthT[BANDS - 1] = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
summa = (summa * 0.5 - freebits) / iacc;
|
|
|
|
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS / 2; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
rres = summer - freebits;
|
2012-05-22 17:45:00 +00:00
|
|
|
if ((rres >= -8) && (rres <= 8))
|
|
|
|
break;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
summer = 0;
|
2012-05-22 17:45:00 +00:00
|
|
|
iacc = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->bitsBandT[j] = cwlen;
|
|
|
|
summer += chctx->bandWidthT[j] * cwlen;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
if (cwlen > 0)
|
2012-06-02 18:30:23 +00:00
|
|
|
iacc += chctx->bandWidthT[j];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flg = t2;
|
|
|
|
t2 = 1;
|
|
|
|
if (freebits < summer)
|
|
|
|
t2 = -1;
|
|
|
|
if (i == 0)
|
|
|
|
flg = t2;
|
2012-05-22 17:45:00 +00:00
|
|
|
if (flg != t2)
|
2006-10-30 13:48:48 +00:00
|
|
|
t1++;
|
|
|
|
|
|
|
|
summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
|
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++)
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWlengthT[j] = chctx->bitsBandT[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (freebits > summer) {
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
|
|
|
|
: (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
highest = 0.0;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
do {
|
2006-10-30 13:48:48 +00:00
|
|
|
if (highest <= -1.e20)
|
|
|
|
break;
|
|
|
|
|
|
|
|
found_indx = 0;
|
|
|
|
highest = -1.e20;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
if (workT[i] > highest) {
|
|
|
|
highest = workT[i];
|
|
|
|
found_indx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (highest > -1.e20) {
|
|
|
|
workT[found_indx] -= 2.0;
|
2012-06-02 18:30:23 +00:00
|
|
|
if (++chctx->bitsBandT[found_indx] == 6)
|
2006-10-30 13:48:48 +00:00
|
|
|
workT[found_indx] = -1.e20;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWlengthT[j]++;
|
2006-10-30 13:48:48 +00:00
|
|
|
summer++;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 17:45:00 +00:00
|
|
|
} while (freebits > summer);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
if (freebits < summer) {
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585)
|
2012-05-22 17:45:00 +00:00
|
|
|
: 1.e20;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
if (stream_format_code & 0x2) {
|
|
|
|
workT[0] = 1.e20;
|
|
|
|
workT[1] = 1.e20;
|
|
|
|
workT[2] = 1.e20;
|
|
|
|
workT[3] = 1.e20;
|
|
|
|
}
|
2012-05-22 17:45:00 +00:00
|
|
|
while (freebits < summer) {
|
|
|
|
lowest = 1.e10;
|
2006-10-30 13:48:48 +00:00
|
|
|
low_indx = 0;
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
if (workT[i] < lowest) {
|
2012-05-22 17:45:00 +00:00
|
|
|
lowest = workT[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
low_indx = i;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 17:45:00 +00:00
|
|
|
// if (lowest >= 1.e10)
|
|
|
|
// break;
|
2006-10-30 13:48:48 +00:00
|
|
|
workT[low_indx] = lowest + 2.0;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!--chctx->bitsBandT[low_indx])
|
2006-10-30 13:48:48 +00:00
|
|
|
workT[low_indx] = 1.e20;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
if (chctx->CWlengthT[j] > 0) {
|
|
|
|
chctx->CWlengthT[j]--;
|
2006-10-30 13:48:48 +00:00
|
|
|
summer--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i, j;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
|
|
|
|
memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
|
2006-10-30 13:48:48 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!chctx->skipFlagRaw[i]) {
|
|
|
|
chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlags[j] = get_bits1(&q->gb);
|
|
|
|
if (chctx->skipFlags[j])
|
|
|
|
chctx->skipFlagCount[i]++;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
|
|
|
|
if (!get_bits1(&q->gb)) { // 0
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlagBits[i]++;
|
|
|
|
chctx->skipFlags[j] = 1;
|
|
|
|
chctx->skipFlags[j + 1] = 1;
|
|
|
|
chctx->skipFlagCount[i] += 2;
|
2012-05-22 17:45:00 +00:00
|
|
|
} else {
|
|
|
|
if (get_bits1(&q->gb)) { // 11
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlagBits[i] += 2;
|
|
|
|
chctx->skipFlags[j] = 0;
|
|
|
|
chctx->skipFlags[j + 1] = 1;
|
|
|
|
chctx->skipFlagCount[i]++;
|
2012-05-22 17:45:00 +00:00
|
|
|
} else {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlagBits[i] += 3;
|
|
|
|
chctx->skipFlags[j + 1] = 0;
|
2012-05-22 17:45:00 +00:00
|
|
|
if (!get_bits1(&q->gb)) { // 100
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlags[j] = 1;
|
|
|
|
chctx->skipFlagCount[i]++;
|
2012-05-22 17:45:00 +00:00
|
|
|
} else { // 101
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlags[j] = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
if (j < band_tab[i + 1]) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->skipFlagBits[i]++;
|
|
|
|
if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
|
|
|
|
chctx->skipFlagCount[i]++;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase highest' band coefficient sizes as some bits won't be used
|
|
|
|
*/
|
2012-06-02 18:30:23 +00:00
|
|
|
static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx,
|
|
|
|
int summer)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
float workT[32];
|
|
|
|
int corrected = 0;
|
|
|
|
int i, j;
|
2012-05-22 17:45:00 +00:00
|
|
|
float highest = 0;
|
|
|
|
int found_indx = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
|
|
|
|
: (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (corrected < summer) {
|
2012-05-22 17:45:00 +00:00
|
|
|
if (highest <= -1.e20)
|
2006-10-30 13:48:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
highest = -1.e20;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2006-10-30 13:48:48 +00:00
|
|
|
if (workT[i] > highest) {
|
|
|
|
highest = workT[i];
|
|
|
|
found_indx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (highest > -1.e20) {
|
|
|
|
workT[found_indx] -= 2.0;
|
2012-06-02 18:30:23 +00:00
|
|
|
if (++(chctx->bitsBandT[found_indx]) == 6)
|
2006-10-30 13:48:48 +00:00
|
|
|
workT[found_indx] = -1.e20;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
|
|
|
|
chctx->CWlengthT[j]++;
|
2006-10-30 13:48:48 +00:00
|
|
|
corrected++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:35:41 +00:00
|
|
|
static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i;
|
|
|
|
float re, im;
|
2012-06-02 18:35:41 +00:00
|
|
|
float *dst1 = q->out_samples;
|
2012-08-27 16:58:25 +00:00
|
|
|
float *dst2 = q->out_samples + (COEFFS - 1);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
/* prerotation */
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < COEFFS / 2; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
|
|
|
|
(q->pre_coef2[i] * chctx->CWdecoded[i * 2]);
|
|
|
|
q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
|
|
|
|
(q->pre_coef1[i] * chctx->CWdecoded[i * 2]);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FFT */
|
2011-03-19 15:14:17 +00:00
|
|
|
q->fft.fft_permute(&q->fft, q->samples);
|
2012-05-22 17:45:00 +00:00
|
|
|
q->fft.fft_calc(&q->fft, q->samples);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
/* postrotation, window and reorder */
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < COEFFS / 2; i++) {
|
|
|
|
re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
|
|
|
|
im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]);
|
2012-06-02 18:35:41 +00:00
|
|
|
*dst1 = (q->mdct_sine_window[COEFFS - 1 - i * 2] * chctx->last_fft_im[i])
|
|
|
|
+ (q->mdct_sine_window[i * 2] * re);
|
|
|
|
*dst2 = (q->mdct_sine_window[i * 2] * chctx->last_fft_im[i])
|
|
|
|
- (q->mdct_sine_window[COEFFS - 1 - i * 2] * re);
|
2012-08-27 16:58:25 +00:00
|
|
|
dst1 += 2;
|
|
|
|
dst2 -= 2;
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->last_fft_im[i] = im;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx,
|
|
|
|
int stream_format_code)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i, j;
|
|
|
|
int middle_value, cw_len, max_size;
|
2012-05-22 17:45:00 +00:00
|
|
|
const float *quantizer;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWdecoded[j] = 0;
|
|
|
|
cw_len = chctx->CWlengthT[j];
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (cw_len <= 0 || chctx->skipFlags[j])
|
2006-10-30 13:48:48 +00:00
|
|
|
continue;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
max_size = 1 << cw_len;
|
2006-10-30 13:48:48 +00:00
|
|
|
middle_value = max_size >> 1;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
|
2011-10-28 22:36:28 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
if (cw_len >= 4) {
|
2006-10-30 13:48:48 +00:00
|
|
|
quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
|
2012-06-02 18:30:23 +00:00
|
|
|
if (chctx->codewords[j] >= middle_value)
|
|
|
|
chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
else
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
}else{
|
2012-06-02 18:30:23 +00:00
|
|
|
quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
|
|
|
|
if (chctx->codewords[j] >= middle_value)
|
|
|
|
chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
else
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx)
|
2012-05-22 17:45:00 +00:00
|
|
|
{
|
2006-10-30 13:48:48 +00:00
|
|
|
int i, j, cw_len, cw;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!chctx->sumLenArr[i])
|
2012-05-22 17:45:00 +00:00
|
|
|
continue;
|
2012-06-02 18:30:23 +00:00
|
|
|
if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
cw_len = chctx->CWlengthT[j];
|
2006-10-30 13:48:48 +00:00
|
|
|
cw = 0;
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
if (get_bits_count(&q->gb) + cw_len > 512) {
|
2012-08-21 10:41:40 +00:00
|
|
|
av_dlog(NULL, "Band %i coeff %i cw_len %i\n", i, j, cw_len);
|
2011-10-28 22:36:28 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j]))
|
2006-10-30 13:48:48 +00:00
|
|
|
cw = get_bits(&q->gb, cw_len);
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->codewords[j] = cw;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int bits, summer;
|
|
|
|
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
chctx->sumLenArr[i] = 0;
|
|
|
|
chctx->skipFlagRaw[i] = 0;
|
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++)
|
|
|
|
chctx->sumLenArr[i] += chctx->CWlengthT[j];
|
|
|
|
if (chctx->bandFlagsBuf[i])
|
|
|
|
if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
|
|
|
|
chctx->skipFlagRaw[i] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
imc_get_skip_coeff(q, chctx);
|
|
|
|
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
|
|
|
|
/* band has flag set and at least one coded coefficient */
|
|
|
|
if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
|
|
|
|
chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
|
|
|
|
q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate bits left, bits needed and adjust bit allocation */
|
|
|
|
bits = summer = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
if (chctx->bandFlagsBuf[i]) {
|
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
|
|
|
|
if (chctx->skipFlags[j]) {
|
|
|
|
summer += chctx->CWlengthT[j];
|
|
|
|
chctx->CWlengthT[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bits += chctx->skipFlagBits[i];
|
|
|
|
summer -= chctx->skipFlagBits[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
imc_adjust_bit_allocation(q, chctx, summer);
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
|
|
|
int stream_format_code;
|
2011-09-06 16:17:45 +00:00
|
|
|
int imc_hdr, i, j, ret;
|
2006-10-30 13:48:48 +00:00
|
|
|
int flag;
|
2013-07-11 05:04:42 +00:00
|
|
|
int bits;
|
2006-10-30 13:48:48 +00:00
|
|
|
int counter, bitscount;
|
2012-06-02 18:30:23 +00:00
|
|
|
IMCChannel *chctx = q->chctx + ch;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Check the frame header */
|
|
|
|
imc_hdr = get_bits(&q->gb, 9);
|
2012-06-02 19:07:02 +00:00
|
|
|
if (imc_hdr & 0x18) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "frame header check failed!\n");
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "got %X.\n", imc_hdr);
|
2011-10-28 22:36:28 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
stream_format_code = get_bits(&q->gb, 3);
|
|
|
|
|
|
|
|
if (stream_format_code & 0x04)
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->decoder_reset = 1;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (chctx->decoder_reset) {
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++)
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->old_floor[i] = 1.0;
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < COEFFS; i++)
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWdecoded[i] = 0;
|
|
|
|
chctx->decoder_reset = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flag = get_bits1(&q->gb);
|
2013-07-11 05:04:42 +00:00
|
|
|
if (stream_format_code & 0x1)
|
|
|
|
imc_decode_level_coefficients_raw(q, chctx->levlCoeffBuf,
|
|
|
|
chctx->flcoeffs1, chctx->flcoeffs2);
|
|
|
|
else if (stream_format_code & 0x1)
|
|
|
|
imc_read_level_coeffs_raw(q, stream_format_code, chctx->levlCoeffBuf);
|
|
|
|
else
|
|
|
|
imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
if (stream_format_code & 0x4)
|
2012-06-02 18:30:23 +00:00
|
|
|
imc_decode_level_coefficients(q, chctx->levlCoeffBuf,
|
|
|
|
chctx->flcoeffs1, chctx->flcoeffs2);
|
2006-10-30 13:48:48 +00:00
|
|
|
else
|
2012-06-02 18:30:23 +00:00
|
|
|
imc_decode_level_coefficients2(q, chctx->levlCoeffBuf, chctx->old_floor,
|
|
|
|
chctx->flcoeffs1, chctx->flcoeffs2);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-11-13 23:01:56 +00:00
|
|
|
for(i=0; i<BANDS; i++) {
|
|
|
|
if(chctx->flcoeffs1[i] > INT_MAX) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "scalefactor out of range\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
counter = 0;
|
2013-07-11 05:04:42 +00:00
|
|
|
if (stream_format_code & 0x1) {
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
|
|
|
|
chctx->bandFlagsBuf[i] = 0;
|
|
|
|
chctx->flcoeffs3[i] = chctx->flcoeffs2[i] * 2;
|
|
|
|
chctx->flcoeffs5[i] = 1.0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < BANDS; i++) {
|
|
|
|
if (chctx->levlCoeffBuf[i] == 16) {
|
|
|
|
chctx->bandWidthT[i] = 0;
|
|
|
|
counter++;
|
|
|
|
} else
|
|
|
|
chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
|
|
|
|
for (i = 0; i < BANDS - 1; i++)
|
|
|
|
if (chctx->bandWidthT[i])
|
|
|
|
chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2,
|
|
|
|
chctx->bandWidthT, chctx->flcoeffs3,
|
|
|
|
chctx->flcoeffs5);
|
|
|
|
}
|
2006-10-30 13:48:48 +00:00
|
|
|
|
|
|
|
bitscount = 0;
|
|
|
|
/* first 4 bands will be assigned 5 bits per coefficient */
|
|
|
|
if (stream_format_code & 0x2) {
|
|
|
|
bitscount += 15;
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->bitsBandT[0] = 5;
|
|
|
|
chctx->CWlengthT[0] = 5;
|
|
|
|
chctx->CWlengthT[1] = 5;
|
|
|
|
chctx->CWlengthT[2] = 5;
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 1; i < 4; i++) {
|
2013-07-11 05:04:42 +00:00
|
|
|
if (stream_format_code & 0x1)
|
|
|
|
bits = 5;
|
|
|
|
else
|
|
|
|
bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->bitsBandT[i] = bits;
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->CWlengthT[j] = bits;
|
2012-05-22 17:45:00 +00:00
|
|
|
bitscount += bits;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-05 09:11:04 +00:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_IAC) {
|
2012-06-02 19:07:02 +00:00
|
|
|
bitscount += !!chctx->bandWidthT[BANDS - 1];
|
|
|
|
if (!(stream_format_code & 0x2))
|
|
|
|
bitscount += 16;
|
|
|
|
}
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if ((ret = bit_allocation(q, chctx, stream_format_code,
|
2012-05-22 17:45:00 +00:00
|
|
|
512 - bitscount - get_bits_count(&q->gb),
|
|
|
|
flag)) < 0) {
|
2006-10-30 13:48:48 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->decoder_reset = 1;
|
2011-10-28 22:36:28 +00:00
|
|
|
return ret;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 05:04:42 +00:00
|
|
|
if (stream_format_code & 0x1) {
|
|
|
|
for (i = 0; i < BANDS; i++)
|
|
|
|
chctx->skipFlags[i] = 0;
|
|
|
|
} else {
|
|
|
|
imc_refine_bit_allocation(q, chctx);
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (i = 0; i < BANDS; i++) {
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->sumLenArr[i] = 0;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-05-22 17:45:00 +00:00
|
|
|
for (j = band_tab[i]; j < band_tab[i + 1]; j++)
|
2012-06-02 18:30:23 +00:00
|
|
|
if (!chctx->skipFlags[j])
|
|
|
|
chctx->sumLenArr[i] += chctx->CWlengthT[j];
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
memset(chctx->codewords, 0, sizeof(chctx->codewords));
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (imc_get_coeffs(q, chctx) < 0) {
|
2006-10-30 13:48:48 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->decoder_reset = 1;
|
2011-10-29 15:16:01 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
|
2006-10-30 13:48:48 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n");
|
2012-06-02 18:30:23 +00:00
|
|
|
chctx->decoder_reset = 1;
|
2011-10-29 15:16:01 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
|
|
|
|
|
2012-06-02 18:35:41 +00:00
|
|
|
imc_imdct256(q, chctx, avctx->channels);
|
2012-06-02 18:30:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imc_decode_frame(AVCodecContext *avctx, void *data,
|
|
|
|
int *got_frame_ptr, AVPacket *avpkt)
|
|
|
|
{
|
2012-12-23 23:01:45 +00:00
|
|
|
AVFrame *frame = data;
|
2012-06-02 18:30:23 +00:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
|
|
|
int ret, i;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
IMCContext *q = avctx->priv_data;
|
|
|
|
|
|
|
|
LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]);
|
|
|
|
|
2012-06-02 19:07:02 +00:00
|
|
|
if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
|
2011-10-29 15:16:01 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
/* get output buffer */
|
2012-12-23 23:01:45 +00:00
|
|
|
frame->nb_samples = COEFFS;
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 07:41:53 +00:00
|
|
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
2012-06-02 18:30:23 +00:00
|
|
|
return ret;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
for (i = 0; i < avctx->channels; i++) {
|
2012-12-23 23:01:45 +00:00
|
|
|
q->out_samples = (float *)frame->extended_data[i];
|
2012-06-02 18:30:23 +00:00
|
|
|
|
2014-02-13 16:57:05 +00:00
|
|
|
q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
|
2012-06-02 18:30:23 +00:00
|
|
|
|
|
|
|
init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
|
|
|
|
|
|
|
|
buf += IMC_BLOCK_SIZE;
|
|
|
|
|
|
|
|
if ((ret = imc_decode_block(avctx, q, i)) < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 19:07:02 +00:00
|
|
|
if (avctx->channels == 2) {
|
2012-12-23 23:01:45 +00:00
|
|
|
q->fdsp.butterflies_float((float *)frame->extended_data[0],
|
|
|
|
(float *)frame->extended_data[1], COEFFS);
|
2012-06-02 19:07:02 +00:00
|
|
|
}
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-12-23 23:01:45 +00:00
|
|
|
*got_frame_ptr = 1;
|
2006-10-30 13:48:48 +00:00
|
|
|
|
2012-06-02 18:30:23 +00:00
|
|
|
return IMC_BLOCK_SIZE * avctx->channels;
|
2006-10-30 13:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int imc_decode_close(AVCodecContext * avctx)
|
2006-10-30 13:48:48 +00:00
|
|
|
{
|
|
|
|
IMCContext *q = avctx->priv_data;
|
|
|
|
|
|
|
|
ff_fft_end(&q->fft);
|
2011-09-06 16:17:45 +00:00
|
|
|
|
2006-10-30 13:48:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-25 21:48:18 +00:00
|
|
|
static av_cold void flush(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
IMCContext *q = avctx->priv_data;
|
|
|
|
|
|
|
|
q->chctx[0].decoder_reset =
|
|
|
|
q->chctx[1].decoder_reset = 1;
|
|
|
|
}
|
|
|
|
|
2012-06-11 12:40:28 +00:00
|
|
|
#if CONFIG_IMC_DECODER
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_imc_decoder = {
|
2012-04-06 16:19:39 +00:00
|
|
|
.name = "imc",
|
2013-10-03 20:57:53 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"),
|
2012-04-06 16:19:39 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.id = AV_CODEC_ID_IMC,
|
2006-10-30 13:48:48 +00:00
|
|
|
.priv_data_size = sizeof(IMCContext),
|
2012-04-06 16:19:39 +00:00
|
|
|
.init = imc_decode_init,
|
|
|
|
.close = imc_decode_close,
|
|
|
|
.decode = imc_decode_frame,
|
2012-11-25 21:48:18 +00:00
|
|
|
.flush = flush,
|
2012-04-06 16:19:39 +00:00
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2012-08-27 16:58:25 +00:00
|
|
|
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2006-10-30 13:48:48 +00:00
|
|
|
};
|
2012-06-11 12:40:28 +00:00
|
|
|
#endif
|
|
|
|
#if CONFIG_IAC_DECODER
|
2012-06-02 19:07:02 +00:00
|
|
|
AVCodec ff_iac_decoder = {
|
|
|
|
.name = "iac",
|
2013-10-03 20:57:53 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("IAC (Indeo Audio Coder)"),
|
2012-06-02 19:07:02 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.id = AV_CODEC_ID_IAC,
|
2012-06-02 19:07:02 +00:00
|
|
|
.priv_data_size = sizeof(IMCContext),
|
|
|
|
.init = imc_decode_init,
|
|
|
|
.close = imc_decode_close,
|
|
|
|
.decode = imc_decode_frame,
|
2012-11-25 21:48:18 +00:00
|
|
|
.flush = flush,
|
2012-06-02 19:07:02 +00:00
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2012-08-27 16:58:25 +00:00
|
|
|
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2012-06-02 19:07:02 +00:00
|
|
|
};
|
2012-06-11 12:40:28 +00:00
|
|
|
#endif
|