|
|
@ -38,10 +38,10 @@ static av_cold int encode_init(AVCodecContext *avctx) |
|
|
|
|
|
|
|
|
|
|
|
s->avctx = avctx; |
|
|
|
s->avctx = avctx; |
|
|
|
|
|
|
|
|
|
|
|
if (avctx->channels > MAX_CHANNELS) { |
|
|
|
if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, |
|
|
|
av_log(avctx, AV_LOG_ERROR, |
|
|
|
"too many channels: got %i, need %i or fewer\n", |
|
|
|
"too many channels: got %i, need %i or fewer\n", |
|
|
|
avctx->channels, MAX_CHANNELS); |
|
|
|
avctx->ch_layout.nb_channels, MAX_CHANNELS); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
return AVERROR(EINVAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -82,7 +82,7 @@ static av_cold int encode_init(AVCodecContext *avctx) |
|
|
|
s->use_exp_vlc = flags2 & 0x0001; |
|
|
|
s->use_exp_vlc = flags2 & 0x0001; |
|
|
|
s->use_bit_reservoir = flags2 & 0x0002; |
|
|
|
s->use_bit_reservoir = flags2 & 0x0002; |
|
|
|
s->use_variable_block_len = flags2 & 0x0004; |
|
|
|
s->use_variable_block_len = flags2 & 0x0004; |
|
|
|
if (avctx->channels == 2) |
|
|
|
if (avctx->ch_layout.nb_channels == 2) |
|
|
|
s->ms_stereo = 1; |
|
|
|
s->ms_stereo = 1; |
|
|
|
|
|
|
|
|
|
|
|
if ((ret = ff_wma_init(avctx, flags2)) < 0) |
|
|
|
if ((ret = ff_wma_init(avctx, flags2)) < 0) |
|
|
@ -116,7 +116,7 @@ static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame) |
|
|
|
int window_len = 1 << s->block_len_bits; |
|
|
|
int window_len = 1 << s->block_len_bits; |
|
|
|
float n = 2.0 * 32768.0 / window_len; |
|
|
|
float n = 2.0 * 32768.0 / window_len; |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { |
|
|
|
memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output)); |
|
|
|
memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output)); |
|
|
|
s->fdsp->vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len); |
|
|
|
s->fdsp->vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len); |
|
|
|
s->fdsp->vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], |
|
|
|
s->fdsp->vector_fmul_reverse(&s->output[window_len], s->frame_out[ch], |
|
|
@ -186,6 +186,7 @@ static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param) |
|
|
|
static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
int total_gain) |
|
|
|
int total_gain) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int channels = s->avctx->ch_layout.nb_channels; |
|
|
|
int v, bsize, ch, coef_nb_bits, parse_exponents; |
|
|
|
int v, bsize, ch, coef_nb_bits, parse_exponents; |
|
|
|
float mdct_norm; |
|
|
|
float mdct_norm; |
|
|
|
int nb_coefs[MAX_CHANNELS]; |
|
|
|
int nb_coefs[MAX_CHANNELS]; |
|
|
@ -213,7 +214,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
|
|
|
|
|
|
|
|
// FIXME factor
|
|
|
|
// FIXME factor
|
|
|
|
v = s->coefs_end[bsize] - s->coefs_start; |
|
|
|
v = s->coefs_end[bsize] - s->coefs_start; |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) |
|
|
|
for (ch = 0; ch < channels; ch++) |
|
|
|
nb_coefs[ch] = v; |
|
|
|
nb_coefs[ch] = v; |
|
|
|
{ |
|
|
|
{ |
|
|
|
int n4 = s->block_len / 2; |
|
|
|
int n4 = s->block_len / 2; |
|
|
@ -222,17 +223,17 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
mdct_norm *= sqrt(n4); |
|
|
|
mdct_norm *= sqrt(n4); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (s->avctx->channels == 2) |
|
|
|
if (channels == 2) |
|
|
|
put_bits(&s->pb, 1, !!s->ms_stereo); |
|
|
|
put_bits(&s->pb, 1, !!s->ms_stereo); |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
// FIXME only set channel_coded when needed, instead of always
|
|
|
|
// FIXME only set channel_coded when needed, instead of always
|
|
|
|
s->channel_coded[ch] = 1; |
|
|
|
s->channel_coded[ch] = 1; |
|
|
|
if (s->channel_coded[ch]) |
|
|
|
if (s->channel_coded[ch]) |
|
|
|
init_exp(s, ch, fixed_exp); |
|
|
|
init_exp(s, ch, fixed_exp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
WMACoef *coefs1; |
|
|
|
WMACoef *coefs1; |
|
|
|
float *coefs, *exponents, mult; |
|
|
|
float *coefs, *exponents, mult; |
|
|
@ -260,7 +261,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
v = 0; |
|
|
|
v = 0; |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
int a = s->channel_coded[ch]; |
|
|
|
int a = s->channel_coded[ch]; |
|
|
|
put_bits(&s->pb, 1, a); |
|
|
|
put_bits(&s->pb, 1, a); |
|
|
|
v |= a; |
|
|
|
v |= a; |
|
|
@ -276,7 +277,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
coef_nb_bits = ff_wma_total_gain_to_bits(total_gain); |
|
|
|
coef_nb_bits = ff_wma_total_gain_to_bits(total_gain); |
|
|
|
|
|
|
|
|
|
|
|
if (s->use_noise_coding) { |
|
|
|
if (s->use_noise_coding) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
int i, n; |
|
|
|
int i, n; |
|
|
|
n = s->exponent_high_sizes[bsize]; |
|
|
|
n = s->exponent_high_sizes[bsize]; |
|
|
@ -294,7 +295,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
put_bits(&s->pb, 1, parse_exponents); |
|
|
|
put_bits(&s->pb, 1, parse_exponents); |
|
|
|
|
|
|
|
|
|
|
|
if (parse_exponents) { |
|
|
|
if (parse_exponents) { |
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->use_exp_vlc) { |
|
|
|
if (s->use_exp_vlc) { |
|
|
|
encode_exp_vlc(s, ch, fixed_exp); |
|
|
|
encode_exp_vlc(s, ch, fixed_exp); |
|
|
@ -307,7 +308,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
} else |
|
|
|
} else |
|
|
|
av_assert0(0); // FIXME not implemented
|
|
|
|
av_assert0(0); // FIXME not implemented
|
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->avctx->channels; ch++) { |
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
if (s->channel_coded[ch]) { |
|
|
|
int run, tindex; |
|
|
|
int run, tindex; |
|
|
|
WMACoef *ptr, *eptr; |
|
|
|
WMACoef *ptr, *eptr; |
|
|
@ -346,7 +347,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], |
|
|
|
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], |
|
|
|
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], |
|
|
|
s->coef_vlcs[tindex]->huffcodes[1]); |
|
|
|
s->coef_vlcs[tindex]->huffcodes[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
if (s->version == 1 && s->avctx->channels >= 2) |
|
|
|
if (s->version == 1 && channels >= 2) |
|
|
|
align_put_bits(&s->pb); |
|
|
|
align_put_bits(&s->pb); |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|