libavcodec/ac3.h
Go to the documentation of this file.
00001 /*
00002  * Common code between the AC-3 encoder and decoder
00003  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #ifndef AVCODEC_AC3_H
00028 #define AVCODEC_AC3_H
00029 
00030 #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
00031 #define AC3_MAX_CHANNELS 7            
00032 #define CPL_CH 0                      
00034 #define AC3_MAX_COEFS   256
00035 #define AC3_BLOCK_SIZE  256
00036 #define AC3_MAX_BLOCKS    6
00037 #define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256)
00038 #define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2)
00039 #define AC3_CRITICAL_BANDS 50
00040 #define AC3_MAX_CPL_BANDS  18
00041 
00042 #include "libavutil/opt.h"
00043 #include "avcodec.h"
00044 #include "ac3tab.h"
00045 
00046 /* exponent encoding strategy */
00047 #define EXP_REUSE 0
00048 #define EXP_NEW   1
00049 
00050 #define EXP_D15   1
00051 #define EXP_D25   2
00052 #define EXP_D45   3
00053 
00054 /* pre-defined gain values */
00055 #define LEVEL_PLUS_3DB          1.4142135623730950
00056 #define LEVEL_PLUS_1POINT5DB    1.1892071150027209
00057 #define LEVEL_MINUS_1POINT5DB   0.8408964152537145
00058 #define LEVEL_MINUS_3DB         0.7071067811865476
00059 #define LEVEL_MINUS_4POINT5DB   0.5946035575013605
00060 #define LEVEL_MINUS_6DB         0.5000000000000000
00061 #define LEVEL_MINUS_9DB         0.3535533905932738
00062 #define LEVEL_ZERO              0.0000000000000000
00063 #define LEVEL_ONE               1.0000000000000000
00064 
00066 typedef enum {
00067     DBA_REUSE = 0,
00068     DBA_NEW,
00069     DBA_NONE,
00070     DBA_RESERVED
00071 } AC3DeltaStrategy;
00072 
00074 typedef enum {
00075     AC3_CHMODE_DUALMONO = 0,
00076     AC3_CHMODE_MONO,
00077     AC3_CHMODE_STEREO,
00078     AC3_CHMODE_3F,
00079     AC3_CHMODE_2F1R,
00080     AC3_CHMODE_3F1R,
00081     AC3_CHMODE_2F2R,
00082     AC3_CHMODE_3F2R
00083 } AC3ChannelMode;
00084 
00085 typedef struct AC3BitAllocParameters {
00086     int sr_code;
00087     int sr_shift;
00088     int slow_gain, slow_decay, fast_decay, db_per_bit, floor;
00089     int cpl_fast_leak, cpl_slow_leak;
00090 } AC3BitAllocParameters;
00091 
00096 typedef struct {
00100     uint16_t sync_word;
00101     uint16_t crc1;
00102     uint8_t sr_code;
00103     uint8_t bitstream_id;
00104     uint8_t bitstream_mode;
00105     uint8_t channel_mode;
00106     uint8_t lfe_on;
00107     uint8_t frame_type;
00108     int substreamid;                        
00109     int center_mix_level;                   
00110     int surround_mix_level;                 
00111     uint16_t channel_map;
00112     int num_blocks;                         
00113 
00118     uint8_t sr_shift;
00119     uint16_t sample_rate;
00120     uint32_t bit_rate;
00121     uint8_t channels;
00122     uint16_t frame_size;
00123     uint64_t channel_layout;
00125 } AC3HeaderInfo;
00126 
00127 typedef enum {
00128     EAC3_FRAME_TYPE_INDEPENDENT = 0,
00129     EAC3_FRAME_TYPE_DEPENDENT,
00130     EAC3_FRAME_TYPE_AC3_CONVERT,
00131     EAC3_FRAME_TYPE_RESERVED
00132 } EAC3FrameType;
00133 
00134 void ff_ac3_common_init(void);
00135 
00150 void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
00151                                int16_t *band_psd);
00152 
00175 int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
00176                                int start, int end, int fast_gain, int is_lfe,
00177                                int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
00178                                uint8_t *dba_lengths, uint8_t *dba_values,
00179                                int16_t *mask);
00180 
00181 #endif /* AVCODEC_AC3_H */