|
|
@ -34,6 +34,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "libavutil/attributes.h" |
|
|
|
#include "libavutil/attributes.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "avcodec.h" |
|
|
|
#include "avcodec.h" |
|
|
|
#include "internal.h" |
|
|
|
#include "internal.h" |
|
|
|
#include "wma.h" |
|
|
|
#include "wma.h" |
|
|
@ -50,7 +51,8 @@ |
|
|
|
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len); |
|
|
|
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRACE |
|
|
|
#ifdef TRACE |
|
|
|
static void dump_floats(WMACodecContext *s, const char *name, int prec, const float *tab, int n) |
|
|
|
static void dump_floats(WMACodecContext *s, const char *name, |
|
|
|
|
|
|
|
int prec, const float *tab, int n) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
@ -65,7 +67,7 @@ static void dump_floats(WMACodecContext *s, const char *name, int prec, const fl |
|
|
|
if ((i & 7) != 0) |
|
|
|
if ((i & 7) != 0) |
|
|
|
tprintf(s->avctx, "\n"); |
|
|
|
tprintf(s->avctx, "\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif /* TRACE */ |
|
|
|
|
|
|
|
|
|
|
|
static av_cold int wma_decode_init(AVCodecContext *avctx) |
|
|
|
static av_cold int wma_decode_init(AVCodecContext *avctx) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -83,11 +85,10 @@ static av_cold int wma_decode_init(AVCodecContext * avctx) |
|
|
|
/* extract flag infos */ |
|
|
|
/* extract flag infos */ |
|
|
|
flags2 = 0; |
|
|
|
flags2 = 0; |
|
|
|
extradata = avctx->extradata; |
|
|
|
extradata = avctx->extradata; |
|
|
|
if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4) { |
|
|
|
if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4) |
|
|
|
flags2 = AV_RL16(extradata + 2); |
|
|
|
flags2 = AV_RL16(extradata + 2); |
|
|
|
} else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6) { |
|
|
|
else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6) |
|
|
|
flags2 = AV_RL16(extradata + 4); |
|
|
|
flags2 = AV_RL16(extradata + 4); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s->use_exp_vlc = flags2 & 0x0001; |
|
|
|
s->use_exp_vlc = flags2 & 0x0001; |
|
|
|
s->use_bit_reservoir = flags2 & 0x0002; |
|
|
|
s->use_bit_reservoir = flags2 & 0x0002; |
|
|
@ -106,13 +107,12 @@ static av_cold int wma_decode_init(AVCodecContext * avctx) |
|
|
|
ff_wma_hgain_huffcodes, 2, 2, 0); |
|
|
|
ff_wma_hgain_huffcodes, 2, 2, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (s->use_exp_vlc) { |
|
|
|
if (s->use_exp_vlc) |
|
|
|
init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), // FIXME move out of context
|
|
|
|
init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), // FIXME move out of context
|
|
|
|
ff_aac_scalefactor_bits, 1, 1, |
|
|
|
ff_aac_scalefactor_bits, 1, 1, |
|
|
|
ff_aac_scalefactor_code, 4, 4, 0); |
|
|
|
ff_aac_scalefactor_code, 4, 4, 0); |
|
|
|
} else { |
|
|
|
else |
|
|
|
wma_lsp_to_curve_init(s, s->frame_len); |
|
|
|
wma_lsp_to_curve_init(s, s->frame_len); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; |
|
|
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; |
|
|
|
|
|
|
|
|
|
|
@ -160,7 +160,7 @@ static av_cold void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* NOTE: these two tables are needed to avoid two operations in
|
|
|
|
/* NOTE: these two tables are needed to avoid two operations in
|
|
|
|
pow_m1_4 */ |
|
|
|
* pow_m1_4 */ |
|
|
|
b = 1.0; |
|
|
|
b = 1.0; |
|
|
|
for (i = (1 << LSP_POW_BITS) - 1; i >= 0; i--) { |
|
|
|
for (i = (1 << LSP_POW_BITS) - 1; i >= 0; i--) { |
|
|
|
m = (1 << LSP_POW_BITS) + i; |
|
|
|
m = (1 << LSP_POW_BITS) + i; |
|
|
@ -176,8 +176,7 @@ static av_cold void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len) |
|
|
|
* NOTE: We use the same code as Vorbis here |
|
|
|
* NOTE: We use the same code as Vorbis here |
|
|
|
* @todo optimize it further with SSE/3Dnow |
|
|
|
* @todo optimize it further with SSE/3Dnow |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void wma_lsp_to_curve(WMACodecContext *s, |
|
|
|
static void wma_lsp_to_curve(WMACodecContext *s, float *out, float *val_max_ptr, |
|
|
|
float *out, float *val_max_ptr, |
|
|
|
|
|
|
|
int n, float *lsp) |
|
|
|
int n, float *lsp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, j; |
|
|
|
int i, j; |
|
|
@ -365,7 +364,6 @@ static int decode_exp_vlc(WMACodecContext *s, int ch) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Apply MDCT window and add into output. |
|
|
|
* Apply MDCT window and add into output. |
|
|
|
* |
|
|
|
* |
|
|
@ -384,7 +382,6 @@ static void wma_window(WMACodecContext *s, float *out) |
|
|
|
|
|
|
|
|
|
|
|
s->fdsp.vector_fmul_add(out, in, s->windows[bsize], |
|
|
|
s->fdsp.vector_fmul_add(out, in, s->windows[bsize], |
|
|
|
out, block_len); |
|
|
|
out, block_len); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
block_len = 1 << s->prev_block_len_bits; |
|
|
|
block_len = 1 << s->prev_block_len_bits; |
|
|
|
n = (s->block_len - block_len) / 2; |
|
|
|
n = (s->block_len - block_len) / 2; |
|
|
@ -405,7 +402,6 @@ static void wma_window(WMACodecContext *s, float *out) |
|
|
|
bsize = s->frame_len_bits - s->block_len_bits; |
|
|
|
bsize = s->frame_len_bits - s->block_len_bits; |
|
|
|
|
|
|
|
|
|
|
|
s->fdsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len); |
|
|
|
s->fdsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
block_len = 1 << s->next_block_len_bits; |
|
|
|
block_len = 1 << s->next_block_len_bits; |
|
|
|
n = (s->block_len - block_len) / 2; |
|
|
|
n = (s->block_len - block_len) / 2; |
|
|
@ -413,13 +409,13 @@ static void wma_window(WMACodecContext *s, float *out) |
|
|
|
|
|
|
|
|
|
|
|
memcpy(out, in, n * sizeof(float)); |
|
|
|
memcpy(out, in, n * sizeof(float)); |
|
|
|
|
|
|
|
|
|
|
|
s->fdsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len); |
|
|
|
s->fdsp.vector_fmul_reverse(out + n, in + n, s->windows[bsize], |
|
|
|
|
|
|
|
block_len); |
|
|
|
|
|
|
|
|
|
|
|
memset(out + n + block_len, 0, n * sizeof(float)); |
|
|
|
memset(out + n + block_len, 0, n * sizeof(float)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @return 0 if OK. 1 if last block of frame. return -1 if |
|
|
|
* @return 0 if OK. 1 if last block of frame. return -1 if |
|
|
|
* unrecorrable error. |
|
|
|
* unrecorrable error. |
|
|
@ -433,8 +429,9 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
FFTContext *mdct; |
|
|
|
FFTContext *mdct; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRACE |
|
|
|
#ifdef TRACE |
|
|
|
tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num); |
|
|
|
tprintf(s->avctx, "***decode_block: %d:%d\n", |
|
|
|
#endif |
|
|
|
s->frame_count - 1, s->block_num); |
|
|
|
|
|
|
|
#endif /* TRACE */ |
|
|
|
|
|
|
|
|
|
|
|
/* compute current block length */ |
|
|
|
/* compute current block length */ |
|
|
|
if (s->use_variable_block_len) { |
|
|
|
if (s->use_variable_block_len) { |
|
|
@ -444,13 +441,17 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
s->reset_block_lengths = 0; |
|
|
|
s->reset_block_lengths = 0; |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
|
|
|
"prev_block_len_bits %d out of range\n", |
|
|
|
|
|
|
|
s->frame_len_bits - v); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
s->prev_block_len_bits = s->frame_len_bits - v; |
|
|
|
s->prev_block_len_bits = s->frame_len_bits - v; |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
|
|
|
"block_len_bits %d out of range\n", |
|
|
|
|
|
|
|
s->frame_len_bits - v); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
s->block_len_bits = s->frame_len_bits - v; |
|
|
|
s->block_len_bits = s->frame_len_bits - v; |
|
|
@ -461,7 +462,9 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
} |
|
|
|
} |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
v = get_bits(&s->gb, n); |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
if (v >= s->nb_block_sizes) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
|
|
|
"next_block_len_bits %d out of range\n", |
|
|
|
|
|
|
|
s->frame_len_bits - v); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
s->next_block_len_bits = s->frame_len_bits - v; |
|
|
|
s->next_block_len_bits = s->frame_len_bits - v; |
|
|
@ -479,9 +482,8 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (s->avctx->channels == 2) { |
|
|
|
if (s->avctx->channels == 2) |
|
|
|
s->ms_stereo = get_bits1(&s->gb); |
|
|
|
s->ms_stereo = get_bits1(&s->gb); |
|
|
|
} |
|
|
|
|
|
|
|
v = 0; |
|
|
|
v = 0; |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
a = get_bits1(&s->gb); |
|
|
|
a = get_bits1(&s->gb); |
|
|
@ -497,7 +499,7 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
goto next; |
|
|
|
goto next; |
|
|
|
|
|
|
|
|
|
|
|
/* read total gain and extract corresponding number of bits for
|
|
|
|
/* read total gain and extract corresponding number of bits for
|
|
|
|
coef escape coding */ |
|
|
|
* coef escape coding */ |
|
|
|
total_gain = 1; |
|
|
|
total_gain = 1; |
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
a = get_bits(&s->gb, 7); |
|
|
|
a = get_bits(&s->gb, 7); |
|
|
@ -515,7 +517,6 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
|
|
|
|
|
|
|
|
/* complex coding */ |
|
|
|
/* complex coding */ |
|
|
|
if (s->use_noise_coding) { |
|
|
|
if (s->use_noise_coding) { |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
int i, n, a; |
|
|
|
int i, n, a; |
|
|
@ -540,9 +541,11 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
if (val == (int) 0x80000000) { |
|
|
|
if (val == (int) 0x80000000) { |
|
|
|
val = get_bits(&s->gb, 7) - 19; |
|
|
|
val = get_bits(&s->gb, 7) - 19; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX); |
|
|
|
code = get_vlc2(&s->gb, s->hgain_vlc.table, |
|
|
|
|
|
|
|
HGAINVLCBITS, HGAINMAX); |
|
|
|
if (code < 0) { |
|
|
|
if (code < 0) { |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n"); |
|
|
|
av_log(s->avctx, AV_LOG_ERROR, |
|
|
|
|
|
|
|
"hgain vlc invalid\n"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
val += code - 18; |
|
|
|
val += code - 18; |
|
|
@ -555,8 +558,7 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* exponents can be reused in short blocks. */ |
|
|
|
/* exponents can be reused in short blocks. */ |
|
|
|
if ((s->block_len_bits == s->frame_len_bits) || |
|
|
|
if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) { |
|
|
|
get_bits1(&s->gb)) { |
|
|
|
|
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->use_exp_vlc) { |
|
|
|
if (s->use_exp_vlc) { |
|
|
@ -577,7 +579,7 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
WMACoef *ptr = &s->coefs1[ch][0]; |
|
|
|
WMACoef *ptr = &s->coefs1[ch][0]; |
|
|
|
|
|
|
|
|
|
|
|
/* special VLC tables are used for ms stereo because
|
|
|
|
/* special VLC tables are used for ms stereo because
|
|
|
|
there is potentially less energy there */ |
|
|
|
* there is potentially less energy there */ |
|
|
|
tindex = (ch == 1 && s->ms_stereo); |
|
|
|
tindex = (ch == 1 && s->ms_stereo); |
|
|
|
memset(ptr, 0, s->block_len * sizeof(WMACoef)); |
|
|
|
memset(ptr, 0, s->block_len * sizeof(WMACoef)); |
|
|
|
ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex], |
|
|
|
ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex], |
|
|
@ -585,19 +587,17 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
0, ptr, 0, nb_coefs[ch], |
|
|
|
0, ptr, 0, nb_coefs[ch], |
|
|
|
s->block_len, s->frame_len_bits, coef_nb_bits); |
|
|
|
s->block_len, s->frame_len_bits, coef_nb_bits); |
|
|
|
} |
|
|
|
} |
|
|
|
if (s->version == 1 && s->avctx->channels >= 2) { |
|
|
|
if (s->version == 1 && s->avctx->channels >= 2) |
|
|
|
align_get_bits(&s->gb); |
|
|
|
align_get_bits(&s->gb); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* normalize */ |
|
|
|
/* normalize */ |
|
|
|
{ |
|
|
|
{ |
|
|
|
int n4 = s->block_len / 2; |
|
|
|
int n4 = s->block_len / 2; |
|
|
|
mdct_norm = 1.0 / (float) n4; |
|
|
|
mdct_norm = 1.0 / (float) n4; |
|
|
|
if (s->version == 1) { |
|
|
|
if (s->version == 1) |
|
|
|
mdct_norm *= sqrt(n4); |
|
|
|
mdct_norm *= sqrt(n4); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* finally compute the MDCT coefficients */ |
|
|
|
/* finally compute the MDCT coefficients */ |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
@ -619,7 +619,8 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
for (i = 0; i < s->coefs_start; i++) { |
|
|
|
for (i = 0; i < s->coefs_start; i++) { |
|
|
|
*coefs++ = s->noise_table[s->noise_index] * |
|
|
|
*coefs++ = s->noise_table[s->noise_index] * |
|
|
|
exponents[i << bsize >> esize] * mult1; |
|
|
|
exponents[i << bsize >> esize] * mult1; |
|
|
|
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); |
|
|
|
s->noise_index = (s->noise_index + 1) & |
|
|
|
|
|
|
|
(NOISE_TAB_SIZE - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
n1 = s->exponent_high_sizes[bsize]; |
|
|
|
n1 = s->exponent_high_sizes[bsize]; |
|
|
@ -648,13 +649,11 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
/* main freqs and high freqs */ |
|
|
|
/* main freqs and high freqs */ |
|
|
|
exponents = s->exponents[ch] + (s->coefs_start << bsize >> esize); |
|
|
|
exponents = s->exponents[ch] + (s->coefs_start << bsize >> esize); |
|
|
|
for (j = -1; j < n1; j++) { |
|
|
|
for (j = -1; j < n1; j++) { |
|
|
|
if (j < 0) { |
|
|
|
if (j < 0) |
|
|
|
n = s->high_band_start[bsize] - |
|
|
|
n = s->high_band_start[bsize] - s->coefs_start; |
|
|
|
s->coefs_start; |
|
|
|
else |
|
|
|
} else { |
|
|
|
|
|
|
|
n = s->exponent_high_bands[s->frame_len_bits - |
|
|
|
n = s->exponent_high_bands[s->frame_len_bits - |
|
|
|
s->block_len_bits][j]; |
|
|
|
s->block_len_bits][j]; |
|
|
|
} |
|
|
|
|
|
|
|
if (j >= 0 && s->high_band_coded[ch][j]) { |
|
|
|
if (j >= 0 && s->high_band_coded[ch][j]) { |
|
|
|
/* use noise with specified power */ |
|
|
|
/* use noise with specified power */ |
|
|
|
mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); |
|
|
|
mult1 = sqrt(exp_power[j] / exp_power[last_high_band]); |
|
|
@ -665,8 +664,7 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
for (i = 0; i < n; i++) { |
|
|
|
for (i = 0; i < n; i++) { |
|
|
|
noise = s->noise_table[s->noise_index]; |
|
|
|
noise = s->noise_table[s->noise_index]; |
|
|
|
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); |
|
|
|
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); |
|
|
|
*coefs++ = noise * |
|
|
|
*coefs++ = noise * exponents[i << bsize >> esize] * mult1; |
|
|
|
exponents[i<<bsize>>esize] * mult1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
exponents += n << bsize >> esize; |
|
|
|
exponents += n << bsize >> esize; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -693,9 +691,8 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
for (i = 0; i < s->coefs_start; i++) |
|
|
|
for (i = 0; i < s->coefs_start; i++) |
|
|
|
*coefs++ = 0.0; |
|
|
|
*coefs++ = 0.0; |
|
|
|
n = nb_coefs[ch]; |
|
|
|
n = nb_coefs[ch]; |
|
|
|
for(i = 0;i < n; i++) { |
|
|
|
for (i = 0; i < n; i++) |
|
|
|
*coefs++ = coefs1[i] * exponents[i << bsize >> esize] * mult; |
|
|
|
*coefs++ = coefs1[i] * exponents[i << bsize >> esize] * mult; |
|
|
|
} |
|
|
|
|
|
|
|
n = s->block_len - s->coefs_end[bsize]; |
|
|
|
n = s->block_len - s->coefs_end[bsize]; |
|
|
|
for (i = 0; i < n; i++) |
|
|
|
for (i = 0; i < n; i++) |
|
|
|
*coefs++ = 0.0; |
|
|
|
*coefs++ = 0.0; |
|
|
@ -710,12 +707,12 @@ static int wma_decode_block(WMACodecContext *s) |
|
|
|
dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len); |
|
|
|
dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif /* TRACE */ |
|
|
|
|
|
|
|
|
|
|
|
if (s->ms_stereo && s->channel_coded[1]) { |
|
|
|
if (s->ms_stereo && s->channel_coded[1]) { |
|
|
|
/* nominal case for ms stereo: we do it before mdct */ |
|
|
|
/* nominal case for ms stereo: we do it before mdct */ |
|
|
|
/* no need to optimize this case because it should almost
|
|
|
|
/* no need to optimize this case because it should almost
|
|
|
|
never happen */ |
|
|
|
* never happen */ |
|
|
|
if (!s->channel_coded[0]) { |
|
|
|
if (!s->channel_coded[0]) { |
|
|
|
tprintf(s->avctx, "rare ms-stereo case happened\n"); |
|
|
|
tprintf(s->avctx, "rare ms-stereo case happened\n"); |
|
|
|
memset(s->coefs[0], 0, sizeof(float) * s->block_len); |
|
|
|
memset(s->coefs[0], 0, sizeof(float) * s->block_len); |
|
|
@ -732,9 +729,9 @@ next: |
|
|
|
int n4, index; |
|
|
|
int n4, index; |
|
|
|
|
|
|
|
|
|
|
|
n4 = s->block_len / 2; |
|
|
|
n4 = s->block_len / 2; |
|
|
|
if(s->channel_coded[ch]){ |
|
|
|
if (s->channel_coded[ch]) |
|
|
|
mdct->imdct_calc(mdct, s->output, s->coefs[ch]); |
|
|
|
mdct->imdct_calc(mdct, s->output, s->coefs[ch]); |
|
|
|
}else if(!(s->ms_stereo && ch==1)) |
|
|
|
else if (!(s->ms_stereo && ch == 1)) |
|
|
|
memset(s->output, 0, sizeof(s->output)); |
|
|
|
memset(s->output, 0, sizeof(s->output)); |
|
|
|
|
|
|
|
|
|
|
|
/* multiply by the window and add in the frame */ |
|
|
|
/* multiply by the window and add in the frame */ |
|
|
@ -758,8 +755,9 @@ static int wma_decode_frame(WMACodecContext *s, float **samples, |
|
|
|
int ret, ch; |
|
|
|
int ret, ch; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRACE |
|
|
|
#ifdef TRACE |
|
|
|
tprintf(s->avctx, "***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len); |
|
|
|
tprintf(s->avctx, "***decode_frame: %d size=%d\n", |
|
|
|
#endif |
|
|
|
s->frame_count++, s->frame_len); |
|
|
|
|
|
|
|
#endif /* TRACE */ |
|
|
|
|
|
|
|
|
|
|
|
/* read each block */ |
|
|
|
/* read each block */ |
|
|
|
s->block_num = 0; |
|
|
|
s->block_num = 0; |
|
|
@ -781,8 +779,9 @@ static int wma_decode_frame(WMACodecContext *s, float **samples, |
|
|
|
s->frame_len * sizeof(*s->frame_out[ch])); |
|
|
|
s->frame_len * sizeof(*s->frame_out[ch])); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef TRACE |
|
|
|
#ifdef TRACE |
|
|
|
dump_floats(s, "samples", 6, samples[ch] + samples_offset, s->frame_len); |
|
|
|
dump_floats(s, "samples", 6, samples[ch] + samples_offset, |
|
|
|
#endif |
|
|
|
s->frame_len); |
|
|
|
|
|
|
|
#endif /* TRACE */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
@ -820,9 +819,8 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, |
|
|
|
/* read super frame header */ |
|
|
|
/* read super frame header */ |
|
|
|
skip_bits(&s->gb, 4); /* super frame index */ |
|
|
|
skip_bits(&s->gb, 4); /* super frame index */ |
|
|
|
nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0); |
|
|
|
nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0); |
|
|
|
} else { |
|
|
|
} else |
|
|
|
nb_frames = 1; |
|
|
|
nb_frames = 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get output buffer */ |
|
|
|
/* get output buffer */ |
|
|
|
frame->nb_samples = nb_frames * s->frame_len; |
|
|
|
frame->nb_samples = nb_frames * s->frame_len; |
|
|
@ -853,18 +851,18 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, |
|
|
|
*q++ = (get_bits) (&s->gb, 8); |
|
|
|
*q++ = (get_bits) (&s->gb, 8); |
|
|
|
len -= 8; |
|
|
|
len -= 8; |
|
|
|
} |
|
|
|
} |
|
|
|
if (len > 0) { |
|
|
|
if (len > 0) |
|
|
|
*q++ = (get_bits) (&s->gb, len) << (8 - len); |
|
|
|
*q++ = (get_bits) (&s->gb, len) << (8 - len); |
|
|
|
} |
|
|
|
|
|
|
|
memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
|
|
|
memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
/* XXX: bit_offset bits into last frame */ |
|
|
|
/* XXX: bit_offset bits into last frame */ |
|
|
|
init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset); |
|
|
|
init_get_bits(&s->gb, s->last_superframe, |
|
|
|
|
|
|
|
s->last_superframe_len * 8 + bit_offset); |
|
|
|
/* skip unused bits */ |
|
|
|
/* skip unused bits */ |
|
|
|
if (s->last_bitoffset > 0) |
|
|
|
if (s->last_bitoffset > 0) |
|
|
|
skip_bits(&s->gb, s->last_bitoffset); |
|
|
|
skip_bits(&s->gb, s->last_bitoffset); |
|
|
|
/* this frame is stored in the last superframe and in the
|
|
|
|
/* this frame is stored in the last superframe and in the
|
|
|
|
current one */ |
|
|
|
* current one */ |
|
|
|
if (wma_decode_frame(s, samples, samples_offset) < 0) |
|
|
|
if (wma_decode_frame(s, samples, samples_offset) < 0) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
samples_offset += s->frame_len; |
|
|
|
samples_offset += s->frame_len; |
|
|
@ -888,7 +886,8 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* we copy the end of the frame in the last frame buffer */ |
|
|
|
/* we copy the end of the frame in the last frame buffer */ |
|
|
|
pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7); |
|
|
|
pos = get_bits_count(&s->gb) + |
|
|
|
|
|
|
|
((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7); |
|
|
|
s->last_bitoffset = pos & 7; |
|
|
|
s->last_bitoffset = pos & 7; |
|
|
|
pos >>= 3; |
|
|
|
pos >>= 3; |
|
|
|
len = buf_size - pos; |
|
|
|
len = buf_size - pos; |
|
|
@ -912,6 +911,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data, |
|
|
|
*got_frame_ptr = 1; |
|
|
|
*got_frame_ptr = 1; |
|
|
|
|
|
|
|
|
|
|
|
return avctx->block_align; |
|
|
|
return avctx->block_align; |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
|
/* when error, we reset the bit reservoir */ |
|
|
|
/* when error, we reset the bit reservoir */ |
|
|
|
s->last_superframe_len = 0; |
|
|
|
s->last_superframe_len = 0; |
|
|
|