|
|
@ -39,6 +39,42 @@ |
|
|
|
static const AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, |
|
|
|
static const AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, |
|
|
|
ac3_options, LIBAVUTIL_VERSION_INT }; |
|
|
|
ac3_options, LIBAVUTIL_VERSION_INT }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Scale MDCT coefficients from float to 24-bit fixed-point. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void scale_coefficients(AC3EncodeContext *s) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int chan_size = AC3_MAX_COEFS * s->num_blocks; |
|
|
|
|
|
|
|
int cpl = s->cpl_on; |
|
|
|
|
|
|
|
s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl), |
|
|
|
|
|
|
|
s->mdct_coef_buffer + (chan_size * !cpl), |
|
|
|
|
|
|
|
chan_size * (s->channels + cpl)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Clip MDCT coefficients to allowable range. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void clip_coefficients(AudioDSPContext *adsp, float *coef, |
|
|
|
|
|
|
|
unsigned int len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
adsp->vector_clipf(coef, coef, len, COEF_MIN, COEF_MAX); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Calculate a single coupling coordinate. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
float coord = 0.125; |
|
|
|
|
|
|
|
if (energy_cpl > 0) |
|
|
|
|
|
|
|
coord *= sqrtf(energy_ch / energy_cpl); |
|
|
|
|
|
|
|
return FFMIN(coord, COEF_MAX); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ac3enc_template.c" |
|
|
|
#include "ac3enc_template.c" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,40 +118,6 @@ av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Scale MDCT coefficients from float to 24-bit fixed-point. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void scale_coefficients(AC3EncodeContext *s) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int chan_size = AC3_MAX_COEFS * s->num_blocks; |
|
|
|
|
|
|
|
int cpl = s->cpl_on; |
|
|
|
|
|
|
|
s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl), |
|
|
|
|
|
|
|
s->mdct_coef_buffer + (chan_size * !cpl), |
|
|
|
|
|
|
|
chan_size * (s->channels + cpl)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Clip MDCT coefficients to allowable range. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static void clip_coefficients(AudioDSPContext *adsp, float *coef, |
|
|
|
|
|
|
|
unsigned int len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
adsp->vector_clipf(coef, coef, len, COEF_MIN, COEF_MAX); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Calculate a single coupling coordinate. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
float coord = 0.125; |
|
|
|
|
|
|
|
if (energy_cpl > 0) |
|
|
|
|
|
|
|
coord *= sqrtf(energy_ch / energy_cpl); |
|
|
|
|
|
|
|
return FFMIN(coord, COEF_MAX); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) |
|
|
|
av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AC3EncodeContext *s = avctx->priv_data; |
|
|
|
AC3EncodeContext *s = avctx->priv_data; |
|
|
|