1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
20 Pathname: PVMP4AudioDecoderInitLibrary.c
23 ------------------------------------------------------------------------------
26 Description: Copied from aac_decode_frame
28 Description: Clean up.
30 Description: Update per review comments
32 Description: Add frame_length, fix mistake in pseudo-code.
33 Change frame_length to frameLength, to matcht the API,
34 look more professional, etc.
37 (1) Added #include of "e_ProgConfigConst.h"
38 Previously, this function was relying on another include file
39 to include "e_ProgConfigConst.h"
41 (2) Updated the copyright header.
44 (1) Modified to initialize pointers for shared memory techniques.
46 Description: Since memory will be allocated continuously, it is initialized
49 Description: Added field aacPlusUpsamplingFactor (default == 1) to have a
50 common interface for all AAC variations
52 Description: Added PVMP4AudioDecoderDisableAacPlus to disable sbr decoding
57 ------------------------------------------------------------------------------
58 INPUT AND OUTPUT DEFINITIONS
61 pExt = pointer to the external application-program interface (API)
62 structure that a client program uses to communicate information
63 with this library. Among the items in this structure is a pointer
64 to the input and output buffers, data for handling the input buffer
65 and output information. Look in PVMP4AudioDecoder_API.h for all the
66 fields to this structure. Data type pointer to a
67 tPVMP4AudioDecoderExternal structure.
69 pMem = pointer to allocated memory, of the size returned by the function
70 PVMP4AudioDecoderGetMemRequirements. This is a void pointer for
72 1) So the external program does not need all of the header files
73 for all of the fields in the structure tDec_Int_File
74 2) To hide data and the implementation of the program. Even knowing
75 how data is stored can help in reverse engineering software.
77 Local Stores/Buffers/Pointers Needed: None
79 Global Stores/Buffers/Pointers Needed: None
82 status = 0 (SUCCESS). Presently there is no error checking in this
85 Pointers and Buffers Modified: None
87 Local Stores Modified: None
89 Global Stores Modified: None
91 ------------------------------------------------------------------------------
94 Initializes the internal memory for the MP4 Audio Decoder library.
95 Also sets relevant values for the external interface structure, clears
96 the bit rate, channel count, sampling rate, and number of used buffer
99 ------------------------------------------------------------------------------
103 ------------------------------------------------------------------------------
106 (1) MPEG-2 NBC Audio Decoder
107 "This software module was originally developed by AT&T, Dolby
108 Laboratories, Fraunhofer Gesellschaft IIS in the course of development
109 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
110 3. This software module is an implementation of a part of one or more
111 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
112 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
113 standards free license to this software module or modifications thereof
114 for use in hardware or software products claiming conformance to the
115 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software
116 module in hardware or software products are advised that this use may
117 infringe existing patents. The original developer of this software
118 module and his/her company, the subsequent editors and their companies,
119 and ISO/IEC have no liability for use of this software module or
120 modifications thereof in an implementation. Copyright is not released
121 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
122 developer retains full right to use the code for his/her own purpose,
123 assign or donate the code to a third party and to inhibit third party
124 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
125 This copyright notice must be included in all copies or derivative
128 ------------------------------------------------------------------------------
136 n = sizeof(tDec_Int_File))
137 MODIFYING(*pVars = 0)
140 pVars->current_program = -1
141 pVars->mc_info.sampling_rate_idx = Fs_44
142 pVars->frameLength = LONG_WINDOW
145 pVars->winmap[ONLY_LONG_SEQUENCE] = &pVars->longFrameInfo;
146 pVars->winmap[LONG_START_SEQUENCE] = &pVars->longFrameInfo;
147 pVars->winmap[EIGHT_SHORT_SEQUENCE] = &pVars->shortFrameInfo;
148 pVars->winmap[LONG_STOP_SEQUENCE] = &pVars->longFrameInfo;
151 samp_rate_indx = pVars->mc_info.sampling_rate_idx,
152 ppWin_seq_info = pVars->winmap,
153 pSfbwidth128 = pVars->SFBWidth128)
154 MODIFYING(ppWinSeq_info)
155 MODIFYING(pSfbwidth128)
159 pExt->encodedChannels = 0;
160 pExt->samplingRate = 0;
161 pExt->inputBufferUsedLength = 0;
167 ------------------------------------------------------------------------------
169 When the code is written for a specific target processor the
170 the resources used should be documented below.
172 STACK USAGE: [stack count for this module] + [variable to represent
173 stack usage for each subroutine called]
175 where: [stack usage variable] = stack usage for [subroutine
176 name] (see [filename].ext)
178 DATA MEMORY USED: x words
180 PROGRAM MEMORY USED: x words
182 CLOCK CYCLES: [cycle count equation for this module] + [variable
183 used to represent cycle count for each subroutine
186 where: [cycle count variable] = cycle count for [subroutine
187 name] (see [filename].ext)
189 ------------------------------------------------------------------------------
193 /*----------------------------------------------------------------------------
195 ----------------------------------------------------------------------------*/
197 #include "pv_audio_type_defs.h"
198 #include "s_tdec_int_file.h"
199 #include "e_progconfigconst.h"
201 #include "huffman.h" /* For the definition of infoinit */
202 #include "aac_mem_funcs.h" /* For pv_memset */
203 #include "pvmp4audiodecoder_api.h" /* Where this function is declared */
204 #include "s_tdec_int_chan.h"
205 #include "sfb.h" /* samp_rate_info[] is declared here */
207 /*----------------------------------------------------------------------------
209 ; Define module specific macros here
210 ----------------------------------------------------------------------------*/
212 /*----------------------------------------------------------------------------
214 ; Include all pre-processor statements here. Include conditional
215 ; compile variables also.
216 ----------------------------------------------------------------------------*/
218 /*----------------------------------------------------------------------------
219 ; LOCAL FUNCTION DEFINITIONS
220 ; Function Prototype declaration
221 ----------------------------------------------------------------------------*/
223 /*----------------------------------------------------------------------------
224 ; LOCAL VARIABLE DEFINITIONS
225 ; Variable declaration - defined here and used outside this module
226 ----------------------------------------------------------------------------*/
228 /*----------------------------------------------------------------------------
229 ; EXTERNAL FUNCTION REFERENCES
230 ; Declare functions defined elsewhere and referenced in this module
231 ----------------------------------------------------------------------------*/
233 /*----------------------------------------------------------------------------
234 ; EXTERNAL VARIABLES REFERENCES
235 ; Declare variables used in this module but defined elsewhere
236 ----------------------------------------------------------------------------*/
238 /*----------------------------------------------------------------------------
240 ----------------------------------------------------------------------------*/
241 OSCL_EXPORT_REF Int PVMP4AudioDecoderInitLibrary(
242 tPVMP4AudioDecoderExternal *pExt,
245 tDec_Int_File *pVars;
247 pVars = (tDec_Int_File *)pMem;
250 * Initialize all memory. The pointers to channel memory will be
256 sizeof(tDec_Int_File));
259 * Pick default values for the library.
261 pVars->perChan[0].fxpCoef = pVars->fxpCoef[0];
262 pVars->perChan[1].fxpCoef = pVars->fxpCoef[1];
264 /* Here, the "shared memory" pointer is set to point
265 * at the 1024th element of fxpCoef, because those spaces
266 * in memory are not used until the filterbank is called.
268 * Therefore, any variables that are only used before
269 * the filterbank can occupy this same space in memory.
272 pVars->perChan[0].pShareWfxpCoef = (per_chan_share_w_fxpCoef *)
273 & (pVars->perChan[0].fxpCoef[1024]);
275 pVars->perChan[1].pShareWfxpCoef = (per_chan_share_w_fxpCoef *)
276 & (pVars->perChan[1].fxpCoef[1024]);
279 * This next line informs the function get_prog_config that no
280 * configuration has been found thus far, so it is a default
284 pVars->current_program = -1;
285 pVars->mc_info.sampling_rate_idx = Fs_44; /* Fs_44 = 4, 44.1kHz */
288 * In the future, the frame length will change with MP4 file format.
289 * Presently this variable is used to simply the unit test for
290 * the function PVMP4AudioDecodeFrame() .. otherwise the test would
291 * have to pass around 1024 length arrays.
293 pVars->frameLength = LONG_WINDOW; /* 1024*/
296 * The window types ONLY_LONG_SEQUENCE, LONG_START_SEQUENCE, and
297 * LONG_STOP_SEQUENCE share the same information. The only difference
298 * between the windows is accounted for in the "filterbank", in
299 * the function trans4m_freq_2_time_fxp()
302 pVars->winmap[ONLY_LONG_SEQUENCE] /* 0 */ = &pVars->longFrameInfo;
303 pVars->winmap[LONG_START_SEQUENCE] /* 1 */ = &pVars->longFrameInfo;
304 pVars->winmap[EIGHT_SHORT_SEQUENCE] /* 2 */ = &pVars->shortFrameInfo;
305 pVars->winmap[LONG_STOP_SEQUENCE] /* 3 */ = &pVars->longFrameInfo;
308 pVars->mc_info.sampling_rate_idx,
309 (FrameInfo **)pVars->winmap,
314 * Clear out external output values. These values are set later at the end
315 * of PVMP4AudioDecodeFrames()
318 pExt->encodedChannels = 0;
319 pExt->samplingRate = 0;
320 pExt->aacPlusUpsamplingFactor = 1; /* Default for regular AAC */
321 pVars->aacPlusEnabled = pExt->aacPlusEnabled;
324 #if defined(AAC_PLUS)
325 pVars->sbrDecoderData.setStreamType = 1; /* Enable Lock for AAC stream type setting */
329 * Initialize input buffer variable.
332 pExt->inputBufferUsedLength = 0;
334 return (MP4AUDEC_SUCCESS);
336 } /* PVMP4AudioDecoderInitLibrary */
340 ------------------------------------------------------------------------------
341 INPUT AND OUTPUT DEFINITIONS
344 pExt = pointer to the external application-program interface (API)
345 structure that a client program uses to communicate information
346 with this library. Among the items in this structure is a pointer
347 to the input and output buffers, data for handling the input buffer
348 and output information. Look in PVMP4AudioDecoder_API.h for all the
349 fields to this structure. Data type pointer to a
350 tPVMP4AudioDecoderExternal structure.
352 pMem = pointer to allocated memory, of the size returned by the function
353 PVMP4AudioDecoderGetMemRequirements. This is a void pointer for
355 1) So the external program does not need all of the header files
356 for all of the fields in the structure tDec_Int_File
357 2) To hide data and the implementation of the program. Even knowing
358 how data is stored can help in reverse engineering software.
360 Local Stores/Buffers/Pointers Needed: None
362 Global Stores/Buffers/Pointers Needed: None
365 status = 0 (SUCCESS). Presently there is no error checking in this
368 Pointers and Buffers Modified: None
370 Local Stores Modified: None
372 Global Stores Modified: None
374 ------------------------------------------------------------------------------
377 Disable SBR decoding functionality and set parameters accordingly
379 ------------------------------------------------------------------------------
383 ----------------------------------------------------------------------------
385 ----------------------------------------------------------------------------*/
388 OSCL_EXPORT_REF void PVMP4AudioDecoderDisableAacPlus(
389 tPVMP4AudioDecoderExternal *pExt,
392 tDec_Int_File *pVars;
394 pVars = (tDec_Int_File *)pMem;
396 if ((pVars->aacPlusEnabled == true) && (pExt->aacPlusEnabled == true))
398 // disable only when makes sense
399 pVars->aacPlusEnabled = false;
400 pExt->aacPlusEnabled = false;
402 #if defined(AAC_PLUS)
403 pVars->mc_info.upsamplingFactor = 1;
404 pVars->mc_info.psPresentFlag = 0;
405 pVars->mc_info.sbrPresentFlag = 0;
406 pVars->prog_config.sampling_rate_idx += 3;
407 pVars->sbrDecoderData.SbrChannel[0].syncState = SBR_NOT_INITIALIZED;
408 pVars->sbrDecoderData.SbrChannel[1].syncState = SBR_NOT_INITIALIZED;
411 pExt->samplingRate = samp_rate_info[pVars->prog_config.sampling_rate_idx].samp_rate;
412 pExt->aacPlusUpsamplingFactor = 1;
415 } /* PVMP4AudioDecoderDisableAacPlus */