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
00038 static const AVClass ac3enc_class = {
00039 .class_name = "Fixed-Point AC-3 Encoder",
00040 .item_name = av_default_item_name,
00041 .option = ac3_options,
00042 .version = LIBAVUTIL_VERSION_INT,
00043 };
00044
00045 #include "ac3enc_template.c"
00046
00047
00053 av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
00054 {
00055 ff_mdct_end(&s->mdct);
00056 }
00057
00058
00065 av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
00066 {
00067 int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
00068 s->mdct_window = ff_ac3_window;
00069 return ret;
00070 }
00071
00072
00073
00074
00075
00076 static void apply_window(void *dsp, int16_t *output, const int16_t *input,
00077 const int16_t *window, unsigned int len)
00078 {
00079 DSPContext *dsp0 = dsp;
00080 dsp0->apply_window_int16(output, input, window, len);
00081 }
00082
00083
00084
00085
00086
00087
00088 static int normalize_samples(AC3EncodeContext *s)
00089 {
00090 int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE);
00091 v = 14 - av_log2(v);
00092 if (v > 0)
00093 s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
00094
00095 return v + 6;
00096 }
00097
00098
00099
00100
00101
00102 static void scale_coefficients(AC3EncodeContext *s)
00103 {
00104 int blk, ch;
00105
00106 for (blk = 0; blk < s->num_blocks; blk++) {
00107 AC3Block *block = &s->blocks[blk];
00108 for (ch = 1; ch <= s->channels; ch++) {
00109 s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
00110 block->coeff_shift[ch]);
00111 }
00112 }
00113 }
00114
00115 static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4],
00116 const int32_t *coef0, const int32_t *coef1,
00117 int len)
00118 {
00119 s->ac3dsp.sum_square_butterfly_int32(sum, coef0, coef1, len);
00120 }
00121
00122
00123
00124
00125 static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
00126 {
00127 dsp->vector_clip_int32(coef, coef, COEF_MIN, COEF_MAX, len);
00128 }
00129
00130
00131
00132
00133
00134 static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
00135 {
00136 if (energy_cpl <= COEF_MAX) {
00137 return 1048576;
00138 } else {
00139 uint64_t coord = energy_ch / (energy_cpl >> 24);
00140 uint32_t coord32 = FFMIN(coord, 1073741824);
00141 coord32 = ff_sqrt(coord32) << 9;
00142 return FFMIN(coord32, COEF_MAX);
00143 }
00144 }
00145
00146
00147 static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
00148 {
00149 AC3EncodeContext *s = avctx->priv_data;
00150 s->fixed_point = 1;
00151 return ff_ac3_encode_init(avctx);
00152 }
00153
00154
00155 AVCodec ff_ac3_fixed_encoder = {
00156 .name = "ac3_fixed",
00157 .type = AVMEDIA_TYPE_AUDIO,
00158 .id = AV_CODEC_ID_AC3,
00159 .priv_data_size = sizeof(AC3EncodeContext),
00160 .init = ac3_fixed_encode_init,
00161 .encode2 = ff_ac3_fixed_encode_frame,
00162 .close = ff_ac3_encode_close,
00163 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
00164 AV_SAMPLE_FMT_NONE },
00165 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
00166 .priv_class = &ac3enc_class,
00167 .channel_layouts = ff_ac3_channel_layouts,
00168 .defaults = ac3_defaults,
00169 };