1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 � Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur F�rderung 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@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 enum codecType 105 { 106 CODEC_AAC=0, 107 CODEC_AACLD=1, 108 CODEC_UNSPECIFIED=99 109 } CODEC_TYPE; 110 111 112 typedef struct 113 { 114 INT bitRate; 115 INT nChannels; 116 INT sampleFreq; 117 INT transFac; 118 INT standardBitrate; 119 } CODEC_PARAM; 120 121 typedef enum 122 { 123 SBR_MONO, 124 SBR_LEFT_RIGHT, 125 SBR_COUPLING, 126 SBR_SWITCH_LRC 127 } SBR_STEREO_MODE; 128 129 /* bitstream syntax flags */ 130 enum 131 { 132 SBR_SYNTAX_LOW_DELAY = 0x0001, 133 SBR_SYNTAX_SCALABLE = 0x0002, 134 SBR_SYNTAX_CRC = 0x0004, 135 SBR_SYNTAX_DRM_CRC = 0x0008 136 }; 137 138 typedef enum 139 { 140 FREQ_RES_LOW = 0, 141 FREQ_RES_HIGH 142 } FREQ_RES; 143 144 typedef struct 145 { 146 CODEC_TYPE coreCoder; /*!< LC or ELD */ 147 UINT bitrateFrom; /*!< inclusive */ 148 UINT bitrateTo; /*!< exclusive */ 149 150 UINT sampleRate; /*!< */ 151 UCHAR numChannels; /*!< */ 152 153 UCHAR startFreq; /*!< bs_start_freq */ 154 UCHAR startFreqSpeech; /*!< bs_start_freq for speech config flag */ 155 UCHAR stopFreq; /*!< bs_stop_freq */ 156 UCHAR stopFreqSpeech; /*!< bs_stop_freq for speech config flag */ 157 158 UCHAR numNoiseBands; /*!< */ 159 UCHAR noiseFloorOffset; /*!< */ 160 SCHAR noiseMaxLevel; /*!< */ 161 SBR_STEREO_MODE stereoMode; /*!< */ 162 UCHAR freqScale; /*!< */ 163 } sbrTuningTable_t; 164 165 typedef struct sbrConfiguration 166 { 167 /* 168 core coder dependent configurations 169 */ 170 CODEC_PARAM codecSettings; /*!< Core coder settings. To be set from core coder. */ 171 INT SendHeaderDataTime; /*!< SBR header send update frequency in ms. */ 172 INT useWaveCoding; /*!< Flag: usage of wavecoding tool. */ 173 INT crcSbr; /*!< Flag: usage of SBR-CRC. */ 174 INT dynBwSupported; /*!< Flag: support for dynamic bandwidth in this combination. */ 175 INT parametricCoding; /*!< Flag: usage of parametric coding tool. */ 176 INT downSampleFactor; /*!< Sampling rate relation between the SBR and the core encoder. */ 177 FREQ_RES freq_res_fixfix[2];/*!< Frequency resolution of envelopes in frame class FIXFIX, for non-split case and split case */ 178 UCHAR fResTransIsLow; /*!< Frequency resolution of envelopes in transient frames: low (0) or variable (1) */ 179 180 /* 181 core coder dependent tuning parameters 182 */ 183 INT tran_thr; /*!< SBR transient detector threshold (* 100). */ 184 INT noiseFloorOffset; /*!< Noise floor offset. */ 185 UINT useSpeechConfig; /*!< Flag: adapt tuning parameters according to speech. */ 186 187 188 189 /* 190 core coder independent configurations 191 */ 192 INT sbrFrameSize; /*!< SBR frame size in samples. Will be calculated from core coder settings. */ 193 INT sbr_data_extra; /*!< Flag usage of data extra. */ 194 INT amp_res; /*!< Amplitude resolution. */ 195 INT ana_max_level; /*!< Noise insertion maximum level. */ 196 INT tran_fc; /*!< Transient detector start frequency. */ 197 INT tran_det_mode; /*!< Transient detector mode. */ 198 INT spread; /*!< Flag: usage of SBR spread. */ 199 INT stat; /*!< Flag: usage of static framing. */ 200 INT e; /*!< Number of envelopes when static framing is chosen. */ 201 SBR_STEREO_MODE stereoMode; /*!< SBR stereo mode. */ 202 INT deltaTAcrossFrames; /*!< Flag: allow time-delta coding. */ 203 FIXP_DBL dF_edge_1stEnv; /*!< Extra fraction delta-F coding is allowed to be more expensive. */ 204 FIXP_DBL dF_edge_incr; /*!< Increment dF_edge_1stEnv this much if dT-coding was used this frame. */ 205 INT sbr_invf_mode; /*!< Inverse filtering mode. */ 206 INT sbr_xpos_mode; /*!< Transposer mode. */ 207 INT sbr_xpos_ctrl; /*!< Transposer control. */ 208 INT sbr_xpos_level; /*!< Transposer 3rd order level. */ 209 INT startFreq; /*!< The start frequency table index. */ 210 INT stopFreq; /*!< The stop frequency table index. */ 211 INT useSaPan; /*!< Flag: usage of SAPAN stereo. */ 212 INT dynBwEnabled; /*!< Flag: usage of dynamic bandwidth. */ 213 INT bParametricStereo; /*!< Flag: usage of parametric stereo coding tool. */ 214 215 /* 216 header_extra1 configuration 217 */ 218 UCHAR freqScale; /*!< Frequency grouping. */ 219 INT alterScale; /*!< Scale resolution. */ 220 INT sbr_noise_bands; /*!< Number of noise bands. */ 221 222 223 /* 224 header_extra2 configuration 225 */ 226 INT sbr_limiter_bands; /*!< Number of limiter bands. */ 227 INT sbr_limiter_gains; /*!< Gain of limiter. */ 228 INT sbr_interpol_freq; /*!< Flag: use interpolation in freq. direction. */ 229 INT sbr_smoothing_length; /*!< Flag: choose length 4 or 0 (=on, off). */ 230 UCHAR init_amp_res_FF; 231 FIXP_DBL threshold_AmpRes_FF_m; 232 SCHAR threshold_AmpRes_FF_e; 233 } sbrConfiguration, *sbrConfigurationPtr ; 234 235 typedef struct SBR_CONFIG_DATA 236 { 237 UINT sbrSyntaxFlags; /**< SBR syntax flags derived from AOT. */ 238 INT nChannels; /**< Number of channels. */ 239 240 INT nSfb[2]; /**< Number of SBR scalefactor bands for LO_RES and HI_RES (?) */ 241 INT num_Master; /**< Number of elements in v_k_master. */ 242 INT sampleFreq; /**< SBR sampling frequency. */ 243 INT frameSize; 244 INT xOverFreq; /**< The SBR start frequency. */ 245 INT dynXOverFreq; /**< Used crossover frequency when dynamic bandwidth is enabled. */ 246 INT noQmfBands; /**< Number of QMF frequency bands. */ 247 INT noQmfSlots; /**< Number of QMF slots. */ 248 249 UCHAR *freqBandTable[2]; /**< Frequency table for low and hires, only MAX_FREQ_COEFFS/2 +1 coeffs actually needed for lowres. */ 250 UCHAR *v_k_master; /**< Master BandTable where freqBandTable is derived from. */ 251 252 253 SBR_STEREO_MODE stereoMode; 254 INT noEnvChannels; /**< Number of envelope channels. */ 255 256 INT useWaveCoding; /**< Flag indicates whether to use wave coding at all. */ 257 INT useParametricCoding; /**< Flag indicates whether to use para coding at all. */ 258 INT xposCtrlSwitch; /**< Flag indicates whether to switch xpos ctrl on the fly. */ 259 INT switchTransposers; /**< Flag indicates whether to switch xpos on the fly . */ 260 UCHAR initAmpResFF; 261 FIXP_DBL thresholdAmpResFF_m; 262 SCHAR thresholdAmpResFF_e; 263 } SBR_CONFIG_DATA, *HANDLE_SBR_CONFIG_DATA; 264 265 typedef struct { 266 MP4_ELEMENT_ID elType; 267 INT bitRate; 268 int instanceTag; 269 UCHAR fParametricStereo; 270 UCHAR nChannelsInEl; 271 UCHAR ChannelIndex[2]; 272 } SBR_ELEMENT_INFO; 273 274 #ifdef __cplusplus 275 extern "C" { 276 #endif 277 278 typedef struct SBR_ENCODER *HANDLE_SBR_ENCODER; 279 280 /** 281 * \brief Get the max required input buffer size including delay balancing space 282 * for N audio channels. 283 * \param noChannels Number of audio channels. 284 * \return Max required input buffer size in bytes. 285 */ 286 INT sbrEncoder_GetInBufferSize(int noChannels); 287 288 INT sbrEncoder_Open( 289 HANDLE_SBR_ENCODER *phSbrEncoder, 290 INT nElements, 291 INT nChannels, 292 INT supportPS 293 ); 294 295 /** 296 * \brief Get closest working bitrate to specified desired 297 * bitrate for a single SBR element. 298 * \param bitRate The desired target bit rate 299 * \param numChannels The amount of audio channels 300 * \param coreSampleRate The sample rate of the core coder 301 * \param aot The current Audio Object Type 302 * \return Closest working bit rate to bitRate value 303 */ 304 UINT sbrEncoder_LimitBitRate(UINT bitRate, UINT numChannels, UINT coreSampleRate, AUDIO_OBJECT_TYPE aot); 305 306 307 /** 308 * \brief Check whether downsampled SBR single rate is possible 309 * with given audio object type. 310 * \param aot The Audio object type. 311 * \return 0 when downsampled SBR is not possible, 312 * 1 when downsampled SBR is possible. 313 */ 314 UINT sbrEncoder_IsSingleRatePossible(AUDIO_OBJECT_TYPE aot); 315 316 /** 317 * \brief Initialize SBR Encoder instance. 318 * \param phSbrEncoder Pointer to a SBR Encoder instance. 319 * \param elInfo Structure that describes the element/channel arrangement. 320 * \param noElements Amount of elements described in elInfo. 321 * \param inputBuffer Pointer to the encoder audio buffer 322 * \param bandwidth Returns the core audio encoder bandwidth (output) 323 * \param bufferOffset Returns the offset for the audio input data in order to do delay balancing. 324 * \param numChannels Input: Encoder input channels. output: core encoder channels. 325 * \param sampleRate Input: Encoder samplerate. output core encoder samplerate. 326 * \param downSampleFactor Input: Relation between SBR and core coder sampling rate; 327 * \param frameLength Input: Encoder frameLength. output core encoder frameLength. 328 * \param aot Input: Desired AOT. output AOT to be used after parameter checking. 329 * \param delay Input: core encoder delay. Output: total delay because of SBR. 330 * \param transformFactor The core encoder transform factor (blockswitching). 331 * \param headerPeriod Repetition rate of the SBR header: 332 * - (-1) means intern configuration. 333 * - (1-10) corresponds to header repetition rate in frames. 334 * \return 0 on success, and non-zero if failed. 335 */ 336 INT sbrEncoder_Init( 337 HANDLE_SBR_ENCODER hSbrEncoder, 338 SBR_ELEMENT_INFO elInfo[(8)], 339 int noElements, 340 INT_PCM *inputBuffer, 341 INT *coreBandwidth, 342 INT *inputBufferOffset, 343 INT *numChannels, 344 INT *sampleRate, 345 UINT *downSampleFactor, 346 INT *frameLength, 347 AUDIO_OBJECT_TYPE aot, 348 int *delay, 349 int transformFactor, 350 const int headerPeriod, 351 ULONG statesInitFlag 352 ); 353 354 /** 355 * \brief Do delay line buffers housekeeping. To be called after each encoded audio frame. 356 * \param hEnvEnc SBR Encoder handle. 357 * \param timeBuffer Pointer to the encoder audio buffer. 358 * \return 0 on success, and non-zero if failed. 359 */ 360 INT sbrEncoder_UpdateBuffers(HANDLE_SBR_ENCODER hEnvEnc, 361 INT_PCM *timeBuffer 362 ); 363 364 /** 365 * \brief Close SBR encoder instance. 366 * \param phEbrEncoder Handle of SBR encoder instance to be closed. 367 * \return void 368 */ 369 void sbrEncoder_Close(HANDLE_SBR_ENCODER *phEbrEncoder); 370 371 /** 372 * \brief Encode SBR data of one complete audio frame. 373 * \param hEnvEncoder Handle of SBR encoder instance. 374 * \param samples Time samples, always interleaved. 375 * \param timeInStride Channel stride factor of samples buffer. 376 * \param sbrDataBits Size of SBR payload in bits. 377 * \param sbrData SBR payload. 378 * \return 0 on success, and non-zero if failed. 379 */ 380 INT sbrEncoder_EncodeFrame(HANDLE_SBR_ENCODER hEnvEncoder, 381 INT_PCM *samples, 382 UINT timeInStride, 383 UINT sbrDataBits[(8)], 384 UCHAR sbrData[(8)][MAX_PAYLOAD_SIZE] 385 ); 386 387 /** 388 * \brief Write SBR headers of one SBR element. 389 * \param sbrEncoder Handle of the SBR encoder instance. 390 * \param hBs Handle of bit stream handle to write SBR header to. 391 * \param element_index Index of the SBR element which header should be written. 392 * \param fSendHeaders Flag indicating that the SBR encoder should send more headers in the SBR payload or not. 393 * \return void 394 */ 395 void sbrEncoder_GetHeader(HANDLE_SBR_ENCODER sbrEncoder, 396 HANDLE_FDK_BITSTREAM hBs, 397 INT element_index, 398 int fSendHeaders); 399 400 /** 401 * \brief SBR encoder bitrate estimation. 402 * \param hSbrEncoder SBR encoder handle. 403 * \return Estimated bitrate. 404 */ 405 INT sbrEncoder_GetEstimateBitrate(HANDLE_SBR_ENCODER hSbrEncoder); 406 407 408 /** 409 * \brief Delay between input data and downsampled output data. 410 * \param hSbrEncoder SBR encoder handle. 411 * \return Delay. 412 */ 413 INT sbrEncoder_GetInputDataDelay(HANDLE_SBR_ENCODER hSbrEncoder); 414 415 /** 416 * \brief Get decoder library version info. 417 * \param info Pointer to an allocated LIB_INFO struct, where library info is written to. 418 * \return 0 on sucess. 419 */ 420 INT sbrEncoder_GetLibInfo(LIB_INFO *info); 421 422 void sbrPrintRAM(void); 423 424 void sbrPrintROM(void); 425 426 #ifdef __cplusplus 427 } 428 #endif 429 430 #endif /* ifndef __SBR_MAIN_H */ 431