comparison aacenc.c @ 7574:27ee0ceab150 libavcodec

Remove not OKed parts from AAC encoder
author kostya
date Thu, 14 Aug 2008 16:07:17 +0000
parents 58f6bb760994
children d8717018ac03
comparison
equal deleted inserted replaced
7573:7802295cae6f 7574:27ee0ceab150
115 duplicate of swb_size_128_96 */ 115 duplicate of swb_size_128_96 */
116 swb_size_128_96, swb_size_128_96, swb_size_128_96, 116 swb_size_128_96, swb_size_128_96, swb_size_128_96,
117 swb_size_128_48, swb_size_128_48, swb_size_128_48, 117 swb_size_128_48, swb_size_128_48, swb_size_128_48,
118 swb_size_128_24, swb_size_128_24, swb_size_128_16, 118 swb_size_128_24, swb_size_128_24, swb_size_128_16,
119 swb_size_128_16, swb_size_128_16, swb_size_128_8 119 swb_size_128_16, swb_size_128_16, swb_size_128_8
120 };
121
122 #define CB_UNSIGNED 0x01 ///< coefficients are coded as absolute values
123 #define CB_PAIRS 0x02 ///< coefficients are grouped into pairs before coding (quads by default)
124 #define CB_ESCAPE 0x04 ///< codebook allows escapes
125
126 /** spectral coefficients codebook information */
127 static const struct {
128 int16_t maxval; ///< maximum possible value
129 int8_t cb_num; ///< codebook number
130 uint8_t flags; ///< codebook features
131 } aac_cb_info[] = {
132 { 0, -1, CB_UNSIGNED }, // zero codebook
133 { 1, 0, 0 },
134 { 1, 1, 0 },
135 { 2, 2, CB_UNSIGNED },
136 { 2, 3, CB_UNSIGNED },
137 { 4, 4, CB_PAIRS },
138 { 4, 5, CB_PAIRS },
139 { 7, 6, CB_PAIRS | CB_UNSIGNED },
140 { 7, 7, CB_PAIRS | CB_UNSIGNED },
141 { 12, 8, CB_PAIRS | CB_UNSIGNED },
142 { 12, 9, CB_PAIRS | CB_UNSIGNED },
143 { 8191, 10, CB_PAIRS | CB_UNSIGNED | CB_ESCAPE },
144 { -1, -1, 0 }, // reserved
145 { -1, -1, 0 }, // perceptual noise substitution
146 { -1, -1, 0 }, // intensity out-of-phase
147 { -1, -1, 0 }, // intensity in-phase
148 }; 120 };
149 121
150 /** default channel configurations */ 122 /** default channel configurations */
151 static const uint8_t aac_chan_configs[6][5] = { 123 static const uint8_t aac_chan_configs[6][5] = {
152 {1, ID_SCE}, // 1 channel - single channel element 124 {1, ID_SCE}, // 1 channel - single channel element
154 {2, ID_SCE, ID_CPE}, // 3 channels - center + stereo 126 {2, ID_SCE, ID_CPE}, // 3 channels - center + stereo
155 {3, ID_SCE, ID_CPE, ID_SCE}, // 4 channels - front center + stereo + back center 127 {3, ID_SCE, ID_CPE, ID_SCE}, // 4 channels - front center + stereo + back center
156 {3, ID_SCE, ID_CPE, ID_CPE}, // 5 channels - front center + stereo + back stereo 128 {3, ID_SCE, ID_CPE, ID_CPE}, // 5 channels - front center + stereo + back stereo
157 {4, ID_SCE, ID_CPE, ID_CPE, ID_LFE}, // 6 channels - front center + stereo + back stereo + LFE 129 {4, ID_SCE, ID_CPE, ID_CPE, ID_LFE}, // 6 channels - front center + stereo + back stereo + LFE
158 }; 130 };
159
160 /**
161 * AAC encoder context
162 */
163 typedef struct {
164 PutBitContext pb;
165 MDCTContext mdct1024; ///< long (1024 samples) frame transform context
166 MDCTContext mdct128; ///< short (128 samples) frame transform context
167 DSPContext dsp;
168 DECLARE_ALIGNED_16(FFTSample, output[2048]); ///< temporary buffer for MDCT input coefficients
169 DECLARE_ALIGNED_16(FFTSample, tmp[1024]); ///< temporary buffer used by MDCT
170 int16_t* samples; ///< saved preprocessed input
171
172 int samplerate_index; ///< MPEG-4 samplerate index
173 const uint8_t *swb_sizes1024; ///< scalefactor band sizes for long frame
174 int swb_num1024; ///< number of scalefactor bands for long frame
175 const uint8_t *swb_sizes128; ///< scalefactor band sizes for short frame
176 int swb_num128; ///< number of scalefactor bands for short frame
177
178 ChannelElement *cpe; ///< channel elements
179 AACPsyContext psy; ///< psychoacoustic model context
180 int last_frame;
181 } AACEncContext;
182 131
183 /** 132 /**
184 * Make AAC audio config object. 133 * Make AAC audio config object.
185 * @see 1.6.2.1 "Syntax - AudioSpecificConfig" 134 * @see 1.6.2.1 "Syntax - AudioSpecificConfig"
186 */ 135 */
225 s->swb_num128 = ff_aac_num_swb_128[i]; 174 s->swb_num128 = ff_aac_num_swb_128[i];
226 175
227 dsputil_init(&s->dsp, avctx); 176 dsputil_init(&s->dsp, avctx);
228 ff_mdct_init(&s->mdct1024, 11, 0); 177 ff_mdct_init(&s->mdct1024, 11, 0);
229 ff_mdct_init(&s->mdct128, 8, 0); 178 ff_mdct_init(&s->mdct128, 8, 0);
230 // window init
231 ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
232 ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
233 ff_sine_window_init(ff_aac_sine_long_1024, 1024);
234 ff_sine_window_init(ff_aac_sine_short_128, 128);
235 179
236 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); 180 s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));
237 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); 181 s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]);
238 if(ff_aac_psy_init(&s->psy, avctx, AAC_PSY_3GPP, aac_chan_configs[avctx->channels-1][0], 0, s->swb_sizes1024, s->swb_num1024, s->swb_sizes128, s->swb_num128) < 0){ 182 if(ff_aac_psy_init(&s->psy, avctx, AAC_PSY_3GPP, aac_chan_configs[avctx->channels-1][0], 0, s->swb_sizes1024, s->swb_num1024, s->swb_sizes128, s->swb_num128) < 0){
239 av_log(avctx, AV_LOG_ERROR, "Cannot initialize selected model.\n"); 183 av_log(avctx, AV_LOG_ERROR, "Cannot initialize selected model.\n");