Libav 0.7.1
|
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_FFT_FLOAT 0 00030 #undef CONFIG_AC3ENC_FLOAT 00031 #include "ac3enc.h" 00032 00033 #define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED 00034 #include "ac3enc_opts_template.c" 00035 static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name, 00036 ac3fixed_options, LIBAVUTIL_VERSION_INT }; 00037 00038 #include "ac3enc_template.c" 00039 00040 00044 av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct) 00045 { 00046 ff_mdct_end(&mdct->fft); 00047 } 00048 00049 00054 av_cold int AC3_NAME(mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct, 00055 int nbits) 00056 { 00057 int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0); 00058 mdct->window = ff_ac3_window; 00059 return ret; 00060 } 00061 00062 00066 void AC3_NAME(apply_window)(DSPContext *dsp, int16_t *output, 00067 const int16_t *input, const int16_t *window, 00068 unsigned int len) 00069 { 00070 dsp->apply_window_int16(output, input, window, len); 00071 } 00072 00073 00080 static int log2_tab(AC3EncodeContext *s, int16_t *src, int len) 00081 { 00082 int v = s->ac3dsp.ac3_max_msb_abs_int16(src, len); 00083 return av_log2(v); 00084 } 00085 00086 00093 int AC3_NAME(normalize_samples)(AC3EncodeContext *s) 00094 { 00095 int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE); 00096 if (v > 0) 00097 s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v); 00098 /* +6 to right-shift from 31-bit to 25-bit */ 00099 return v + 6; 00100 } 00101 00102 00106 void AC3_NAME(scale_coefficients)(AC3EncodeContext *s) 00107 { 00108 int blk, ch; 00109 00110 for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { 00111 AC3Block *block = &s->blocks[blk]; 00112 for (ch = 1; ch <= s->channels; ch++) { 00113 s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS, 00114 block->coeff_shift[ch]); 00115 } 00116 } 00117 } 00118 00119 00120 static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) 00121 { 00122 AC3EncodeContext *s = avctx->priv_data; 00123 s->fixed_point = 1; 00124 return ff_ac3_encode_init(avctx); 00125 } 00126 00127 00128 AVCodec ff_ac3_fixed_encoder = { 00129 "ac3_fixed", 00130 AVMEDIA_TYPE_AUDIO, 00131 CODEC_ID_AC3, 00132 sizeof(AC3EncodeContext), 00133 ac3_fixed_encode_init, 00134 ff_ac3_encode_frame, 00135 ff_ac3_encode_close, 00136 NULL, 00137 .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, 00138 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), 00139 .priv_class = &ac3enc_class, 00140 .channel_layouts = ff_ac3_channel_layouts, 00141 };