2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
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.
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.
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.
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.
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:
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.
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.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
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.
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."
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.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
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.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
84 /*************************** Fraunhofer IIS ***********************
87 Description: SBR encoder top level processing prototype
89 ******************************************************************************/
91 #ifndef __SBR_ENCODER_H
92 #define __SBR_ENCODER_H
94 #include "common_fix.h"
95 #include "FDK_audio.h"
97 #include "FDK_bitstream.h"
99 /* core coder helpers */
100 #define MAX_TRANS_FAC 8
101 #define MAX_CODEC_FRAME_RATIO 2
102 #define MAX_PAYLOAD_SIZE 256
104 typedef enum codecType
129 /* bitstream syntax flags */
132 SBR_SYNTAX_LOW_DELAY
= 0x0001,
133 SBR_SYNTAX_SCALABLE
= 0x0002,
134 SBR_SYNTAX_CRC
= 0x0004,
135 SBR_SYNTAX_DRM_CRC
= 0x0008
140 CODEC_TYPE coreCoder
; /*!< LC or ELD */
141 UINT bitrateFrom
; /*!< inclusive */
142 UINT bitrateTo
; /*!< exclusive */
144 UINT sampleRate
; /*!< */
145 UCHAR numChannels
; /*!< */
147 UCHAR startFreq
; /*!< bs_start_freq */
148 UCHAR startFreqSpeech
; /*!< bs_start_freq for speech config flag */
149 UCHAR stopFreq
; /*!< bs_stop_freq */
150 UCHAR stopFreqSpeech
; /*!< bs_stop_freq for speech config flag */
152 UCHAR numNoiseBands
; /*!< */
153 UCHAR noiseFloorOffset
; /*!< */
154 SCHAR noiseMaxLevel
; /*!< */
155 SBR_STEREO_MODE stereoMode
; /*!< */
156 UCHAR freqScale
; /*!< */
159 typedef struct sbrConfiguration
162 core coder dependent configurations
164 CODEC_PARAM codecSettings
; /*!< Core coder settings. To be set from core coder. */
165 INT SendHeaderDataTime
; /*!< SBR header send update frequency in ms. */
166 INT useWaveCoding
; /*!< Flag: usage of wavecoding tool. */
167 INT crcSbr
; /*!< Flag: usage of SBR-CRC. */
168 INT dynBwSupported
; /*!< Flag: support for dynamic bandwidth in this combination. */
169 INT parametricCoding
; /*!< Flag: usage of parametric coding tool. */
170 INT downSampleFactor
; /*!< Sampling rate relation between the SBR and the core encoder. */
171 int freq_res_fixfix
[3]; /*!< Frequency resolution of envelopes in frame class FIXFIX
172 0=1 Env; 1=2 Env; 2=4 Env; */
174 core coder dependent tuning parameters
176 INT tran_thr
; /*!< SBR transient detector threshold (* 100). */
177 INT noiseFloorOffset
; /*!< Noise floor offset. */
178 UINT useSpeechConfig
; /*!< Flag: adapt tuning parameters according to speech. */
183 core coder independent configurations
185 INT sbrFrameSize
; /*!< SBR frame size in samples. Will be calculated from core coder settings. */
186 INT sbr_data_extra
; /*!< Flag usage of data extra. */
187 INT amp_res
; /*!< Amplitude resolution. */
188 INT ana_max_level
; /*!< Noise insertion maximum level. */
189 INT tran_fc
; /*!< Transient detector start frequency. */
190 INT tran_det_mode
; /*!< Transient detector mode. */
191 INT spread
; /*!< Flag: usage of SBR spread. */
192 INT stat
; /*!< Flag: usage of static framing. */
193 INT e
; /*!< Number of envelopes when static framing is chosen. */
194 SBR_STEREO_MODE stereoMode
; /*!< SBR stereo mode. */
195 INT deltaTAcrossFrames
; /*!< Flag: allow time-delta coding. */
196 FIXP_DBL dF_edge_1stEnv
; /*!< Extra fraction delta-F coding is allowed to be more expensive. */
197 FIXP_DBL dF_edge_incr
; /*!< Increment dF_edge_1stEnv this much if dT-coding was used this frame. */
198 INT sbr_invf_mode
; /*!< Inverse filtering mode. */
199 INT sbr_xpos_mode
; /*!< Transposer mode. */
200 INT sbr_xpos_ctrl
; /*!< Transposer control. */
201 INT sbr_xpos_level
; /*!< Transposer 3rd order level. */
202 INT startFreq
; /*!< The start frequency table index. */
203 INT stopFreq
; /*!< The stop frequency table index. */
204 INT useSaPan
; /*!< Flag: usage of SAPAN stereo. */
205 INT dynBwEnabled
; /*!< Flag: usage of dynamic bandwidth. */
206 INT bParametricStereo
; /*!< Flag: usage of parametric stereo coding tool. */
209 header_extra1 configuration
211 UCHAR freqScale
; /*!< Frequency grouping. */
212 INT alterScale
; /*!< Scale resolution. */
213 INT sbr_noise_bands
; /*!< Number of noise bands. */
217 header_extra2 configuration
219 INT sbr_limiter_bands
; /*!< Number of limiter bands. */
220 INT sbr_limiter_gains
; /*!< Gain of limiter. */
221 INT sbr_interpol_freq
; /*!< Flag: use interpolation in freq. direction. */
222 INT sbr_smoothing_length
; /*!< Flag: choose length 4 or 0 (=on, off). */
223 UCHAR init_amp_res_FF
;
224 } sbrConfiguration
, *sbrConfigurationPtr
;
226 typedef struct SBR_CONFIG_DATA
228 UINT sbrSyntaxFlags
; /**< SBR syntax flags derived from AOT. */
229 INT nChannels
; /**< Number of channels. */
231 INT nSfb
[2]; /**< Number of SBR scalefactor bands for LO_RES and HI_RES (?) */
232 INT num_Master
; /**< Number of elements in v_k_master. */
233 INT sampleFreq
; /**< SBR sampling frequency. */
235 INT xOverFreq
; /**< The SBR start frequency. */
236 INT dynXOverFreq
; /**< Used crossover frequency when dynamic bandwidth is enabled. */
237 INT noQmfBands
; /**< Number of QMF frequency bands. */
238 INT noQmfSlots
; /**< Number of QMF slots. */
240 UCHAR
*freqBandTable
[2]; /**< Frequency table for low and hires, only MAX_FREQ_COEFFS/2 +1 coeefs actually needed for lowres. */
241 UCHAR
*v_k_master
; /**< Master BandTable where freqBandTable is derived from. */
244 SBR_STEREO_MODE stereoMode
;
245 INT noEnvChannels
; /**< Number of envelope channels. */
247 INT useWaveCoding
; /**< Flag indicates whether to use wave coding at all. */
248 INT useParametricCoding
; /**< Flag indicates whether to use para coding at all. */
249 INT xposCtrlSwitch
; /**< Flag indicates whether to switch xpos ctrl on the fly. */
250 INT switchTransposers
; /**< Flag indicates whether to switch xpos on the fly . */
252 } SBR_CONFIG_DATA
, *HANDLE_SBR_CONFIG_DATA
;
255 MP4_ELEMENT_ID elType
;
258 UCHAR fParametricStereo
;
260 UCHAR ChannelIndex
[2];
267 typedef struct SBR_ENCODER
*HANDLE_SBR_ENCODER
;
270 * \brief Get the max required input buffer size including delay balancing space
271 * for N audio channels.
272 * \param noChannels Number of audio channels.
273 * \return Max required input buffer size in bytes.
275 INT
sbrEncoder_GetInBufferSize(int noChannels
);
278 HANDLE_SBR_ENCODER
*phSbrEncoder
,
285 * \brief Get closest working bitrate to specified desired
286 * bitrate for a single SBR element.
287 * \param bitRate The desired target bit rate
288 * \param numChannels The amount of audio channels
289 * \param coreSampleRate The sample rate of the core coder
290 * \param aot The current Audio Object Type
291 * \return Closest working bit rate to bitRate value
293 UINT
sbrEncoder_LimitBitRate(UINT bitRate
, UINT numChannels
, UINT coreSampleRate
, AUDIO_OBJECT_TYPE aot
);
297 * \brief Check whether downsampled SBR single rate is possible
298 * with given audio object type.
299 * \param aot The Audio object type.
300 * \return 0 when downsampled SBR is not possible,
301 * 1 when downsampled SBR is possible.
303 UINT
sbrEncoder_IsSingleRatePossible(AUDIO_OBJECT_TYPE aot
);
306 * \brief Initialize SBR Encoder instance.
307 * \param phSbrEncoder Pointer to a SBR Encoder instance.
308 * \param elInfo Structure that describes the element/channel arrangement.
309 * \param noElements Amount of elements described in elInfo.
310 * \param inputBuffer Pointer to the encoder audio buffer
311 * \param bandwidth Returns the core audio encoder bandwidth (output)
312 * \param bufferOffset Returns the offset for the audio input data in order to do delay balancing.
313 * \param numChannels Input: Encoder input channels. output: core encoder channels.
314 * \param sampleRate Input: Encoder samplerate. output core encoder samplerate.
315 * \param downSampleFactor Input: Relation between SBR and core coder sampling rate;
316 * \param frameLength Input: Encoder frameLength. output core encoder frameLength.
317 * \param aot Input: Desired AOT. output AOT to be used after parameter checking.
318 * \param delay Input: core encoder delay. Output: total delay because of SBR.
319 * \param transformFactor The core encoder transform factor (blockswitching).
320 * \param headerPeriod Repetition rate of the SBR header:
321 * - (-1) means intern configuration.
322 * - (1-10) corresponds to header repetition rate in frames.
323 * \return 0 on success, and non-zero if failed.
326 HANDLE_SBR_ENCODER hSbrEncoder
,
327 SBR_ELEMENT_INFO elInfo
[(8)],
329 INT_PCM
*inputBuffer
,
331 INT
*inputBufferOffset
,
334 UINT
*downSampleFactor
,
336 AUDIO_OBJECT_TYPE aot
,
339 const int headerPeriod
,
344 * \brief Do delay line buffers housekeeping. To be called after each encoded audio frame.
345 * \param hEnvEnc SBR Encoder handle.
346 * \param timeBuffer Pointer to the encoder audio buffer.
347 * \return 0 on success, and non-zero if failed.
349 INT
sbrEncoder_UpdateBuffers(HANDLE_SBR_ENCODER hEnvEnc
,
354 * \brief Close SBR encoder instance.
355 * \param phEbrEncoder Handle of SBR encoder instance to be closed.
358 void sbrEncoder_Close(HANDLE_SBR_ENCODER
*phEbrEncoder
);
361 * \brief Encode SBR data of one complete audio frame.
362 * \param hEnvEncoder Handle of SBR encoder instance.
363 * \param samples Time samples, always interleaved.
364 * \param timeInStride Channel stride factor of samples buffer.
365 * \param sbrDataBits Size of SBR payload in bits.
366 * \param sbrData SBR payload.
367 * \return 0 on success, and non-zero if failed.
369 INT
sbrEncoder_EncodeFrame(HANDLE_SBR_ENCODER hEnvEncoder
,
372 UINT sbrDataBits
[(8)],
373 UCHAR sbrData
[(8)][MAX_PAYLOAD_SIZE
]
377 * \brief Write SBR headers of one SBR element.
378 * \param sbrEncoder Handle of the SBR encoder instance.
379 * \param hBs Handle of bit stream handle to write SBR header to.
380 * \param element_index Index of the SBR element which header should be written.
381 * \param fSendHeaders Flag indicating that the SBR encoder should send more headers in the SBR payload or not.
384 void sbrEncoder_GetHeader(HANDLE_SBR_ENCODER sbrEncoder
,
385 HANDLE_FDK_BITSTREAM hBs
,
390 * \brief SBR encoder bitrate estimation.
391 * \param hSbrEncoder SBR encoder handle.
392 * \return Estimated bitrate.
394 INT
sbrEncoder_GetEstimateBitrate(HANDLE_SBR_ENCODER hSbrEncoder
);
398 * \brief Delay between input data and downsampled output data.
399 * \param hSbrEncoder SBR encoder handle.
402 INT
sbrEncoder_GetInputDataDelay(HANDLE_SBR_ENCODER hSbrEncoder
);
405 * \brief Get decoder library version info.
406 * \param info Pointer to an allocated LIB_INFO struct, where library info is written to.
407 * \return 0 on sucess.
409 INT
sbrEncoder_GetLibInfo(LIB_INFO
*info
);
411 void sbrPrintRAM(void);
413 void sbrPrintROM(void);
419 #endif /* ifndef __SBR_MAIN_H */