]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamOutInit.c
1669557c107be7d98a0150ddd77932fc809aa966
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutInit.c
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
77     
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 #if 0
130 // Create ASOT event
131 static Int asotCreateEvent(void);
132 #endif
134 // Create IO Buff & Phy framework components
135 static Int PAF_ASOT_ioCompCreate(
136     PAF_AST_IoOut *pIoOut, 
137     Int numOut, 
138     IHeap_Handle iHeapHandle
139 );
141 // Audio Stream Output Processing initialization function
142 Void taskAsopFxnInit(
143     const PAF_ASOT_Params *pP,
144     const PAF_ASOT_Patchs *pQ
147     PAF_ASOT_Config *pAsotCfg;      /* ASOT configuration pointer */
148     PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
149     PAF_AST_IoOut *pOut;
150     Int as;                         /* Audio Stream Number (1, 2, etc.) */
151     Int z;                          /* input/encode/stream/decode/output counter */
152     Int i;                          /* phase */
153     Int zMS;
154     Int status;
156     Log_info0("Enter taskAsopFxnInit()");
158     //
159     // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
160     //
161     if (!pP)
162     {
163         TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
164         LINNO_RPRT(TaskAsop, -1);
165         return;
166     }
168     if (!pQ)
169     {
170         TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
171         LINNO_RPRT(TaskAsop, -1);
172         return;
173     }
175     //
176     // Audio Stream Output Task Configuration (*pAsotCfg):
177     //
178     pAsotCfg = &gPAF_ASOT_config;       // initialize pointer to task configuration
179     pAsotCfg->taskHandle = Task_self(); // set task handle
180     pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
182     // Create ASOT event
183     status = astCreateEvent(&gAsotEvtHandle);
184     if (status < 0)
185     {
186         TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
187         return;
188     }
189     
190     /* Obtain Audio Stream Number (1, 2, etc.) */
191     as = pAstCfg->as;
192     TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
194     //
195     // Initialize message log trace and line number reporting
196     //
197     for (z=STREAM1; z < STREAMN; z++)
198     {
199         TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
200     }
201     LINNO_RPRT(TaskAsop, -1);
203     //
204     // Determine stream index
205     //
206     zMS = pAstCfg->masterStr;
208     // Initialize as per parametrized phases:
209     //
210     //   In standard form these are:
211     //      - Malloc: Memory Allocation
212     //      - Config: Configuration Initialization
213     //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
214     //      - Common: Common Memory Initialization
215     //      - AlgKey: Dec/Enc chain to Array Initialization
216     //      - Device: I/O Device Initialization
217     //      - Unused: (available)
218     //      - Unused: (available)
219     //
220     LINNO_RPRT(TaskAsop, -2);
221     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
222     {
223         Int linno;
224         if (pP->fxns->initPhase[i])
225         {
226             linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
227             if (linno)
228             {
229                 LINNO_RPRT(TaskAsop, linno);
230                 return;
231             }
232         }
233         else
234         {
235             TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
236         }
237         TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
238         LINNO_RPRT(TaskAsop, -i-3);
239     }
241     //
242     // End of Initialization -- display memory usage report.
243     //
244     if (pP->fxns->memStatusPrint)
245     {
246         pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
247             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
248             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
249     }
251     pOut = &pAsotCfg->pIoOut[zMS];
252     pOut->hMcaspChan = NULL;
253 } /* taskAsopFxnInit */
255 #if 0
256 // Create ASOT event object
257 static Int asotCreateEvent(void)
259     Error_Block eb;
260     
261     Error_init(&eb);
262     
263     // Default instance configuration params
264     asotEvt = Event_create(NULL, &eb);
265     if (asotEvt == NULL)
266     {
267         return -1; // error code
268     }
269     
270     return 0;
271 } /* asotCreateEvent */
272 #endif
274 // Create IO Buff & Phy framework components
275 static Int PAF_ASOT_ioCompCreate(
276     PAF_AST_IoOut *pIoOut, 
277     Int numOut, 
278     IHeap_Handle iHeapHandle)
280     int i, j, num_alloc;
281     lib_mem_rec_t   *mem_rec;
282     ioBuffHandle_t  ioBufHandle;
283     ioPhyHandle_t   ioPhyHandle;
284     Error_Block     eb;
286     for(i=0; i<numOut; i++)
287     {
288         // Create an I/O BUFF instance
289         // Obtain number of memory blocks required by I/O BUFF
290         num_alloc = ioBuffNumAlloc();
292         // Obtain requirements of each memory block
293         mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
294         if(ioBuffAlloc(mem_rec) != IOBUFF_NOERR) {
295             return __LINE__;
296         }
298         /* Allocate memory and create I/O BUFF instance */
299         for(j=0; j<num_alloc; j++) {
300             mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
301                                             (1<<mem_rec[j].alignment), &eb);
302         }
304         if(ioBuffCreate(&ioBufHandle, mem_rec) != IOBUFF_NOERR) {
305             return __LINE__;
306         }
308         pIoOut[i].hIoBuff = ioBufHandle;
310         free(mem_rec);
312         // Create an I/O PHY instance
313         // Obtain number of memory blocks required by I/O PHY
314         num_alloc = ioPhyNumAlloc();
316         // Obtain requirements of each memory block
317         mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
318         if(ioPhyAlloc(mem_rec) != IOBUFF_NOERR) {
319             return __LINE__;
320         }
322         /* Allocate memory and create I/O PHY instance */
323         for(j=0; j<num_alloc; j++) {
324             mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
325                                             (1<<mem_rec[j].alignment), &eb);
326         }
328         if(ioPhyCreate(&ioPhyHandle, mem_rec) != IOBUFF_NOERR) {
329             return __LINE__;
330         }
332         pIoOut[i].hIoPhy = ioPhyHandle;
334         free(mem_rec);
336     } // end of for loop
338     return 0;
339 } // PAF_ASOT_ioCompCreate
341 // -----------------------------------------------------------------------------
342 // AST Initialization Function - Memory Allocation
343 //
344 //   Name:      PAF_ASOT_initPhaseMalloc
345 //   Purpose:   Audio Stream Output Task Function for initialization of data pointers
346 //              by allocation of memory.
347 //   From:      audioStream1Task or equivalent
348 //   Uses:      See code.
349 //   States:    x
350 //   Return:    0 on success.
351 //              Source code line number on MEM_calloc failure.
352 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
353 //              * State information as per parent.
354 //              * Memory allocation errors.
355 //
357 Int PAF_ASOT_initPhaseMalloc(
358     const PAF_ASOT_Params *pP, 
359     const PAF_ASOT_Patchs *pQ, 
360     PAF_ASOT_Config *pAsotCfg
363     PAF_AST_Config *pAstCfg;
364     Int as;                     /* Audio Stream Number (1, 2, etc.) */
365     Int zMS, errLineNum;
366     Error_Block    eb;
367     //Int i;
369     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
370     as = pAstCfg->as;
371     zMS = pAstCfg->masterStr;
373     TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
375     // Initialize error block
376     Error_init(&eb); 
378     /* Stream memory */
379     if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
380     {
381         TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
382         SW_BREAKPOINT;
383         return __LINE__;
384     }
385     TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
386             STREAMN * sizeof (*pAstCfg->xStr),
387             HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
389     {
390         Int z;                          /* stream counter */
392         PAF_AudioFrame *fBuf;
394         if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
395         {
396             TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
397             SW_BREAKPOINT;
398             return __LINE__;
399         }
400         TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
401                 STREAMS * sizeof (*fBuf),
402                 HEAP_ID_INTERNAL, (IArg)fBuf);
404         for (z=STREAM1; z < STREAMN; z++)
405         {
406             pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
407             TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
408         }
409     }
411     /* Encode memory */
412     if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
413     {
414         TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
415         SW_BREAKPOINT;
416         return __LINE__;
417     }
418     TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
419             ENCODEN * sizeof (*pAstCfg->xEnc),
420             HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
422     /* Output memory */
423     if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
424     {
425         TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
426         SW_BREAKPOINT;
427         return __LINE__;
428     }
429     TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
430             OUTPUTN * sizeof (*pAstCfg->xOut),
431             HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
433     /* Output I/O data structure memory */
434     if (!(pAsotCfg->pIoOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAsotCfg->pIoOut), 4, &eb)))
435     {
436         TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
437         SW_BREAKPOINT;
438         return __LINE__;
439     }
440     TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAsotCfg->pIoOut) %d bytes from space %d at 0x%x.",
441                  OUTPUTN * sizeof (*pAsotCfg->pIoOut),
442                  HEAP_ID_INTERNAL, (IArg)pAsotCfg->pIoOut);
444     /* I/O components memory for output */
445     errLineNum = PAF_ASOT_ioCompCreate(pAsotCfg->pIoOut, OUTPUTN, (IHeap_Handle)HEAP_INTERNAL);
446     if(errLineNum)
447     {
448         SW_BREAKPOINT;
449         return errLineNum;
450     }
451     TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
452     return 0;
453 } //PAF_ASOT_initPhaseMalloc
455 // -----------------------------------------------------------------------------
456 // ASOT Initialization Function - Memory Initialization from Configuration
457 //
458 //   Name:      PAF_ASOT_initPhaseConfig
459 //   Purpose:   Audio Stream Output Task Function for initialization of data values
460 //              from parameters.
461 //   From:      audioStream1Task or equivalent
462 //   Uses:      See code.
463 //   States:    x
464 //   Return:    0 on success.
465 //              Other as per initFrame0 and initFrame1.
466 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
467 //              * State information as per parent.
468 //
469 Int PAF_ASOT_initPhaseConfig(
470     const PAF_ASOT_Params *pP, 
471     const PAF_ASOT_Patchs *pQ, 
472     PAF_ASOT_Config *pAsotCfg
475     PAF_AST_Config *pAstCfg;
476     Int as;                     /* Audio Stream Number (1, 2, etc.) */
477     Int z;                      /* input/encode/stream/decode/output counter */
478     Int zMS;
480     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
481     as = pAstCfg->as;
482     zMS = pAstCfg->masterStr;
484     TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
486     //
487     // Unspecified elements have been initialized to zero during alloc
488     //
490     for (z=STREAM1; z < STREAMN; z++) 
491     {
492         Int linno;
493         if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
494         {
495             return linno;           
496         }
497         if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
498         {
499             return linno;
500         }
501     }
503     for (z=ENCODE1; z < ENCODEN; z++) 
504     {
505         Int zO = pP->outputsFromEncodes[z];
506         Int zS = pP->streamsFromEncodes[z];
507         pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
508         pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
509         pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
510         pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
511         pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
512         pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
513         pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
514         pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
515     }
517     for (z=OUTPUT1; z < OUTPUTN; z++)
518     {
519         pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
520     }
522     TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
523     return 0;
524 } //PAF_ASOT_initPhaseConfig
526 // -----------------------------------------------------------------------------
527 // ASOT Initialization Function - ACP Algorithm Instantiation
528 //
529 //   Name:      PAF_ASOT_initPhaseAcpAlg
530 //   Purpose:   Audio Stream Input Task Function for initialization of ACP by
531 //              instantiation of the algorithm.
532 //   From:      audioStream1Task or equivalent
533 //   Uses:      See code.
534 //   States:    x
535 //   Return:    0 on success.
536 //              Source code line number on ACP Algorithm creation failure.
537 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
538 //              * State information as per parent.
539 //              * Memory allocation errors.
540 //
541 Int PAF_ASOT_initPhaseAcpAlg(
542     const PAF_ASOT_Params *pP, 
543     const PAF_ASOT_Patchs *pQ, 
544     PAF_ASOT_Config *pAsotCfg
547     PAF_AST_Config *pAstCfg;
548     Int as;                     /* Audio Stream Number (1, 2, etc.) */
549     Int z;                      /* input/encode/stream/decode/output counter */
550     Int betaPrimeOffset;
551     ACP_Handle acp;
552     Int zMS;
553     Int zS, zX;
555     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
556     as = pAstCfg->as;
557     zMS = pAstCfg->masterStr;
559     TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
561     ACP_MDS_init();
563     if (!(acp = (ACP_Handle )ACP_MDS_create(NULL))) 
564     {
565         TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
566         return __LINE__;
567     }
568     pAsotCfg->acp = acp;
570     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
571         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
573     for (z=ENCODE1; z < ENCODEN; z++) 
574     {
575         zS = pP->streamsFromEncodes[z];
576         acp->fxns->attach(acp, ACP_SERIES_STD,
577             STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
578             (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
579         acp->fxns->attach(acp, ACP_SERIES_STD,
580             STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
581             (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
582         /* Ignore errors, not reported. */
583     }
585     for (z=OUTPUT1; z < OUTPUTN; z++) 
586     {
587         zS = z;
588         for (zX = ENCODE1; zX < ENCODEN; zX++) 
589         {
590             if (pP->outputsFromEncodes[zX] == z) 
591             {
592                 zS = pP->streamsFromEncodes[zX];
593                 break;
594             }
595         }
596         acp->fxns->attach(acp, ACP_SERIES_STD,
597             STD_BETA_OB + betaPrimeOffset * (as-1+zS),
598             (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
599         /* Ignore errors, not reported. */
600     }
602     TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
604     return 0;
605 } //PAF_ASOT_initPhaseAcpAlg
607 // -----------------------------------------------------------------------------
608 // ASOT Initialization Function - Common Memory
609 //
610 //   Name:      PAF_ASOT_initPhaseCommon
611 //   Purpose:   Audio Stream Output Task Function for allocation of common memory.
612 //   From:      audioStream1Task or equivalent
613 //   Uses:      See code.
614 //   States:    x
615 //   Return:    0 on success.
616 //              Source code line number on PAF_ALG_alloc failure.
617 //              Source code line number on PAF_ALG_mallocMemory failure.
618 //              Source code line number on Decode Chain initialization failure.
619 //              Source code line number on ASP Chain initialization failure.
620 //              Source code line number on Encode Chain initialization failure.
621 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
622 //              * State information as per parent.
623 //              * Memory allocation errors.
624 //
625 Int PAF_ASOT_initPhaseCommon(
626     const PAF_ASOT_Params *pP, 
627     const PAF_ASOT_Patchs *pQ, 
628     PAF_ASOT_Config *pAsotCfg
631     PAF_AST_Config *pAstCfg;
632     Int as;                     /* Audio Stream Number (1, 2, etc.) */
633     Int z;                      /* stream counter */
634     Int g;                      /* gear */
635     ACP_Handle acp;
636     PAF_IALG_Config pafAlgConfig;
637     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
638    
639     acp = pAsotCfg->acp;
640     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
641     as = pAstCfg->as;
643     TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
645     //
646     // Determine memory needs and instantiate algorithms across audio streams
647     //
648     TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
649     PAF_ALG_setup(&pafAlgConfig, 
650         HEAP_ID_INTERNAL,                 HEAP_INTERNAL, 
651         HEAP_ID_INTERNAL1,                HEAP_INTERNAL1, 
652         HEAP_ID_EXTERNAL,                 HEAP_EXTERNAL, 
653         HEAP_ID_INTERNAL1_SHM,            HEAP_INTERNAL1_SHM, 
654         HEAP_ID_EXTERNAL_SHM,             HEAP_EXTERNAL_SHM, 
655         HEAP_ID_EXTERNAL_NONCACHED_SHM,   HEAP_EXTERNAL_NONCACHED_SHM,
656         HEAP_CLEAR);
658     if (pP->fxns->headerPrint)
659     {
660         pP->fxns->headerPrint();        
661     }
663     for (z = STREAM1; z < STREAMN; z++) 
664     {
665         //Int zD, zE, zX;
666         Int zE, zX;
668         TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
670         //
671         // Determine common memory needs for:
672         //  (1) ASP Algorithms
673         //  (2) Encode Algorithms
674         //  (3) Logical Output drivers
675         //
676         PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
678         zE = -1;
679         for (zX = ENCODE1; zX < ENCODEN; zX++) 
680         {
681             if (pP->streamsFromEncodes[zX] == z) 
682             {
683                 zE = zX;
684                 break;
685             }
686         }
688         TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
689         if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z])) 
690         {
691             TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
692             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
693             SW_BREAKPOINT;
694             return __LINE__;
695         }
696         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
697         if (pP->fxns->allocPrint)
698         {
699             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
700         }
702         if (zE >= 0) 
703         {
704             TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
705             if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z])) 
706             {
707                 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
708                 SW_BREAKPOINT;
709                 return __LINE__;
710             }
711             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
712             if (pP->fxns->allocPrint)
713             {
714                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
715             }
716         }
718         //
719         // Determine common memory needs of Logical IO drivers
720         //
722         if (OUTPUT1 <= z && z < OUTPUTN)
723         {
724             TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
725             if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
726             {
727                 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
728                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
729                 SW_BREAKPOINT;
730                 return __LINE__;
731             }
732             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
733             if (pP->fxns->allocPrint)
734             {
735                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
736             }
737         }
738     }
739     {
740         // Changes made to share scratch between zones
741         // Assume maximum 3 zones and scratch common memory is at offset 0;
742         int max=0;
743         for (z=STREAM1; z<STREAMN; z++)
744         {
745             if (max < common[z][0].size)
746             {
747                 max = common[z][0].size;
748             }
749         }
750         common[STREAM1][0].size=max;
751         for (z=STREAM1+1; z<STREAMN; z++)
752         {
753             common[z][0].size = 0;            
754         }
755     }
756         
757     //
758     // Allocate common memory for:
759     //  (1) ASP Algorithms
760     //  (2) Encode Algorithms
761     //  (3) Logical Output drivers
762     //
763     for (z = STREAM1; z < STREAMN; z++) 
764     {
765         //Int zD, zE, zX;
766         Int zE, zX;
768         TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
769         if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
770         {
771             TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
772             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
773             SW_BREAKPOINT;
774             return __LINE__;
775         }
776         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
777         // share zone0 scratch with all zones 
778         common[z][0].base = common[0][0].base;
779         if (pP->fxns->commonPrint)
780         {
781             pP->fxns->commonPrint(common[z], &pafAlgConfig);
782         }
784         zE = -1;
785         for (zX = ENCODE1; zX < ENCODEN; zX++) 
786         {
787             if (pP->streamsFromEncodes[zX] == z) 
788             {
789                 zE = zX;
790                 break;
791             }
792         }
794         pAstCfg->xStr[z].aspChain[0] = NULL;
795         for (g=0; g < GEARS; g++) 
796         {
797             PAF_ASP_Chain *chain;
798             TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
799             chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
800                 HEAP_INTERNAL, as+z, acp, &trace,
801                 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
802             if (!chain) 
803             {
804                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
805                 return __LINE__;
806             }
807             else
808             {
809                 pAstCfg->xStr[z].aspChain[g] = chain;
810             }
811         }
813         if (zE >= 0) 
814         {
815             PAF_ASP_Chain *chain;
816             TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
817             chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
818                 HEAP_INTERNAL, as+z, acp, &trace,
819                 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
820             if (!chain) 
821             {
822                 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
823                 return __LINE__;
824             }
825         }
827         //
828         // Allocate non-common memories for Logical IO drivers
829         //    Since these structures are used at run-time we allocate from external memory
830         if (OUTPUT1 <= z && z < OUTPUTN) 
831         {
832             PAF_ASP_Chain *chain;
833             TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
834                            as+z, z);
835             chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
836                         HEAP_EXTERNAL, as+z, acp, &trace,
837                         outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
838             if (!chain) 
839             {
840                 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
841                 return __LINE__;
842             }
843         }
844     }
845     TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
847     return 0;
848 } //PAF_ASOT_initPhaseCommon
850 // -----------------------------------------------------------------------------
851 // ASOT Initialization Function - Algorithm Keys
852 //
853 //   Name:      PAF_ASOT_initPhaseAlgKey
854 //   Purpose:   Audio Stream Output Task Function for initialization of data values
855 //              from parameters for Algorithm Keys.
856 //   From:      audioStream1Task or equivalent
857 //   Uses:      See code.
858 //   States:    x
859 //   Return:    0.
860 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
861 //              * State information as per parent.
862 //
863 // .............................................................................
864 Int PAF_ASOT_initPhaseAlgKey(
865     const PAF_ASOT_Params *pP, 
866     const PAF_ASOT_Patchs *pQ, 
867     PAF_ASOT_Config *pAsotCfg
870     PAF_AST_Config *pAstCfg;
871     Int as;                     /* Audio Stream Number (1, 2, etc.) */
872     Int z;                      /* decode/encode counter */
873     Int s;                      /* key number */
874     PAF_ASP_Link *that;
876     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
877     as = pAstCfg->as;
878     (void)as; // clear compiler warning in case not used with tracing disabled
880     TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
882     for (z=ENCODE1; z < ENCODEN; z++) 
883     {
884         for (s=0; s < pP->pEncAlgKey->length; s++) 
885         {
886             if ((pP->pEncAlgKey->code[s].full != 0) && 
887                 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
888             {
889                 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
890             }
891             /* Cast in interface, for now --Kurt */
892             else
893             {
894                 pAstCfg->xEnc[z].encAlg[s] = NULL;                
895             }
896         }
897     }
899     return 0;
900 } //PAF_ASOT_initPhaseAlgKey
902 // -----------------------------------------------------------------------------
903 // ASOT Initialization Function - I/O Devices
904 //
905 //   Name:      PAF_ASOT_initPhaseDevice
906 //   Purpose:   Audio Stream Output Task Function for initialization of I/O Devices.
907 //   From:      audioStream1Task or equivalent
908 //   Uses:      See code.
909 //   States:    x
910 //   Return:    0 on success.
911 //              Source code line number on device allocation failure.
912 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
913 //              * State information as per parent.
914 //              * Memory allocation errors.
915 //
916 Int PAF_ASOT_initPhaseDevice(
917     const PAF_ASOT_Params *pP, 
918     const PAF_ASOT_Patchs *pQ, 
919     PAF_ASOT_Config *pAsotCfg
922     PAF_AST_Config *pAstCfg;
923     Int as;                     /* Audio Stream Number (1, 2, etc.) */
924     Int z;                      /* input/output counter */
925     PAF_SIO_IALG_Obj    *pObj;
926     PAF_SIO_IALG_Config *pAlgConfig;
927     PAF_IALG_Config pafAlgConfig;
929     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
930     as = pAstCfg->as;
931     (void)as; // clear compiler warning in case not used with tracing disabled
933     TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
935     if(pP->fxns->bufMemPrint)
936     {
937         PAF_ALG_setup (&pafAlgConfig, 
938             HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
939             HEAP_ID_INTERNAL1,              HEAP_INTERNAL1,
940             HEAP_ID_EXTERNAL,               HEAP_EXTERNAL,
941             HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM,
942             HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM,
943             HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
944             HEAP_CLEAR);
945         TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
946     }
947     
948     for (z=OUTPUT1; z < OUTPUTN; z++) 
949     {
950         PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
952         pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
953         pAlgConfig = &pObj->config;
955         pAstCfg->xOut[z].hTxSio = NULL;
956         pConfig->base.pVoid     = pAlgConfig->pMemRec[0].base;
957         pConfig->pntr.pVoid     = pAlgConfig->pMemRec[0].base;
958         pConfig->head.pVoid     = pAlgConfig->pMemRec[0].base;
959         pConfig->allocation     = pAlgConfig->pMemRec[0].size;
960         pConfig->sizeofElement  = 3;
961         pConfig->precision      = 24;
962         if(pP->fxns->bufMemPrint)
963         {
964             pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
965         }
966     }
967     TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
969     return 0;
970 } //PAF_ASOT_initPhaseDevice
972 // -----------------------------------------------------------------------------
973 // ASOT Initialization Function Helper - Initialization of Audio Frame
974 //
975 //   Name:      PAF_ASOT_initFrame0
976 //   Purpose:   Audio Stream Output Task Function for initialization of the Audio
977 //              Frame(s) by memory allocation and loading of data pointers
978 //              and values.
979 //   From:      AST Parameter Function -> decodeInfo
980 //   Uses:      See code.
981 //   States:    x
982 //   Return:    0 on success.
983 //              Source code line number on MEM_calloc failure.
984 //              Source code line number on unsupported option.
985 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
986 //              * Memory allocation errors.
987 //              * Unsupported option errors.
988 //
990 // MID 314
991 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
992 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
994 Int PAF_ASOT_initFrame0(
995     const PAF_ASOT_Params *pP, 
996     const PAF_ASOT_Patchs *pQ, 
997     PAF_ASOT_Config *pAsotCfg, 
998     Int z
1001     PAF_AST_Config *pAstCfg;
1002     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1003     Int ch;
1004     //Int aLen;
1005     Int aLen_int=0,aLen_ext=0;
1006     Int aSize = sizeof(PAF_AudioData);
1007     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1008     Int maxFrameLength = pP->maxFramelength;
1009     Int zX;
1010     PAF_AudioData *aBuf_int=NULL;
1011     PAF_AudioData *aBuf_ext=NULL;
1012     XDAS_UInt8 *metadataBuf;
1013     char i;
1014     Error_Block    eb;
1016     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1017     as = pAstCfg->as;
1019     // Initialize error block
1020     Error_init(&eb); 
1022     // Compute maximum framelength (needed for ARC support)
1023     maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1024     //aLen = numchan[z] * maxFrameLength;
1025     for (i=0; i < numchan[z]; i++)
1026     {
1027         if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1028         {
1029             aLen_int += maxFrameLength;
1030         }
1031         else
1032         {
1033             aLen_ext += maxFrameLength;
1034         }
1035     }
1037     //
1038     // Initialize audio frame elements directly
1039     //
1040     pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1041     pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1042 ///    pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1043     pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1044     pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1045     pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1046     pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1048     //
1049     // Allocate memory for and initialize pointers to audio data buffers
1050     //
1051     //   The NUMCHANMASK is used to identify the channels for which data
1052     //   buffers can be allocated. Using this mask and switch statement
1053     //   rather than some other construct allows efficient code generation,
1054     //   providing just the code necessary (with significant savings).
1055     //
1056     if (pP->fxns->bufMemPrint)
1057     {
1058         pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1059         pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1060     }
1062     TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1063     
1064     if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1065     {
1066         if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1067         {
1068             TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1069             TRACE_TERSE2("  maxFrameLength: %d.  aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1070             SW_BREAKPOINT;
1071             return __LINE__;
1072         }
1073     }
1074         
1075     if (aLen_ext*aSize!=0)
1076     {
1077         if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1078         {
1079             TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1080             TRACE_TERSE2("  maxFrameLength: %d.  aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1081             SW_BREAKPOINT;
1082             return __LINE__;
1083         }
1084     }
1085     
1086     TRACE_TERSE3("  maxFrameLength: %d.  aLen_int*aSize: %d.  aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1087     TRACE_TERSE3("  maxFrameLength: %d.  aLen_ext*aSize: %d.  aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1089     TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1090     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1091     {
1092         TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1093         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1094         SW_BREAKPOINT;
1095         return __LINE__;
1096     }
1098     {
1099         Int i;
1101 #pragma UNROLL(1)
1102         for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1103         {
1104             pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1105         }
1106     }
1108     // MID 314
1109     if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1110     {
1111         TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1112         return __LINE__;
1113     }
1114     else 
1115     {
1116         Int j = 0;
1117         Int k = 0;
1118         TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1119         for(i=0;i<numchan[z];i++)
1120         {
1121             char chan = AFChanPtrMap[numchan[z]][i];
1122             if(chan != -1)
1123             {
1124                 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1125                 {
1126                     pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1127                     j++;
1128                 }
1129                 else
1130                 {        
1131                     pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1132                     k++;
1133                 }    
1134                 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1135                 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1136             }
1137         }
1138     }
1140     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1141     {
1142         if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1143         {
1144             pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1145         }
1146     }
1148     //
1149     // Initialize meta data elements
1150     //
1151     pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1152     pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1153     pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1154     pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1155     pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1156     for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1157     {
1158         pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1159         pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1160         pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1161     }
1163     //
1164     // Initialize decoder elements directly
1165     //
1167     for (zX = DECODE1; zX < DECODEN; zX++) 
1168     {
1169         if (pP->streamsFromDecodes[zX] == z) 
1170         {
1171 #ifdef NOAUDIOSHARE
1172             pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1173             pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1174 #else /* NOAUDIOSHARE */
1175             pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1176             pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1177 #endif /* NOAUDIOSHARE */
1178         }
1179     }
1181     return 0;
1182 } //PAF_ASOT_initFrame0
1184 // -----------------------------------------------------------------------------
1185 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1186 // AST Decoding Function              - Reinitialization of Audio Frame
1187 //
1188 //   Name:      PAF_ASOT_initFrame1
1189 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1190 //              zation of the Audio Frame(s) by loading of data values of a
1191 //              time-varying nature.
1192 //   From:      audioStream1Task or equivalent
1193 //              AST Parameter Function -> decodeInfo
1194 //              AST Parameter Function -> decodeDecode
1195 //   Uses:      See code.
1196 //   States:    x
1197 //   Return:    0.
1198 //   Trace:     None.
1199 //
1200 Int PAF_ASOT_initFrame1(
1201     const PAF_ASOT_Params *pP, 
1202     const PAF_ASOT_Patchs *pQ, 
1203     PAF_ASOT_Config *pAsotCfg, 
1204     Int z, 
1205     Int apply
1208     PAF_AST_Config *pAstCfg;
1210     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1212     //
1213     // Reinitialize audio frame elements:
1214     //
1215     //   Channel Configurations during sys init                 = Unknown
1216     //      "          "        during info or decode           = None
1217     //
1218     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1219     //
1221     if (apply < 0) 
1222     {
1223         pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1224         pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1225     }
1226     else 
1227     {
1228         pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1229         pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1230     }
1232     if (apply < 1) 
1233     {
1234         pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1235         pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1236     }
1238     return 0;
1239 } //PAF_ASOT_initFrame1