Libav 0.7.1
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 Libav.
00008  *
00009  * Libav 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  * Libav 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 Libav; 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 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 
00048 av_cold void ff_ac3_float_mdct_end(AC3MDCTContext *mdct)
00049 {
00050     ff_mdct_end(&mdct->fft);
00051     av_freep(&mdct->window);
00052 }
00053 
00054 
00059 av_cold int ff_ac3_float_mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
00060                                    int nbits)
00061 {
00062     float *window;
00063     int i, n, n2;
00064 
00065     n  = 1 << nbits;
00066     n2 = n >> 1;
00067 
00068     window = av_malloc(n * sizeof(*window));
00069     if (!window) {
00070         av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
00071         return AVERROR(ENOMEM);
00072     }
00073     ff_kbd_window_init(window, 5.0, n2);
00074     for (i = 0; i < n2; i++)
00075         window[n-1-i] = window[i];
00076     mdct->window = window;
00077 
00078     return ff_mdct_init(&mdct->fft, nbits, 0, -2.0 / n);
00079 }
00080 
00081 
00085 void ff_ac3_float_apply_window(DSPContext *dsp, float *output,
00086                                const float *input, const float *window,
00087                                unsigned int len)
00088 {
00089     dsp->vector_fmul(output, input, window, len);
00090 }
00091 
00092 
00096 void ff_ac3_float_scale_coefficients(AC3EncodeContext *s)
00097 {
00098     int chan_size = AC3_MAX_COEFS * AC3_MAX_BLOCKS;
00099     s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + chan_size,
00100                                s->mdct_coef_buffer  + chan_size,
00101                                chan_size * s->channels);
00102 }
00103 
00104 
00105 #if CONFIG_AC3_ENCODER
00106 AVCodec ff_ac3_encoder = {
00107     "ac3",
00108     AVMEDIA_TYPE_AUDIO,
00109     CODEC_ID_AC3,
00110     sizeof(AC3EncodeContext),
00111     ff_ac3_encode_init,
00112     ff_ac3_encode_frame,
00113     ff_ac3_encode_close,
00114     NULL,
00115     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
00116     .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
00117     .priv_class = &ac3enc_class,
00118     .channel_layouts = ff_ac3_channel_layouts,
00119 };
00120 #endif