1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Frderung der angewandten Forschung e.V. 6 All rights reserved. 7 8 1. INTRODUCTION 9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements 10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. 11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices. 12 13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual 14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by 15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part 16 of the MPEG specifications. 17 18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) 19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners 20 individually for the purpose of encoding or decoding bit streams in products that are compliant with 21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license 22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec 23 software may already be covered under those patent licenses when it is used for those licensed purposes only. 24 25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, 26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional 27 applications information and documentation. 28 29 2. COPYRIGHT LICENSE 30 31 Redistribution and use in source and binary forms, with or without modification, are permitted without 32 payment of copyright license fees provided that you satisfy the following conditions: 33 34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or 35 your modifications thereto in source code form. 36 37 You must retain the complete text of this software license in the documentation and/or other materials 38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. 39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your 40 modifications thereto to recipients of copies in binary form. 41 42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without 43 prior written permission. 44 45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec 46 software or your modifications thereto. 47 48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software 49 and the date of any change. For modified versions of the FDK AAC Codec, the term 50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term 51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." 52 53 3. NO PATENT LICENSE 54 55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, 56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with 57 respect to this software. 58 59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized 60 by appropriate patent licenses. 61 62 4. DISCLAIMER 63 64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors 65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties 66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, 68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits, 69 or business interruption, however caused and on any theory of liability, whether in contract, strict 70 liability, or tort (including negligence), arising in any way out of the use of this software, even if 71 advised of the possibility of such damage. 72 73 5. CONTACT INFORMATION 74 75 Fraunhofer Institute for Integrated Circuits IIS 76 Attention: Audio and Multimedia Departments - FDK AAC LL 77 Am Wolfsmantel 33 78 91058 Erlangen, Germany 79 80 www.iis.fraunhofer.de/amm 81 amm-info (at) iis.fraunhofer.de 82 ----------------------------------------------------------------------------------------------------------- */ 83 84 /*************************** Fraunhofer IIS *********************** 85 86 Author(s): 87 Description: SBR encoder top level processing prototype 88 89 ******************************************************************************/ 90 91 #ifndef __SBR_ENCODER_H 92 #define __SBR_ENCODER_H 93 94 #include "common_fix.h" 95 #include "FDK_audio.h" 96 97 #include "FDK_bitstream.h" 98 99 /* core coder helpers */ 100 #define MAX_TRANS_FAC 8 101 #define MAX_CODEC_FRAME_RATIO 2 102 #define MAX_PAYLOAD_SIZE 256 103 104 typedef struct 105 { 106 INT bitRate; 107 INT nChannels; 108 INT sampleFreq; 109 INT transFac; 110 INT standardBitrate; 111 } CODEC_PARAM; 112 113 typedef enum 114 { 115 SBR_MONO, 116 SBR_LEFT_RIGHT, 117 SBR_COUPLING, 118 SBR_SWITCH_LRC 119 } SBR_STEREO_MODE; 120 121 /* bitstream syntax flags */ 122 enum 123 { 124 SBR_SYNTAX_LOW_DELAY = 0x0001, 125 SBR_SYNTAX_SCALABLE = 0x0002, 126 SBR_SYNTAX_CRC = 0x0004, 127 SBR_SYNTAX_DRM_CRC = 0x0008 128 }; 129 130 typedef struct 131 { 132 UINT bitrateFrom; /*!< inclusive */ 133 UINT bitrateTo; /*!< exclusive */ 134 135 USHORT sampleRate; /*!< */ 136 UCHAR numChannels; /*!< */ 137 138 UCHAR startFreq; /*!< bs_start_freq */ 139 UCHAR startFreqSpeech; /*!< bs_start_freq for speech config flag */ 140 UCHAR stopFreq; /*!< bs_stop_freq */ 141 UCHAR stopFreqSpeech; /*!< bs_stop_freq for speech config flag */ 142 143 UCHAR numNoiseBands; /*!< */ 144 UCHAR noiseFloorOffset; /*!< */ 145 SCHAR noiseMaxLevel; /*!< */ 146 SBR_STEREO_MODE stereoMode; /*!< */ 147 UCHAR freqScale; /*!< */ 148 } sbrTuningTable_t; 149 150 typedef struct sbrConfiguration 151 { 152 /* 153 core coder dependent configurations 154 */ 155 CODEC_PARAM codecSettings; /*!< Core coder settings. To be set from core coder. */ 156 INT SendHeaderDataTime; /*!< SBR header send update frequency in ms. */ 157 INT useWaveCoding; /*!< Flag: usage of wavecoding tool. */ 158 INT crcSbr; /*!< Flag: usage of SBR-CRC. */ 159 INT dynBwSupported; /*!< Flag: support for dynamic bandwidth in this combination. */ 160 INT parametricCoding; /*!< Flag: usage of parametric coding tool. */ 161 int freq_res_fixfix[3]; /*!< Frequency resolution of envelopes in frame class FIXFIX 162 0=1 Env; 1=2 Env; 2=4 Env; */ 163 /* 164 core coder dependent tuning parameters 165 */ 166 INT tran_thr; /*!< SBR transient detector threshold (* 100). */ 167 INT noiseFloorOffset; /*!< Noise floor offset. */ 168 UINT useSpeechConfig; /*!< Flag: adapt tuning parameters according to speech. */ 169 170 171 172 /* 173 core coder independent configurations 174 */ 175 INT sbrFrameSize; /*!< SBR frame size in samples. Will be calculated from core coder settings. */ 176 INT sbr_data_extra; /*!< Flag usage of data extra. */ 177 INT amp_res; /*!< Amplitude resolution. */ 178 INT ana_max_level; /*!< Noise insertion maximum level. */ 179 INT tran_fc; /*!< Transient detector start frequency. */ 180 INT tran_det_mode; /*!< Transient detector mode. */ 181 INT spread; /*!< Flag: usage of SBR spread. */ 182 INT stat; /*!< Flag: usage of static framing. */ 183 INT e; /*!< Number of envelopes when static framing is chosen. */ 184 SBR_STEREO_MODE stereoMode; /*!< SBR stereo mode. */ 185 INT deltaTAcrossFrames; /*!< Flag: allow time-delta coding. */ 186 FIXP_DBL dF_edge_1stEnv; /*!< Extra fraction delta-F coding is allowed to be more expensive. */ 187 FIXP_DBL dF_edge_incr; /*!< Increment dF_edge_1stEnv this much if dT-coding was used this frame. */ 188 INT sbr_invf_mode; /*!< Inverse filtering mode. */ 189 INT sbr_xpos_mode; /*!< Transposer mode. */ 190 INT sbr_xpos_ctrl; /*!< Transposer control. */ 191 INT sbr_xpos_level; /*!< Transposer 3rd order level. */ 192 INT startFreq; /*!< The start frequency table index. */ 193 INT stopFreq; /*!< The stop frequency table index. */ 194 INT useSaPan; /*!< Flag: usage of SAPAN stereo. */ 195 INT dynBwEnabled; /*!< Flag: usage of dynamic bandwidth. */ 196 INT bParametricStereo; /*!< Flag: usage of parametric stereo coding tool. */ 197 INT bDownSampledSbr; /*!< Signal downsampled SBR is used. */ 198 199 /* 200 header_extra1 configuration 201 */ 202 UCHAR freqScale; /*!< Frequency grouping. */ 203 INT alterScale; /*!< Scale resolution. */ 204 INT sbr_noise_bands; /*!< Number of noise bands. */ 205 206 207 /* 208 header_extra2 configuration 209 */ 210 INT sbr_limiter_bands; /*!< Number of limiter bands. */ 211 INT sbr_limiter_gains; /*!< Gain of limiter. */ 212 INT sbr_interpol_freq; /*!< Flag: use interpolation in freq. direction. */ 213 INT sbr_smoothing_length; /*!< Flag: choose length 4 or 0 (=on, off). */ 214 UCHAR init_amp_res_FF; 215 } sbrConfiguration, *sbrConfigurationPtr ; 216 217 typedef struct 218 { 219 UINT sbrSyntaxFlags; /**< SBR syntax flags derived from AOT. */ 220 INT nChannels; /**< Number of channels. */ 221 222 INT nSfb[2]; /**< Number of SBR scalefactor bands for LO_RES and HI_RES (?) */ 223 INT num_Master; /**< Number of elements in v_k_master. */ 224 INT sampleFreq; /**< SBR sampling frequency. */ 225 INT frameSize; 226 INT xOverFreq; /**< The SBR start frequency. */ 227 INT dynXOverFreq; /**< Used crossover frequency when dynamic bandwidth is enabled. */ 228 INT noQmfBands; /**< Number of QMF frequency bands. */ 229 INT noQmfSlots; /**< Number of QMF slots. */ 230 231 UCHAR *freqBandTable[2]; /**< Frequency table for low and hires, only MAX_FREQ_COEFFS/2 +1 coeefs actually needed for lowres. */ 232 UCHAR *v_k_master; /**< Master BandTable where freqBandTable is derived from. */ 233 234 235 SBR_STEREO_MODE stereoMode; 236 INT noEnvChannels; /**< Number of envelope channels. */ 237 238 INT useWaveCoding; /**< Flag indicates whether to use wave coding at all. */ 239 INT useParametricCoding; /**< Flag indicates whether to use para coding at all. */ 240 INT xposCtrlSwitch; /**< Flag indicates whether to switch xpos ctrl on the fly. */ 241 INT switchTransposers; /**< Flag indicates whether to switch xpos on the fly . */ 242 UCHAR initAmpResFF; 243 } SBR_CONFIG_DATA; 244 245 typedef SBR_CONFIG_DATA *HANDLE_SBR_CONFIG_DATA; 246 247 typedef struct { 248 MP4_ELEMENT_ID elType; 249 INT bitRate; 250 int instanceTag; 251 UCHAR fParametricStereo; 252 UCHAR nChannelsInEl; 253 UCHAR ChannelIndex[2]; 254 } SBR_ELEMENT_INFO; 255 256 #ifdef __cplusplus 257 extern "C" { 258 #endif 259 260 typedef struct SBR_ENCODER *HANDLE_SBR_ENCODER; 261 262 /** 263 * \brief Get the max required input buffer size including delay balancing space 264 * for N audio channels. 265 * \param noChannels Number of audio channels. 266 * \return Max required input buffer size in bytes. 267 */ 268 INT sbrEncoder_GetInBufferSize(int noChannels); 269 270 INT sbrEncoder_Open( 271 HANDLE_SBR_ENCODER *phSbrEncoder, 272 INT nElements, 273 INT nChannels, 274 INT supportPS 275 ); 276 277 /** 278 * \brief get closest working bit rate to specified desired bit rate for a single SBR element 279 * \param bitRate the desired target bit rate 280 * \param numChannels the amount of audio channels 281 * \param coreSampleRate the sample rate of the core coder 282 * \param the current Audio Object Type 283 * \return closest working bit rate to bitRate value 284 */ 285 UINT sbrEncoder_LimitBitRate(UINT bitRate, UINT numChannels, UINT coreSampleRate, AUDIO_OBJECT_TYPE aot); 286 287 /** 288 * \brief Initialize SBR Encoder instance. 289 * \param phSbrEncoder Pointer to a SBR Encoder instance. 290 * \param elInfo Structure that describes the element/channel arrangement. 291 * \param noElements Amount of elements described in elInfo. 292 * \param inputBuffer Pointer to the encoder audio buffer 293 * \param bandwidth Returns the core audio encoder bandwidth (output) 294 * \param bufferOffset Returns the offset for the audio input data in order to do delay balancing. 295 * \param numChannels Input: Encoder input channels. output: core encoder channels. 296 * \param sampleRate Input: Encoder samplerate. output core encoder samplerate. 297 * \param frameLength Input: Encoder frameLength. output core encoder frameLength. 298 * \param aot Input: Desired AOT. output AOT to be used after parameter checking. 299 * \param delay Input: core encoder delay. Output: total delay because of SBR. 300 * \param transformFactor The core encoder transform factor (blockswitching). 301 * \return 0 on success, and non-zero if failed. 302 */ 303 INT sbrEncoder_Init( HANDLE_SBR_ENCODER hSbrEncoder, 304 SBR_ELEMENT_INFO elInfo[(6)], 305 int noElements, 306 INT_PCM *inputBuffer, 307 INT *bandwidth, 308 INT *bufferOffset, 309 INT *numChannels, 310 INT *sampleRate, 311 INT *frameLength, 312 AUDIO_OBJECT_TYPE *aot, 313 int *delay, 314 int transformFactor, 315 ULONG statesInitFlag 316 ); 317 318 /** 319 * \brief Do delay line buffers housekeeping. To be called after each encoded audio frame. 320 * \param hEnvEnc SBR Encoder handle. 321 * \param timeBuffer Pointer to the encoder audio buffer. 322 * \return 0 on success, and non-zero if failed. 323 */ 324 INT sbrEncoder_UpdateBuffers(HANDLE_SBR_ENCODER hEnvEnc, 325 INT_PCM *timeBuffer 326 ); 327 328 /** 329 * \brief Close SBR encoder instance. 330 * \param phEbrEncoder Handle of SBR encoder instance to be closed. 331 * \return void 332 */ 333 void sbrEncoder_Close(HANDLE_SBR_ENCODER *phEbrEncoder); 334 335 /** 336 * \brief Encode SBR data of one complete audio frame. 337 * \param hEnvEncoder Handle of SBR encoder instance. 338 * \param samples Time samples, always interleaved. 339 * \param timeInStride Channel stride factor of samples buffer. 340 * \param sbrDataBits Size of SBR payload in bits. 341 * \param sbrData SBR payload. 342 * \return 0 on success, and non-zero if failed. 343 */ 344 INT sbrEncoder_EncodeFrame(HANDLE_SBR_ENCODER hEnvEncoder, 345 INT_PCM *samples, 346 UINT timeInStride, 347 UINT sbrDataBits[(6)], 348 UCHAR sbrData[(6)][MAX_PAYLOAD_SIZE] 349 ); 350 351 /** 352 * \brief Write SBR headers of one SBR element. 353 * \param sbrEncoder Handle of the SBR encoder instance. 354 * \param hBs Handle of bit stream handle to write SBR header to. 355 * \param element_index Index of the SBR element which header should be written. 356 * \param fSendHeaders Flag indicating that the SBR encoder should send more headers in the SBR payload or not. 357 * \return void 358 */ 359 void sbrEncoder_GetHeader(SBR_ENCODER *sbrEncoder, 360 HANDLE_FDK_BITSTREAM hBs, 361 INT element_index, 362 int fSendHeaders); 363 364 /** 365 * \brief SBR encoder bitrate estimation. 366 * \param hSbrEncoder SBR encoder handle. 367 * \return Estimated bitrate. 368 */ 369 INT sbrEncoder_GetEstimateBitrate(HANDLE_SBR_ENCODER hSbrEncoder); 370 371 372 /** 373 * \brief Delay between input data and downsampled output data. 374 * \param hSbrEncoder SBR encoder handle. 375 * \return Delay. 376 */ 377 INT sbrEncoder_GetInputDataDelay(HANDLE_SBR_ENCODER hSbrEncoder); 378 379 /** 380 * \brief Get decoder library version info. 381 * \param info Pointer to an allocated LIB_INFO struct, where library info is written to. 382 * \return 0 on sucess. 383 */ 384 INT sbrEncoder_GetLibInfo(LIB_INFO *info); 385 386 void sbrPrintRAM(void); 387 388 void sbrPrintROM(void); 389 390 #ifdef __cplusplus 391 } 392 #endif 393 394 #endif /* ifndef __SBR_MAIN_H */ 395