annotate ffmpeg/libavcodec/ac3.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Common code between the AC-3 encoder and decoder
yading@10 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 /**
yading@10 23 * @file
yading@10 24 * Common code between the AC-3 encoder and decoder.
yading@10 25 */
yading@10 26
yading@10 27 #ifndef AVCODEC_AC3_H
yading@10 28 #define AVCODEC_AC3_H
yading@10 29
yading@10 30 #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
yading@10 31 #define AC3_MAX_CHANNELS 7 /**< maximum number of channels, including coupling channel */
yading@10 32 #define CPL_CH 0 /**< coupling channel index */
yading@10 33
yading@10 34 #define AC3_MAX_COEFS 256
yading@10 35 #define AC3_BLOCK_SIZE 256
yading@10 36 #define AC3_MAX_BLOCKS 6
yading@10 37 #define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256)
yading@10 38 #define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2)
yading@10 39 #define AC3_CRITICAL_BANDS 50
yading@10 40 #define AC3_MAX_CPL_BANDS 18
yading@10 41
yading@10 42 #include "libavutil/opt.h"
yading@10 43 #include "avcodec.h"
yading@10 44 #include "ac3tab.h"
yading@10 45
yading@10 46 /* exponent encoding strategy */
yading@10 47 #define EXP_REUSE 0
yading@10 48 #define EXP_NEW 1
yading@10 49
yading@10 50 #define EXP_D15 1
yading@10 51 #define EXP_D25 2
yading@10 52 #define EXP_D45 3
yading@10 53
yading@10 54 /* pre-defined gain values */
yading@10 55 #define LEVEL_PLUS_3DB 1.4142135623730950
yading@10 56 #define LEVEL_PLUS_1POINT5DB 1.1892071150027209
yading@10 57 #define LEVEL_MINUS_1POINT5DB 0.8408964152537145
yading@10 58 #define LEVEL_MINUS_3DB 0.7071067811865476
yading@10 59 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605
yading@10 60 #define LEVEL_MINUS_6DB 0.5000000000000000
yading@10 61 #define LEVEL_MINUS_9DB 0.3535533905932738
yading@10 62 #define LEVEL_ZERO 0.0000000000000000
yading@10 63 #define LEVEL_ONE 1.0000000000000000
yading@10 64
yading@10 65 /** Delta bit allocation strategy */
yading@10 66 typedef enum {
yading@10 67 DBA_REUSE = 0,
yading@10 68 DBA_NEW,
yading@10 69 DBA_NONE,
yading@10 70 DBA_RESERVED
yading@10 71 } AC3DeltaStrategy;
yading@10 72
yading@10 73 /** Channel mode (audio coding mode) */
yading@10 74 typedef enum {
yading@10 75 AC3_CHMODE_DUALMONO = 0,
yading@10 76 AC3_CHMODE_MONO,
yading@10 77 AC3_CHMODE_STEREO,
yading@10 78 AC3_CHMODE_3F,
yading@10 79 AC3_CHMODE_2F1R,
yading@10 80 AC3_CHMODE_3F1R,
yading@10 81 AC3_CHMODE_2F2R,
yading@10 82 AC3_CHMODE_3F2R
yading@10 83 } AC3ChannelMode;
yading@10 84
yading@10 85 typedef struct AC3BitAllocParameters {
yading@10 86 int sr_code;
yading@10 87 int sr_shift;
yading@10 88 int slow_gain, slow_decay, fast_decay, db_per_bit, floor;
yading@10 89 int cpl_fast_leak, cpl_slow_leak;
yading@10 90 } AC3BitAllocParameters;
yading@10 91
yading@10 92 /**
yading@10 93 * @struct AC3HeaderInfo
yading@10 94 * Coded AC-3 header values up to the lfeon element, plus derived values.
yading@10 95 */
yading@10 96 typedef struct AC3HeaderInfo {
yading@10 97 /** @name Coded elements
yading@10 98 * @{
yading@10 99 */
yading@10 100 uint16_t sync_word;
yading@10 101 uint16_t crc1;
yading@10 102 uint8_t sr_code;
yading@10 103 uint8_t bitstream_id;
yading@10 104 uint8_t bitstream_mode;
yading@10 105 uint8_t channel_mode;
yading@10 106 uint8_t lfe_on;
yading@10 107 uint8_t frame_type;
yading@10 108 int substreamid; ///< substream identification
yading@10 109 int center_mix_level; ///< Center mix level index
yading@10 110 int surround_mix_level; ///< Surround mix level index
yading@10 111 uint16_t channel_map;
yading@10 112 int num_blocks; ///< number of audio blocks
yading@10 113 /** @} */
yading@10 114
yading@10 115 /** @name Derived values
yading@10 116 * @{
yading@10 117 */
yading@10 118 uint8_t sr_shift;
yading@10 119 uint16_t sample_rate;
yading@10 120 uint32_t bit_rate;
yading@10 121 uint8_t channels;
yading@10 122 uint16_t frame_size;
yading@10 123 uint64_t channel_layout;
yading@10 124 /** @} */
yading@10 125 } AC3HeaderInfo;
yading@10 126
yading@10 127 typedef enum {
yading@10 128 EAC3_FRAME_TYPE_INDEPENDENT = 0,
yading@10 129 EAC3_FRAME_TYPE_DEPENDENT,
yading@10 130 EAC3_FRAME_TYPE_AC3_CONVERT,
yading@10 131 EAC3_FRAME_TYPE_RESERVED
yading@10 132 } EAC3FrameType;
yading@10 133
yading@10 134 void ff_ac3_common_init(void);
yading@10 135
yading@10 136 /**
yading@10 137 * Calculate the log power-spectral density of the input signal.
yading@10 138 * This gives a rough estimate of signal power in the frequency domain by using
yading@10 139 * the spectral envelope (exponents). The psd is also separately grouped
yading@10 140 * into critical bands for use in the calculating the masking curve.
yading@10 141 * 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters
yading@10 142 * determines the reference level.
yading@10 143 *
yading@10 144 * @param[in] exp frequency coefficient exponents
yading@10 145 * @param[in] start starting bin location
yading@10 146 * @param[in] end ending bin location
yading@10 147 * @param[out] psd signal power for each frequency bin
yading@10 148 * @param[out] band_psd signal power for each critical band
yading@10 149 */
yading@10 150 void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
yading@10 151 int16_t *band_psd);
yading@10 152
yading@10 153 /**
yading@10 154 * Calculate the masking curve.
yading@10 155 * First, the excitation is calculated using parameters in s and the signal
yading@10 156 * power in each critical band. The excitation is compared with a predefined
yading@10 157 * hearing threshold table to produce the masking curve. If delta bit
yading@10 158 * allocation information is provided, it is used for adjusting the masking
yading@10 159 * curve, usually to give a closer match to a better psychoacoustic model.
yading@10 160 *
yading@10 161 * @param[in] s adjustable bit allocation parameters
yading@10 162 * @param[in] band_psd signal power for each critical band
yading@10 163 * @param[in] start starting bin location
yading@10 164 * @param[in] end ending bin location
yading@10 165 * @param[in] fast_gain fast gain (estimated signal-to-mask ratio)
yading@10 166 * @param[in] is_lfe whether or not the channel being processed is the LFE
yading@10 167 * @param[in] dba_mode delta bit allocation mode (none, reuse, or new)
yading@10 168 * @param[in] dba_nsegs number of delta segments
yading@10 169 * @param[in] dba_offsets location offsets for each segment
yading@10 170 * @param[in] dba_lengths length of each segment
yading@10 171 * @param[in] dba_values delta bit allocation for each segment
yading@10 172 * @param[out] mask calculated masking curve
yading@10 173 * @return returns 0 for success, non-zero for error
yading@10 174 */
yading@10 175 int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
yading@10 176 int start, int end, int fast_gain, int is_lfe,
yading@10 177 int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
yading@10 178 uint8_t *dba_lengths, uint8_t *dba_values,
yading@10 179 int16_t *mask);
yading@10 180
yading@10 181 #endif /* AVCODEC_AC3_H */