• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/ac3enc_float.c

Go to the documentation of this file.
00001 /*
00002  * The simplest AC-3 encoder
00003  * Copyright (c) 2000 Fabrice Bellard
00004  * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
00005  * Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
00006  *
00007  * This file is part of FFmpeg.
00008  *
00009  * FFmpeg is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * FFmpeg is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with FFmpeg; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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  * Apply KBD window to input samples prior to MDCT.
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  * Normalize the input samples.
00097  * Not needed for the floating-point encoder.
00098  */
00099 static int normalize_samples(AC3EncodeContext *s)
00100 {
00101     return 0;
00102 }
00103 
00104 
00105 /*
00106  * Scale MDCT coefficients from float to 24-bit fixed-point.
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  * Clip MDCT coefficients to allowable range.
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  * Calculate a single coupling coordinate.
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
Generated on Fri Feb 1 2013 14:34:29 for FFmpeg by doxygen 1.7.1