00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #define CONFIG_FFT_FLOAT 0
00030 #undef CONFIG_AC3ENC_FLOAT
00031 #include "internal.h"
00032 #include "ac3enc.h"
00033 #include "eac3enc.h"
00034
00035 #define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
00036 #include "ac3enc_opts_template.c"
00037 static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
00038 ac3fixed_options, LIBAVUTIL_VERSION_INT };
00039
00040 #include "ac3enc_template.c"
00041
00042
00048 av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
00049 {
00050 ff_mdct_end(&s->mdct);
00051 }
00052
00053
00060 av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
00061 {
00062 int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
00063 s->mdct_window = ff_ac3_window;
00064 return ret;
00065 }
00066
00067
00068
00069
00070
00071 static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input,
00072 const int16_t *window, unsigned int len)
00073 {
00074 dsp->apply_window_int16(output, input, window, len);
00075 }
00076
00077
00078
00079
00080
00081
00082 static int normalize_samples(AC3EncodeContext *s)
00083 {
00084 int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE);
00085 v = 14 - av_log2(v);
00086 if (v > 0)
00087 s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
00088
00089 return v + 6;
00090 }
00091
00092
00093
00094
00095
00096 static void scale_coefficients(AC3EncodeContext *s)
00097 {
00098 int blk, ch;
00099
00100 for (blk = 0; blk < s->num_blocks; blk++) {
00101 AC3Block *block = &s->blocks[blk];
00102 for (ch = 1; ch <= s->channels; ch++) {
00103 s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
00104 block->coeff_shift[ch]);
00105 }
00106 }
00107 }
00108
00109 static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4],
00110 const int32_t *coef0, const int32_t *coef1,
00111 int len)
00112 {
00113 s->ac3dsp.sum_square_butterfly_int32(sum, coef0, coef1, len);
00114 }
00115
00116
00117
00118
00119 static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
00120 {
00121 dsp->vector_clip_int32(coef, coef, COEF_MIN, COEF_MAX, len);
00122 }
00123
00124
00125
00126
00127
00128 static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
00129 {
00130 if (energy_cpl <= COEF_MAX) {
00131 return 1048576;
00132 } else {
00133 uint64_t coord = energy_ch / (energy_cpl >> 24);
00134 uint32_t coord32 = FFMIN(coord, 1073741824);
00135 coord32 = ff_sqrt(coord32) << 9;
00136 return FFMIN(coord32, COEF_MAX);
00137 }
00138 }
00139
00140
00141 static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
00142 {
00143 AC3EncodeContext *s = avctx->priv_data;
00144 s->fixed_point = 1;
00145 return ff_ac3_encode_init(avctx);
00146 }
00147
00148
00149 AVCodec ff_ac3_fixed_encoder = {
00150 .name = "ac3_fixed",
00151 .type = AVMEDIA_TYPE_AUDIO,
00152 .id = CODEC_ID_AC3,
00153 .priv_data_size = sizeof(AC3EncodeContext),
00154 .init = ac3_fixed_encode_init,
00155 .encode2 = ff_ac3_fixed_encode_frame,
00156 .close = ff_ac3_encode_close,
00157 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
00158 AV_SAMPLE_FMT_NONE },
00159 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
00160 .priv_class = &ac3enc_class,
00161 .channel_layouts = ff_ac3_channel_layouts,
00162 .defaults = ac3_defaults,
00163 };