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