1 /** 2 * Aften: A/52 audio encoder 3 * Copyright (c) 2006-2007 Justin Ruggles 4 * 2006-2007 Prakash Punnoor <prakash@punnoor.de> 5 * 6 * Based on "The simplest AC3 encoder" from FFmpeg 7 * Copyright (c) 2000 Fabrice Bellard. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 /** 25 * @file aften.h 26 * libaften public header for type definitions 27 */ 28 29 #ifndef AFTEN_TYPES_H 30 #define AFTEN_TYPES_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /** 37 * Some helpful size constants 38 */ 39 enum { 40 A52_MAX_CODED_FRAME_SIZE = 3840, 41 A52_SAMPLES_PER_FRAME = 1536 42 }; 43 44 /** 45 * Aften Encoding Mode 46 */ 47 typedef enum { 48 AFTEN_ENC_MODE_CBR = 0, 49 AFTEN_ENC_MODE_VBR 50 } AftenEncMode; 51 52 /** 53 * Floating-Point Data Types 54 */ 55 typedef enum { 56 FLOAT_TYPE_DOUBLE, 57 FLOAT_TYPE_FLOAT 58 } FloatType; 59 60 /** 61 * Audio Sample Formats 62 */ 63 typedef enum { 64 A52_SAMPLE_FMT_U8 = 0, 65 A52_SAMPLE_FMT_S16, 66 A52_SAMPLE_FMT_S20, 67 A52_SAMPLE_FMT_S24, 68 A52_SAMPLE_FMT_S32, 69 A52_SAMPLE_FMT_FLT, 70 A52_SAMPLE_FMT_DBL 71 } A52SampleFormat; 72 73 /** 74 * Dynamic Range Profiles 75 */ 76 typedef enum { 77 DYNRNG_PROFILE_FILM_LIGHT=0, 78 DYNRNG_PROFILE_FILM_STANDARD, 79 DYNRNG_PROFILE_MUSIC_LIGHT, 80 DYNRNG_PROFILE_MUSIC_STANDARD, 81 DYNRNG_PROFILE_SPEECH, 82 DYNRNG_PROFILE_NONE 83 } DynRngProfile; 84 85 /** 86 * Audio Coding Mode (acmod) options 87 */ 88 enum { 89 A52_ACMOD_DUAL_MONO = 0, 90 A52_ACMOD_MONO, 91 A52_ACMOD_STEREO, 92 A52_ACMOD_3_0, 93 A52_ACMOD_2_1, 94 A52_ACMOD_3_1, 95 A52_ACMOD_2_2, 96 A52_ACMOD_3_2 97 }; 98 99 /** 100 * SIMD instruction sets 101 */ 102 typedef struct { 103 int mmx; 104 int sse; 105 int sse2; 106 int sse3; 107 int ssse3; 108 int amd_3dnow; 109 int amd_3dnowext; 110 int amd_sse_mmx; 111 int altivec; 112 } AftenSimdInstructions; 113 114 /** 115 * Performance related parameters 116 */ 117 typedef struct { 118 /** 119 * Number of threads 120 * How many threads should be used. 121 * Default value is 0, which indicates detecting number of CPUs. 122 * Maximum value is AFTEN_MAX_THREADS. 123 */ 124 int n_threads; 125 126 /** 127 * Available SIMD instruction sets; shouldn't be modified 128 */ 129 AftenSimdInstructions available_simd_instructions; 130 131 /** 132 * Wanted SIMD instruction sets 133 */ 134 AftenSimdInstructions wanted_simd_instructions; 135 } AftenSystemParams; 136 137 /** 138 * Parameters which affect encoded audio output 139 */ 140 typedef struct { 141 /** 142 * Bitrate selection mode. 143 * AFTEN_ENC_MODE_CBR : constant bitrate 144 * AFTEN_ENC_MODE_VBR : variable bitrate 145 * default is CBR 146 */ 147 AftenEncMode encoding_mode; 148 149 /** 150 * Stereo rematrixing option. 151 * Set to 0 to disable stereo rematrixing, 1 to enable it. 152 * default is 1 153 */ 154 int use_rematrixing; 155 156 /** 157 * Block switching option. 158 * Set to 0 to disable block switching, 1 to enable it. 159 * default is 0 160 */ 161 int use_block_switching; 162 163 /** 164 * DC high-pass filter option. 165 * Set to 0 to disable the filter, 1 to enable it. 166 * default is 0 167 */ 168 int use_dc_filter; 169 170 /** 171 * Bandwidth low-pass filter option. 172 * Set to 0 to disable the, 1 to enable it. 173 * This option cannot be enabled with variable bandwidth mode (bwcode=-2) 174 * default is 0 175 */ 176 int use_bw_filter; 177 178 /** 179 * LFE low-pass filter option. 180 * Set to 0 to disable the filter, 1 to enable it. 181 * This limits the LFE bandwidth, and can only be used if the input audio 182 * has an LFE channel. 183 * default is 0 184 */ 185 int use_lfe_filter; 186 187 /** 188 * Constant bitrate. 189 * This option sets the bitrate for CBR encoding mode. 190 * It can also be used to set the maximum bitrate for VBR mode. 191 * It is specified in kbps. Only certain bitrates are valid: 192 * 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 193 * 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 194 * default is 0 195 * For CBR mode, this selects bitrate based on the number of channels. 196 * For VBR mode, this sets the maximum bitrate to 640 kbps. 197 */ 198 int bitrate; 199 200 /** 201 * VBR Quality. 202 * This option sets the target quality for VBR encoding mode. 203 * The range is 0 to 1023 and corresponds to the SNR offset. 204 * default is 240 205 */ 206 int quality; 207 208 /** 209 * Bandwidth code. 210 * This option determines the cutoff frequency for encoded bandwidth. 211 * 0 to 60 corresponds to a cutoff of 28.5% to 98.8% of the full bandwidth. 212 * -1 is used for constant adaptive bandwidth. Aften selects a good value 213 * based on the quality or bitrate parameters. 214 * -2 is used for variable adaptive bandwidth. Aften selects a value for 215 * each frame based on the encoding quality level for that frame. 216 * default is -1 217 */ 218 int bwcode; 219 220 /** 221 * Bit Allocation speed/accuracy 222 * This determines how accurate the bit allocation search method is. 223 * Set to 0 for better quality 224 * Set to 1 for faster encoding 225 * default is 0 226 */ 227 int bitalloc_fast; 228 229 /** 230 * Exponent Strategy speed/quality 231 * This determines whether to use a fixed or adaptive exponent strategy. 232 * Set to 0 for adaptive strategy (better quality, slower) 233 * Set to 1 for fixed strategy (lower quality, faster) 234 */ 235 int expstr_fast; 236 237 /** 238 * Dynamic Range Compression profile 239 * This determines which DRC profile to use. 240 * Film Light: DYNRNG_PROFILE_FILM_LIGHT 241 * Film Standard: DYNRNG_PROFILE_FILM_STANDARD 242 * Music Light: DYNRNG_PROFILE_MUSIC_LIGHT 243 * Music Standard: DYNRNG_PROFILE_MUSIC_STANDARD 244 * Speech: DYNRNG_PROFILE_SPEECH, 245 * None: DYNRNG_PROFILE_NONE 246 * default is None 247 */ 248 DynRngProfile dynrng_profile; 249 250 /** 251 * Minimum bandwidth code. 252 * For use with variable bandwidth mode, this option determines the 253 * minimum value for the bandwidth code. 254 * default is 0. 255 */ 256 int min_bwcode; 257 258 /** 259 * Maximum bandwidth code. 260 * For use with variable bandwidth mode, this option determines the 261 * maximum value for the bandwidth code. 262 * default is 60. 263 */ 264 int max_bwcode; 265 266 } AftenEncParams; 267 268 /** 269 * Metadata parameters 270 * See the A/52 specification for details regarding the metadata. 271 */ 272 typedef struct { 273 /** Center mix level */ 274 int cmixlev; 275 276 /** Surround mix level */ 277 int surmixlev; 278 279 /** Dolby(R) Surround mode */ 280 int dsurmod; 281 282 /** Dialog normalization */ 283 int dialnorm; 284 285 /** Extended bit stream info 1 exists */ 286 int xbsi1e; 287 288 /** Preferred downmix mode */ 289 int dmixmod; 290 291 /** LtRt center mix level */ 292 int ltrtcmixlev; 293 294 /** LtRt surround mix level */ 295 int ltrtsmixlev; 296 297 /** LoRo center mix level */ 298 int lorocmixlev; 299 300 /** LoRo surround mix level */ 301 int lorosmixlev; 302 303 /** Extended bit stream info 2 exists */ 304 int xbsi2e; 305 306 /** Dolby(R) Surround EX mode */ 307 int dsurexmod; 308 309 /** Dolby(R) Headphone mode */ 310 int dheadphonmod; 311 312 /** A/D converter type */ 313 int adconvtyp; 314 315 } AftenMetadata; 316 317 /** 318 * Values in this structure are updated by Aften during encoding. 319 * They give information about the previously encoded frame. 320 */ 321 typedef struct { 322 int quality; 323 int bit_rate; 324 int bwcode; 325 } AftenStatus; 326 327 /** 328 * libaften public encoding context 329 */ 330 typedef struct { 331 AftenEncParams params; 332 AftenMetadata meta; 333 AftenStatus status; 334 AftenSystemParams system; 335 336 /** 337 * Verbosity level. 338 * 0 is quiet mode. 1 and 2 are more verbose. 339 * default is 1 340 */ 341 int verbose; 342 343 /** 344 * Total number of channels in the input stream. 345 */ 346 int channels; 347 348 /** 349 * Audio coding mode (channel configuration). 350 * There are utility functions to set this if you don't know the proper 351 * value. 352 */ 353 int acmod; 354 355 /** 356 * Indicates that there is an LFE channel present. 357 * There are utility functions to set this if you don't know the proper 358 * value. 359 */ 360 int lfe; 361 362 /** 363 * Audio sample rate in Hz 364 */ 365 int samplerate; 366 367 /** 368 * Audio sample format 369 * default: A52_SAMPLE_FMT_S16 370 */ 371 A52SampleFormat sample_format; 372 373 /** 374 * Used internally by the encoder. The user should leave this alone. 375 * It is allocated in aften_encode_init and free'd in aften_encode_close. 376 */ 377 void *private_context; 378 } AftenContext; 379 380 #if defined(__cplusplus) 381 } 382 #endif 383 384 #endif /* AFTEN_TYPES_H */ 385