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_AC3ENC_FLOAT 1
00030 #include "internal.h"
00031 #include "ac3enc.h"
00032 #include "eac3enc.h"
00033 #include "kbdwin.h"
00034
00035
00036 #if CONFIG_AC3_ENCODER
00037 #define AC3ENC_TYPE AC3ENC_TYPE_AC3
00038 #include "ac3enc_opts_template.c"
00039 static const AVClass ac3enc_class = {
00040 .class_name = "AC-3 Encoder",
00041 .item_name = av_default_item_name,
00042 .option = ac3_options,
00043 .version = LIBAVUTIL_VERSION_INT,
00044 };
00045 #endif
00046
00047 #include "ac3enc_template.c"
00048
00049
00055 av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s)
00056 {
00057 ff_mdct_end(&s->mdct);
00058 av_freep(&s->mdct_window);
00059 }
00060
00061
00068 av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s)
00069 {
00070 float *window;
00071 int i, n, n2;
00072
00073 n = 1 << 9;
00074 n2 = n >> 1;
00075
00076 window = av_malloc(n * sizeof(*window));
00077 if (!window) {
00078 av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
00079 return AVERROR(ENOMEM);
00080 }
00081 ff_kbd_window_init(window, 5.0, n2);
00082 for (i = 0; i < n2; i++)
00083 window[n-1-i] = window[i];
00084 s->mdct_window = window;
00085
00086 return ff_mdct_init(&s->mdct, 9, 0, -2.0 / n);
00087 }
00088
00089
00090
00091
00092
00093 static void apply_window(void *dsp, float *output,
00094 const float *input, const float *window,
00095 unsigned int len)
00096 {
00097 AVFloatDSPContext *fdsp = dsp;
00098 fdsp->vector_fmul(output, input, window, len);
00099 }
00100
00101
00102
00103
00104
00105
00106 static int normalize_samples(AC3EncodeContext *s)
00107 {
00108 return 0;
00109 }
00110
00111
00112
00113
00114
00115 static void scale_coefficients(AC3EncodeContext *s)
00116 {
00117 int chan_size = AC3_MAX_COEFS * s->num_blocks;
00118 int cpl = s->cpl_on;
00119 s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl),
00120 s->mdct_coef_buffer + (chan_size * !cpl),
00121 chan_size * (s->channels + cpl));
00122 }
00123
00124 static void sum_square_butterfly(AC3EncodeContext *s, float sum[4],
00125 const float *coef0, const float *coef1,
00126 int len)
00127 {
00128 s->ac3dsp.sum_square_butterfly_float(sum, coef0, coef1, len);
00129 }
00130
00131
00132
00133
00134 static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len)
00135 {
00136 dsp->vector_clipf(coef, coef, COEF_MIN, COEF_MAX, len);
00137 }
00138
00139
00140
00141
00142
00143 static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
00144 {
00145 float coord = 0.125;
00146 if (energy_cpl > 0)
00147 coord *= sqrtf(energy_ch / energy_cpl);
00148 return FFMIN(coord, COEF_MAX);
00149 }
00150
00151
00152 #if CONFIG_AC3_ENCODER
00153 AVCodec ff_ac3_encoder = {
00154 .name = "ac3",
00155 .type = AVMEDIA_TYPE_AUDIO,
00156 .id = AV_CODEC_ID_AC3,
00157 .priv_data_size = sizeof(AC3EncodeContext),
00158 .init = ff_ac3_encode_init,
00159 .encode2 = ff_ac3_float_encode_frame,
00160 .close = ff_ac3_encode_close,
00161 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
00162 AV_SAMPLE_FMT_NONE },
00163 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
00164 .priv_class = &ac3enc_class,
00165 .channel_layouts = ff_ac3_channel_layouts,
00166 .defaults = ac3_defaults,
00167 };
00168 #endif