2 /*
3 Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamOutInit.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/runtime/Log.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Memory.h>
45 #include <acp_mds.h>
46 #include "pafsio_ialg.h"
47 #include "stdasp.h"
49 #include "common.h"
50 #include "audioStreamProc_common.h"
51 #include "audioStreamOutProc.h"
53 // -----------------------------------------------------------------------------
54 // Debugging Trace Control, local to this file.
55 //
56 #include "logp.h"
58 // Allow a developer to selectively enable tracing.
59 #define CURRENT_TRACE_MASK 0x07
61 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
62 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
63 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
65 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
66 #undef TRACE_TERSE0
67 #undef TRACE_TERSE1
68 #undef TRACE_TERSE2
69 #undef TRACE_TERSE3
70 #undef TRACE_TERSE4
71 #define TRACE_TERSE0(a)
72 #define TRACE_TERSE1(a,b)
73 #define TRACE_TERSE2(a,b,c)
74 #define TRACE_TERSE3(a,b,c,d)
75 #define TRACE_TERSE4(a,b,c,d,e)
76 #endif
78 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
79 #undef TRACE_GEN0
80 #undef TRACE_GEN1
81 #undef TRACE_GEN2
82 #undef TRACE_GEN3
83 #undef TRACE_GEN4
84 #define TRACE_GEN0(a)
85 #define TRACE_GEN1(a,b)
86 #define TRACE_GEN2(a,b,c)
87 #define TRACE_GEN3(a,b,c,d)
88 #define TRACE_GEN4(a,b,c,d,e)
89 #endif
91 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
92 #undef TRACE_VERBOSE0
93 #undef TRACE_VERBOSE1
94 #undef TRACE_VERBOSE2
95 #undef TRACE_VERBOSE3
96 #undef TRACE_VERBOSE4
97 #define TRACE_VERBOSE0(a)
98 #define TRACE_VERBOSE1(a,b)
99 #define TRACE_VERBOSE2(a,b,c)
100 #define TRACE_VERBOSE3(a,b,c,d)
101 #define TRACE_VERBOSE4(a,b,c,d,e)
102 #endif
104 // -----------------------------------------------------------------------------
105 //
106 // Audio Stream Output Task definitions
107 //
109 //
110 // Audio Stream Processing Definitions
111 //
112 #define aspLinkInit pQ->i_aspLinkInit
114 //
115 // Encoder Definitions
116 //
117 #define encLinkInit pQ->i_encLinkInit
119 //
120 // Output Definitions
121 //
122 #define outLinkInit pP->i_outLinkInit
124 // -----------------------------------------------------------------------------
126 LINNO_DECL(TaskAsop); // Line number macros
127 ERRNO_DECL(TaskAsop); // Error number macros
129 // Create ASOT event
130 static Int asotCreateEvent(void);
132 // Create IO Buff & Phy framework components
133 static Int PAF_ASOT_ioCompCreate(
134 PAF_AST_IoOut *pIoOut,
135 Int numOut,
136 IHeap_Handle iHeapHandle
137 );
139 // Audio Stream Output Processing initialization function
140 Void taskAsopFxnInit(
141 const PAF_ASOT_Params *pP,
142 const PAF_ASOT_Patchs *pQ
143 )
144 {
145 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
146 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
147 PAF_AST_IoOut *pOut;
148 Int as; /* Audio Stream Number (1, 2, etc.) */
149 Int z; /* input/encode/stream/decode/output counter */
150 Int i; /* phase */
151 Int zMS;
152 Int status;
154 Log_info0("Enter taskAsopFxnInit()");
156 //
157 // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
158 //
159 if (!pP)
160 {
161 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
162 LINNO_RPRT(TaskAsop, -1);
163 return;
164 }
166 if (!pQ)
167 {
168 TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
169 LINNO_RPRT(TaskAsop, -1);
170 return;
171 }
173 //
174 // Audio Stream Output Task Configuration (*pAsotCfg):
175 //
176 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
177 pAsotCfg->taskHandle = Task_self(); // set task handle
178 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
180 // Create ASOT event
181 status = astCreateEvent(&gAsotEvtHandle);
182 if (status < 0)
183 {
184 TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
185 return;
186 }
188 /* Obtain Audio Stream Number (1, 2, etc.) */
189 as = pAstCfg->as;
190 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
192 //
193 // Initialize message log trace and line number reporting
194 //
195 for (z=STREAM1; z < STREAMN; z++)
196 {
197 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
198 }
199 LINNO_RPRT(TaskAsop, -1);
201 //
202 // Determine stream index
203 //
204 zMS = pAstCfg->masterStr;
206 // Initialize as per parametrized phases:
207 //
208 // In standard form these are:
209 // - Malloc: Memory Allocation
210 // - Config: Configuration Initialization
211 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
212 // - Common: Common Memory Initialization
213 // - AlgKey: Dec/Enc chain to Array Initialization
214 // - Device: I/O Device Initialization
215 // - Unused: (available)
216 // - Unused: (available)
217 //
218 LINNO_RPRT(TaskAsop, -2);
219 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
220 {
221 Int linno;
222 if (pP->fxns->initPhase[i])
223 {
224 linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
225 if (linno)
226 {
227 LINNO_RPRT(TaskAsop, linno);
228 return;
229 }
230 }
231 else
232 {
233 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
234 }
235 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
236 LINNO_RPRT(TaskAsop, -i-3);
237 }
239 //
240 // End of Initialization -- display memory usage report.
241 //
242 if (pP->fxns->memStatusPrint)
243 {
244 pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
245 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
246 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
247 }
249 pOut = &pAsotCfg->pIoOut[zMS];
250 pOut->hMcaspChan = NULL;
251 } /* taskAsopFxnInit */
253 #if 0
254 // Create ASOT event object
255 static Int asotCreateEvent(void)
256 {
257 Error_Block eb;
259 Error_init(&eb);
261 // Default instance configuration params
262 asotEvt = Event_create(NULL, &eb);
263 if (asotEvt == NULL)
264 {
265 return -1; // error code
266 }
268 return 0;
269 } /* asotCreateEvent */
270 #endif
272 // Create IO Buff & Phy framework components
273 static Int PAF_ASOT_ioCompCreate(
274 PAF_AST_IoOut *pIoOut,
275 Int numOut,
276 IHeap_Handle iHeapHandle)
277 {
278 int i, j, num_alloc;
279 lib_mem_rec_t *mem_rec;
280 ioBuffHandle_t ioBufHandle;
281 ioPhyHandle_t ioPhyHandle;
282 Error_Block eb;
284 for(i=0; i<numOut; i++)
285 {
286 // Create an I/O BUFF instance
287 // Obtain number of memory blocks required by I/O BUFF
288 num_alloc = ioBuffNumAlloc();
290 // Obtain requirements of each memory block
291 mem_rec = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
292 if(ioBuffAlloc(mem_rec) != IOBUFF_NOERR) {
293 return __LINE__;
294 }
296 /* Allocate memory and create I/O BUFF instance */
297 for(j=0; j<num_alloc; j++) {
298 mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
299 (1<<mem_rec[j].alignment), &eb);
300 }
302 if(ioBuffCreate(&ioBufHandle, mem_rec) != IOBUFF_NOERR) {
303 return __LINE__;
304 }
306 pIoOut[i].hIoBuff = ioBufHandle;
308 free(mem_rec);
310 // Create an I/O PHY instance
311 // Obtain number of memory blocks required by I/O PHY
312 num_alloc = ioPhyNumAlloc();
314 // Obtain requirements of each memory block
315 mem_rec = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
316 if(ioPhyAlloc(mem_rec) != IOBUFF_NOERR) {
317 return __LINE__;
318 }
320 /* Allocate memory and create I/O PHY instance */
321 for(j=0; j<num_alloc; j++) {
322 mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
323 (1<<mem_rec[j].alignment), &eb);
324 }
326 if(ioPhyCreate(&ioPhyHandle, mem_rec) != IOBUFF_NOERR) {
327 return __LINE__;
328 }
330 pIoOut[i].hIoPhy = ioPhyHandle;
332 free(mem_rec);
334 } // end of for loop
336 return 0;
337 } // PAF_ASOT_ioCompCreate
339 // -----------------------------------------------------------------------------
340 // AST Initialization Function - Memory Allocation
341 //
342 // Name: PAF_ASOT_initPhaseMalloc
343 // Purpose: Audio Stream Output Task Function for initialization of data pointers
344 // by allocation of memory.
345 // From: audioStream1Task or equivalent
346 // Uses: See code.
347 // States: x
348 // Return: 0 on success.
349 // Source code line number on MEM_calloc failure.
350 // Trace: Message Log "trace" in Debug Project Configuration reports:
351 // * State information as per parent.
352 // * Memory allocation errors.
353 //
355 Int PAF_ASOT_initPhaseMalloc(
356 const PAF_ASOT_Params *pP,
357 const PAF_ASOT_Patchs *pQ,
358 PAF_ASOT_Config *pAsotCfg
359 )
360 {
361 PAF_AST_Config *pAstCfg;
362 Int as; /* Audio Stream Number (1, 2, etc.) */
363 Int zMS, errLineNum;
364 Error_Block eb;
365 //Int i;
367 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
368 as = pAstCfg->as;
369 zMS = pAstCfg->masterStr;
371 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
373 // Initialize error block
374 Error_init(&eb);
376 /* Stream memory */
377 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
378 {
379 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
380 SW_BREAKPOINT;
381 return __LINE__;
382 }
383 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
384 STREAMN * sizeof (*pAstCfg->xStr),
385 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
387 {
388 Int z; /* stream counter */
390 PAF_AudioFrame *fBuf;
392 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
393 {
394 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
395 SW_BREAKPOINT;
396 return __LINE__;
397 }
398 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
399 STREAMS * sizeof (*fBuf),
400 HEAP_ID_INTERNAL, (IArg)fBuf);
402 for (z=STREAM1; z < STREAMN; z++)
403 {
404 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
405 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
406 }
407 }
409 /* Encode memory */
410 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
411 {
412 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
413 SW_BREAKPOINT;
414 return __LINE__;
415 }
416 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
417 ENCODEN * sizeof (*pAstCfg->xEnc),
418 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
420 /* Output memory */
421 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
422 {
423 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
424 SW_BREAKPOINT;
425 return __LINE__;
426 }
427 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
428 OUTPUTN * sizeof (*pAstCfg->xOut),
429 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
431 /* Output I/O data structure memory */
432 if (!(pAsotCfg->pIoOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAsotCfg->pIoOut), 4, &eb)))
433 {
434 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
435 SW_BREAKPOINT;
436 return __LINE__;
437 }
438 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAsotCfg->pIoOut) %d bytes from space %d at 0x%x.",
439 OUTPUTN * sizeof (*pAsotCfg->pIoOut),
440 HEAP_ID_INTERNAL, (IArg)pAsotCfg->pIoOut);
442 /* I/O components memory for output */
443 errLineNum = PAF_ASOT_ioCompCreate(pAsotCfg->pIoOut, OUTPUTN, (IHeap_Handle)HEAP_INTERNAL);
444 if(errLineNum)
445 {
446 SW_BREAKPOINT;
447 return errLineNum;
448 }
449 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
450 return 0;
451 } //PAF_ASOT_initPhaseMalloc
453 // -----------------------------------------------------------------------------
454 // ASOT Initialization Function - Memory Initialization from Configuration
455 //
456 // Name: PAF_ASOT_initPhaseConfig
457 // Purpose: Audio Stream Output Task Function for initialization of data values
458 // from parameters.
459 // From: audioStream1Task or equivalent
460 // Uses: See code.
461 // States: x
462 // Return: 0 on success.
463 // Other as per initFrame0 and initFrame1.
464 // Trace: Message Log "trace" in Debug Project Configuration reports:
465 // * State information as per parent.
466 //
467 Int PAF_ASOT_initPhaseConfig(
468 const PAF_ASOT_Params *pP,
469 const PAF_ASOT_Patchs *pQ,
470 PAF_ASOT_Config *pAsotCfg
471 )
472 {
473 PAF_AST_Config *pAstCfg;
474 Int as; /* Audio Stream Number (1, 2, etc.) */
475 Int z; /* input/encode/stream/decode/output counter */
476 Int zMS;
478 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
479 as = pAstCfg->as;
480 zMS = pAstCfg->masterStr;
482 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
484 //
485 // Unspecified elements have been initialized to zero during alloc
486 //
488 for (z=STREAM1; z < STREAMN; z++)
489 {
490 Int linno;
491 if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
492 {
493 return linno;
494 }
495 if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
496 {
497 return linno;
498 }
499 }
501 for (z=ENCODE1; z < ENCODEN; z++)
502 {
503 Int zO = pP->outputsFromEncodes[z];
504 Int zS = pP->streamsFromEncodes[z];
505 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
506 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
507 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
508 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
509 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
510 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
511 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
512 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
513 }
515 for (z=OUTPUT1; z < OUTPUTN; z++)
516 {
517 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
518 }
520 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
521 return 0;
522 } //PAF_ASOT_initPhaseConfig
524 // -----------------------------------------------------------------------------
525 // ASOT Initialization Function - ACP Algorithm Instantiation
526 //
527 // Name: PAF_ASOT_initPhaseAcpAlg
528 // Purpose: Audio Stream Input Task Function for initialization of ACP by
529 // instantiation of the algorithm.
530 // From: audioStream1Task or equivalent
531 // Uses: See code.
532 // States: x
533 // Return: 0 on success.
534 // Source code line number on ACP Algorithm creation failure.
535 // Trace: Message Log "trace" in Debug Project Configuration reports:
536 // * State information as per parent.
537 // * Memory allocation errors.
538 //
539 Int PAF_ASOT_initPhaseAcpAlg(
540 const PAF_ASOT_Params *pP,
541 const PAF_ASOT_Patchs *pQ,
542 PAF_ASOT_Config *pAsotCfg
543 )
544 {
545 PAF_AST_Config *pAstCfg;
546 Int as; /* Audio Stream Number (1, 2, etc.) */
547 Int z; /* input/encode/stream/decode/output counter */
548 Int betaPrimeOffset;
549 ACP_Handle acp;
550 Int zMS;
551 Int zS, zX;
553 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
554 as = pAstCfg->as;
555 zMS = pAstCfg->masterStr;
557 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
559 ACP_MDS_init();
561 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
562 {
563 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
564 return __LINE__;
565 }
566 pAsotCfg->acp = acp;
568 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
569 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
571 for (z=ENCODE1; z < ENCODEN; z++)
572 {
573 zS = pP->streamsFromEncodes[z];
574 acp->fxns->attach(acp, ACP_SERIES_STD,
575 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
576 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
577 acp->fxns->attach(acp, ACP_SERIES_STD,
578 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
579 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
580 /* Ignore errors, not reported. */
581 }
583 for (z=OUTPUT1; z < OUTPUTN; z++)
584 {
585 zS = z;
586 for (zX = ENCODE1; zX < ENCODEN; zX++)
587 {
588 if (pP->outputsFromEncodes[zX] == z)
589 {
590 zS = pP->streamsFromEncodes[zX];
591 break;
592 }
593 }
594 acp->fxns->attach(acp, ACP_SERIES_STD,
595 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
596 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
597 /* Ignore errors, not reported. */
598 }
600 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
602 return 0;
603 } //PAF_ASOT_initPhaseAcpAlg
605 // -----------------------------------------------------------------------------
606 // ASOT Initialization Function - Common Memory
607 //
608 // Name: PAF_ASOT_initPhaseCommon
609 // Purpose: Audio Stream Output Task Function for allocation of common memory.
610 // From: audioStream1Task or equivalent
611 // Uses: See code.
612 // States: x
613 // Return: 0 on success.
614 // Source code line number on PAF_ALG_alloc failure.
615 // Source code line number on PAF_ALG_mallocMemory failure.
616 // Source code line number on Decode Chain initialization failure.
617 // Source code line number on ASP Chain initialization failure.
618 // Source code line number on Encode Chain initialization failure.
619 // Trace: Message Log "trace" in Debug Project Configuration reports:
620 // * State information as per parent.
621 // * Memory allocation errors.
622 //
623 Int PAF_ASOT_initPhaseCommon(
624 const PAF_ASOT_Params *pP,
625 const PAF_ASOT_Patchs *pQ,
626 PAF_ASOT_Config *pAsotCfg
627 )
628 {
629 PAF_AST_Config *pAstCfg;
630 Int as; /* Audio Stream Number (1, 2, etc.) */
631 Int z; /* stream counter */
632 Int g; /* gear */
633 ACP_Handle acp;
634 PAF_IALG_Config pafAlgConfig;
635 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
637 acp = pAsotCfg->acp;
638 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
639 as = pAstCfg->as;
641 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
643 //
644 // Determine memory needs and instantiate algorithms across audio streams
645 //
646 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
647 PAF_ALG_setup(&pafAlgConfig,
648 HEAP_ID_INTERNAL, HEAP_INTERNAL,
649 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
650 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
651 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
652 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
653 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
654 HEAP_CLEAR);
656 if (pP->fxns->headerPrint)
657 {
658 pP->fxns->headerPrint();
659 }
661 for (z = STREAM1; z < STREAMN; z++)
662 {
663 //Int zD, zE, zX;
664 Int zE, zX;
666 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
668 //
669 // Determine common memory needs for:
670 // (1) ASP Algorithms
671 // (2) Encode Algorithms
672 // (3) Logical Output drivers
673 //
674 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
676 zE = -1;
677 for (zX = ENCODE1; zX < ENCODEN; zX++)
678 {
679 if (pP->streamsFromEncodes[zX] == z)
680 {
681 zE = zX;
682 break;
683 }
684 }
686 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
687 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
688 {
689 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
690 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
691 SW_BREAKPOINT;
692 return __LINE__;
693 }
694 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
695 if (pP->fxns->allocPrint)
696 {
697 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
698 }
700 if (zE >= 0)
701 {
702 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
703 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
704 {
705 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
706 SW_BREAKPOINT;
707 return __LINE__;
708 }
709 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
710 if (pP->fxns->allocPrint)
711 {
712 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
713 }
714 }
716 //
717 // Determine common memory needs of Logical IO drivers
718 //
720 if (OUTPUT1 <= z && z < OUTPUTN)
721 {
722 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
723 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
724 {
725 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
726 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
727 SW_BREAKPOINT;
728 return __LINE__;
729 }
730 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
731 if (pP->fxns->allocPrint)
732 {
733 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
734 }
735 }
736 }
737 {
738 // Changes made to share scratch between zones
739 // Assume maximum 3 zones and scratch common memory is at offset 0;
740 int max=0;
741 for (z=STREAM1; z<STREAMN; z++)
742 {
743 if (max < common[z][0].size)
744 {
745 max = common[z][0].size;
746 }
747 }
748 common[STREAM1][0].size=max;
749 for (z=STREAM1+1; z<STREAMN; z++)
750 {
751 common[z][0].size = 0;
752 }
753 }
755 //
756 // Allocate common memory for:
757 // (1) ASP Algorithms
758 // (2) Encode Algorithms
759 // (3) Logical Output drivers
760 //
761 for (z = STREAM1; z < STREAMN; z++)
762 {
763 //Int zD, zE, zX;
764 Int zE, zX;
766 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
767 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
768 {
769 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
770 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
771 SW_BREAKPOINT;
772 return __LINE__;
773 }
774 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
775 // share zone0 scratch with all zones
776 common[z][0].base = common[0][0].base;
777 if (pP->fxns->commonPrint)
778 {
779 pP->fxns->commonPrint(common[z], &pafAlgConfig);
780 }
782 zE = -1;
783 for (zX = ENCODE1; zX < ENCODEN; zX++)
784 {
785 if (pP->streamsFromEncodes[zX] == z)
786 {
787 zE = zX;
788 break;
789 }
790 }
792 pAstCfg->xStr[z].aspChain[0] = NULL;
793 for (g=0; g < GEARS; g++)
794 {
795 PAF_ASP_Chain *chain;
796 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
797 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
798 HEAP_INTERNAL, as+z, acp, &trace,
799 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
800 if (!chain)
801 {
802 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
803 return __LINE__;
804 }
805 else
806 {
807 pAstCfg->xStr[z].aspChain[g] = chain;
808 }
809 }
811 if (zE >= 0)
812 {
813 PAF_ASP_Chain *chain;
814 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
815 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
816 HEAP_INTERNAL, as+z, acp, &trace,
817 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
818 if (!chain)
819 {
820 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
821 return __LINE__;
822 }
823 }
825 //
826 // Allocate non-common memories for Logical IO drivers
827 // Since these structures are used at run-time we allocate from external memory
828 if (OUTPUT1 <= z && z < OUTPUTN)
829 {
830 PAF_ASP_Chain *chain;
831 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
832 as+z, z);
833 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
834 HEAP_EXTERNAL, as+z, acp, &trace,
835 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
836 if (!chain)
837 {
838 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
839 return __LINE__;
840 }
841 }
842 }
843 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
845 return 0;
846 } //PAF_ASOT_initPhaseCommon
848 // -----------------------------------------------------------------------------
849 // ASOT Initialization Function - Algorithm Keys
850 //
851 // Name: PAF_ASOT_initPhaseAlgKey
852 // Purpose: Audio Stream Output Task Function for initialization of data values
853 // from parameters for Algorithm Keys.
854 // From: audioStream1Task or equivalent
855 // Uses: See code.
856 // States: x
857 // Return: 0.
858 // Trace: Message Log "trace" in Debug Project Configuration reports:
859 // * State information as per parent.
860 //
861 // .............................................................................
862 Int PAF_ASOT_initPhaseAlgKey(
863 const PAF_ASOT_Params *pP,
864 const PAF_ASOT_Patchs *pQ,
865 PAF_ASOT_Config *pAsotCfg
866 )
867 {
868 PAF_AST_Config *pAstCfg;
869 Int as; /* Audio Stream Number (1, 2, etc.) */
870 Int z; /* decode/encode counter */
871 Int s; /* key number */
872 PAF_ASP_Link *that;
874 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
875 as = pAstCfg->as;
876 (void)as; // clear compiler warning in case not used with tracing disabled
878 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
880 for (z=ENCODE1; z < ENCODEN; z++)
881 {
882 for (s=0; s < pP->pEncAlgKey->length; s++)
883 {
884 if ((pP->pEncAlgKey->code[s].full != 0) &&
885 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
886 {
887 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
888 }
889 /* Cast in interface, for now --Kurt */
890 else
891 {
892 pAstCfg->xEnc[z].encAlg[s] = NULL;
893 }
894 }
895 }
897 return 0;
898 } //PAF_ASOT_initPhaseAlgKey
900 // -----------------------------------------------------------------------------
901 // ASOT Initialization Function - I/O Devices
902 //
903 // Name: PAF_ASOT_initPhaseDevice
904 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
905 // From: audioStream1Task or equivalent
906 // Uses: See code.
907 // States: x
908 // Return: 0 on success.
909 // Source code line number on device allocation failure.
910 // Trace: Message Log "trace" in Debug Project Configuration reports:
911 // * State information as per parent.
912 // * Memory allocation errors.
913 //
914 Int PAF_ASOT_initPhaseDevice(
915 const PAF_ASOT_Params *pP,
916 const PAF_ASOT_Patchs *pQ,
917 PAF_ASOT_Config *pAsotCfg
918 )
919 {
920 PAF_AST_Config *pAstCfg;
921 Int as; /* Audio Stream Number (1, 2, etc.) */
922 Int z; /* input/output counter */
923 PAF_SIO_IALG_Obj *pObj;
924 PAF_SIO_IALG_Config *pAlgConfig;
925 PAF_IALG_Config pafAlgConfig;
927 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
928 as = pAstCfg->as;
929 (void)as; // clear compiler warning in case not used with tracing disabled
931 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
933 if(pP->fxns->bufMemPrint)
934 {
935 PAF_ALG_setup (&pafAlgConfig,
936 HEAP_ID_INTERNAL, HEAP_INTERNAL,
937 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
938 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
939 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
940 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
941 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
942 HEAP_CLEAR);
943 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
944 }
946 for (z=OUTPUT1; z < OUTPUTN; z++)
947 {
948 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
950 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
951 pAlgConfig = &pObj->config;
953 pAstCfg->xOut[z].hTxSio = NULL;
954 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
955 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
956 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
957 pConfig->allocation = pAlgConfig->pMemRec[0].size;
958 pConfig->sizeofElement = 3;
959 pConfig->precision = 24;
960 if(pP->fxns->bufMemPrint)
961 {
962 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
963 }
964 }
965 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
967 return 0;
968 } //PAF_ASOT_initPhaseDevice
970 // -----------------------------------------------------------------------------
971 // ASOT Initialization Function Helper - Initialization of Audio Frame
972 //
973 // Name: PAF_ASOT_initFrame0
974 // Purpose: Audio Stream Output Task Function for initialization of the Audio
975 // Frame(s) by memory allocation and loading of data pointers
976 // and values.
977 // From: AST Parameter Function -> decodeInfo
978 // Uses: See code.
979 // States: x
980 // Return: 0 on success.
981 // Source code line number on MEM_calloc failure.
982 // Source code line number on unsupported option.
983 // Trace: Message Log "trace" in Debug Project Configuration reports:
984 // * Memory allocation errors.
985 // * Unsupported option errors.
986 //
988 // MID 314
989 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
990 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
992 Int PAF_ASOT_initFrame0(
993 const PAF_ASOT_Params *pP,
994 const PAF_ASOT_Patchs *pQ,
995 PAF_ASOT_Config *pAsotCfg,
996 Int z
997 )
998 {
999 PAF_AST_Config *pAstCfg;
1000 Int as; /* Audio Stream Number (1, 2, etc.) */
1001 Int ch;
1002 //Int aLen;
1003 Int aLen_int=0,aLen_ext=0;
1004 Int aSize = sizeof(PAF_AudioData);
1005 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1006 Int maxFrameLength = pP->maxFramelength;
1007 Int zX;
1008 PAF_AudioData *aBuf_int=NULL;
1009 PAF_AudioData *aBuf_ext=NULL;
1010 XDAS_UInt8 *metadataBuf;
1011 char i;
1012 Error_Block eb;
1014 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1015 as = pAstCfg->as;
1017 // Initialize error block
1018 Error_init(&eb);
1020 // Compute maximum framelength (needed for ARC support)
1021 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1022 //aLen = numchan[z] * maxFrameLength;
1023 for (i=0; i < numchan[z]; i++)
1024 {
1025 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1026 {
1027 aLen_int += maxFrameLength;
1028 }
1029 else
1030 {
1031 aLen_ext += maxFrameLength;
1032 }
1033 }
1035 //
1036 // Initialize audio frame elements directly
1037 //
1038 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1039 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1040 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1041 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1042 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1043 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1044 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1046 //
1047 // Allocate memory for and initialize pointers to audio data buffers
1048 //
1049 // The NUMCHANMASK is used to identify the channels for which data
1050 // buffers can be allocated. Using this mask and switch statement
1051 // rather than some other construct allows efficient code generation,
1052 // providing just the code necessary (with significant savings).
1053 //
1054 if (pP->fxns->bufMemPrint)
1055 {
1056 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1057 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1058 }
1060 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1062 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1063 {
1064 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1065 {
1066 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1067 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1068 SW_BREAKPOINT;
1069 return __LINE__;
1070 }
1071 }
1073 if (aLen_ext*aSize!=0)
1074 {
1075 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1076 {
1077 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1078 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1079 SW_BREAKPOINT;
1080 return __LINE__;
1081 }
1082 }
1084 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1085 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1087 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1088 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1089 {
1090 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1091 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1092 SW_BREAKPOINT;
1093 return __LINE__;
1094 }
1096 {
1097 Int i;
1099 #pragma UNROLL(1)
1100 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1101 {
1102 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1103 }
1104 }
1106 // MID 314
1107 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1108 {
1109 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1110 return __LINE__;
1111 }
1112 else
1113 {
1114 Int j = 0;
1115 Int k = 0;
1116 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1117 for(i=0;i<numchan[z];i++)
1118 {
1119 char chan = AFChanPtrMap[numchan[z]][i];
1120 if(chan != -1)
1121 {
1122 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1123 {
1124 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1125 j++;
1126 }
1127 else
1128 {
1129 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1130 k++;
1131 }
1132 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1133 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1134 }
1135 }
1136 }
1138 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1139 {
1140 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1141 {
1142 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1143 }
1144 }
1146 //
1147 // Initialize meta data elements
1148 //
1149 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1150 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1151 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1152 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1153 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1154 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1155 {
1156 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1157 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1158 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1159 }
1161 //
1162 // Initialize decoder elements directly
1163 //
1165 for (zX = DECODE1; zX < DECODEN; zX++)
1166 {
1167 if (pP->streamsFromDecodes[zX] == z)
1168 {
1169 #ifdef NOAUDIOSHARE
1170 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1171 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1172 #else /* NOAUDIOSHARE */
1173 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1174 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1175 #endif /* NOAUDIOSHARE */
1176 }
1177 }
1179 return 0;
1180 } //PAF_ASOT_initFrame0
1182 // -----------------------------------------------------------------------------
1183 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1184 // AST Decoding Function - Reinitialization of Audio Frame
1185 //
1186 // Name: PAF_ASOT_initFrame1
1187 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1188 // zation of the Audio Frame(s) by loading of data values of a
1189 // time-varying nature.
1190 // From: audioStream1Task or equivalent
1191 // AST Parameter Function -> decodeInfo
1192 // AST Parameter Function -> decodeDecode
1193 // Uses: See code.
1194 // States: x
1195 // Return: 0.
1196 // Trace: None.
1197 //
1198 Int PAF_ASOT_initFrame1(
1199 const PAF_ASOT_Params *pP,
1200 const PAF_ASOT_Patchs *pQ,
1201 PAF_ASOT_Config *pAsotCfg,
1202 Int z,
1203 Int apply
1204 )
1205 {
1206 PAF_AST_Config *pAstCfg;
1208 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1210 //
1211 // Reinitialize audio frame elements:
1212 //
1213 // Channel Configurations during sys init = Unknown
1214 // " " during info or decode = None
1215 //
1216 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1217 //
1219 if (apply < 0)
1220 {
1221 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1222 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1223 }
1224 else
1225 {
1226 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1227 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1228 }
1230 if (apply < 1)
1231 {
1232 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1233 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1234 }
1236 return 0;
1237 } //PAF_ASOT_initFrame1