]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_arm/framework/audioStreamDecodeProc.c
Merge branch 'dev_pasdk_pp_pasdk302' of ssh://git@bitbucket.itg.ti.com/pasdk/pasdk_sr...
[processor-sdk/performance-audio-sr.git] / pasdk / test_arm / framework / audioStreamDecodeProc.c
2 /*
3 Copyright (c) 2017, 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  *  ======== audioStreamDecodeProc.c ========
38  */
40 #include <xdc/cfg/global.h>
41 #include <xdc/runtime/Error.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/BIOS.h>
45 #include <ti/sysbios/hal/Cache.h>
46 #include <ti/sysbios/knl/Task.h>
47 #include <ti/ipc/Ipc.h>
48 #include <ti/ipc/MessageQ.h>
49 #include <ti/ipc/MultiProc.h>
51 #include <acp_mds.h>
52 #include <pcm.h>
53 #include "audioStreamProc_params.h"
54 #include "audioStreamProc_patchs.h"
55 #include "audioStreamProc_config.h"
57 #include "common.h"
58 #include "aspMsg_common.h"
59 #include "aspMsg_slave.h"
60 #include "aspDecOpCircBuf_slave.h"
61 #include "audioStreamProc_common.h"
62 #include "audioStreamDecodeProc.h"
63 #include "statusOp_common.h"
65 #include "pfp/pfp.h"
66 #include "pfp_app.h"        /* contains all PFP ID's */
68 // FL: debug
69 #include "dbgCapAf.h"
70 #include "dbgDib.h"
71 #include "evmc66x_gpio_dbg.h"
73 //
74 // Decoder Definitions
75 //
76 #define decLinkInit pQ->i_decLinkInit
78 #define __TASK_NAME__  "TaskAsdp"
80 extern struct {
81     Int size;
82     IALG_Status *pStatus[512];
83 } IACP_STD_BETA_TABLE;
85 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
86 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
88 LINNO_DEFN(TaskAsdp); /* Line number macros */
89 ERRNO_DEFN(TaskAsdp); /* Error number macros */
91 // ASDT configuration
92 PAF_ASDT_Config gPAF_ASDT_config 
93 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
94     NULL,               // taskHandle
95     NULL,               // acp
96     {NULL, NULL},       // decOpCircBufCtl
97     &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
98 };
100 PAF_AudioFrame *gpDecAudioFrame=NULL;
101 PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
102 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
103 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
105 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
106 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
107 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
108 UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
109 UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
110 UInt32 gSlaveCbResetCnt         =0; // slave circular buffer reset count
112 // Global debug counters */
113 UInt32 gSlaveStartErrCnt        =0;
114 UInt32 gSlaveStartCnt           =0;
115 UInt32 gSlaveSourceSelectCnt    =0;
116 UInt32 gSlaveExitCnt            =0;
117 UInt32 gSlaveDecExitCnt         =0;
118 UInt32 gSlaveDecControlCnt      =0;
119 UInt32 gSlaveDecActivateCnt     =0;
120 UInt32 gSlaveDecResetCnt        =0;
121 UInt32 gSlaveDecInfoCnt         =0;
122 UInt32 gSlaveDecDecodeCnt       =0;
123 UInt32 gSlaveDecDeactivateCnt   =0;
126 //#define CAPTURE_DECODER_OUTSAMPLES_PP
127 #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
129 #define CAP_FRAME_MAX            2000
130 Uint32 tempCap_frameCnt = 0;
131 int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
132 #endif
134 /*
135  *  ======== taskAsdpFxn ========
136  *  Audio Stream Decode Processing task function
137  */
138 Void taskAsdpFxn(
139 //    Int betaPrimeValue, // FL: revisit
140     const PAF_ASDT_Params *pP,
141     const PAF_ASDT_Patchs *pQ
144     PAF_ASDT_Config *pAsdtCfg;      /* ASDT configuration pointer */
145     PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
146     Int as;                         /* Audio Stream Number (1, 2, etc.) */
147     Int z;                          /* input/encode/stream/decode/output counter */
148     Int i;                          /* phase */
149     Int zMD, zMS;
150     Bool done;
151     Bool decDone;
152     ALG_Handle alg[DECODEN_MAX];
153     ASP_Slave_Cmd slaveCmd;
154     Int sourceSelect;
155     DEC_Handle dec;
156     IALG_Cmd decCtrlCmd;            // decoder control command
157     Int decCtrlRet;                 // decoder control return
158     Int errno;                      /* error number */
159     Int size;
160     Int argIdx;
161     // Decoder output circular buffer
162     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
163     PAF_AudioFrame *pAfWrt;
164     Int cbErrno;    
165     // Messaging
166     PAF_InpBufConfig *pIpBufConfig;
167     ASP_Msg *pAspMsg;
168     MessageQ_QueueId queId;
169     Int status;
170     Int zI;
171     Int bufEnd, wrapSize, currentBufSize, chunkSize;
172     Int8 temp8;
174     Log_info0("Enter taskAsdpFxn()");
175     
176     
177     //
178     // Audio Framework Parameters & Patch (*pP, *pQ):
179     //
180     if (!pP) 
181     {
182         TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
183         LINNO_RPRT(TaskAsdp, -1);
184         return;
185     }
187     if (!pQ) 
188     {
189         TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
190         LINNO_RPRT(TaskAsdp, -1);
191         return;
192     }    
194     //
195     // Audio Stream Decode Task Configuration (*pAsdtCfg):
196     //
197     pAsdtCfg = &gPAF_ASDT_config;           // initialize pointer to task configuration
198     pAsdtCfg->taskHandle = Task_self();     // set task handle
199     pAstCfg = pAsdtCfg->pAstCfg;            // get pointer to AST common (shared) configuration 
200     pCbCtl = &pAsdtCfg->decOpCircBufCtl;    // get pointer to circular buffer control
202     // wait for initialization message from master
203     do {
204         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
205         //TRACE_TERSE1("Rx ASP message: status=%d", status);
206     //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
207     } while (status != MessageQ_S_SUCCESS);
208     if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
209         (pAspMsg->cmd != ASP_SLAVE_START))
210     {
211         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
212         SW_BREAKPOINT;
213     }
214     hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
215     gSlaveStartCnt++;
216     TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
218     // invalidate AST shared configuration
219     Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
220     Cache_wait();
221     
222     // (***) FL: revisit
223     // invalidate Dec configuration for all Decoder zones
224     Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
225     Cache_wait();
227     // (***) FL: revisit
228     // invalidate Beta Table status pointers
229     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
230     Cache_wait();
232     /* Obtain Audio Stream Number (1, 2, etc.) */
233     as = pAstCfg->as;
234     TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
235     
236     //
237     // Initialize message log trace and line number reporting
238     //
239     for (z=STREAM1; z < STREAMN; z++)
240     {
241         TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
242     }
243     LINNO_RPRT(TaskAsdp, -1);
245     // Get decoder and stream index associated with the master input
246     zMD = pAstCfg->masterDec;
247     zMS = pAstCfg->masterStr;
249     // 
250     // Initialize per parameterized phases.
251     //   - Malloc: Memory Allocation
252     //   - Config: Configuration Initialization
253     //   - AcpAlg: ACP Algorithm Initialization and Local Attachment
254     //   - Common: Common Algorithm Initialization
255     //   - AlgKey: Dec/Enc chain to Array Initialization
256     //   - Unused: (available)
257     //   - Unused: (available)
258     //   - Unused: (available)
259     //
260     LINNO_RPRT(TaskAsdp, -2);
261     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
262     {
263         Int linno;
264         if (pP->fxns->initPhase[i])
265         {
266             if ((linno = pP->fxns->initPhase[i](pP, pQ, pAsdtCfg)))
267             {
268                 LINNO_RPRT(TaskAsdp, linno);
269                 return;
270             }
271         }
272         else 
273         {
274             TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
275         }
276         TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
277         LINNO_RPRT(TaskAsdp, -i-3);
278     }
279       
280 #ifdef NON_CACHE_STATUS
281     //
282     // init Status structure Gate
283     //
284     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
285     {
286         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DEC);
287     }
288     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
289     {
290         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_DDP);
291     }
292     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
293     {
294         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_PCM);
295     }
296     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
297     {
298         TRACE_TERSE1("TaskAsdp: Gate Index %d:initialization status GateMP Fail.", GATEMP_INDEX_THD);
299     }
300 #endif
302     //
303     // End of Initialization -- final memory usage report.
304     //
305     if (pP->fxns->memStatusPrint)
306     {
307         pP->fxns->memStatusPrint("ASDT MEMSTAT REPORT",
308             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
309             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
310     }
311     
312     // (***) FL: revisit
313     // write back Status structure addresses for Beta Units initialized on Slave
314     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
315     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
316     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
317     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
318     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
319     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
320     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
321     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DTSUHDA]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
322     Cache_wait();
323     
324     // (***) FL: revisit
325     // write back Status structures for Beta Units initialized on Slave
326    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
327     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
328     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
329     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
330     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
331     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
332     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
333     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
334     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
335     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
336     Cache_wait();
338     // (***) FL: revisit
339     // write back Dec configuration
340     Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
341     Cache_wait();*/
342     
343     // Send initialization complete message to master
344     queId = MessageQ_getReplyQueue(pAspMsg);
345     pAspMsg->procId = hAspMsgSlave->slaveProcId;
346     pAspMsg->cmd = ASP_MASTER_START_DONE;
347     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
348     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
349     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
350     if (status != MessageQ_S_SUCCESS)
351     {
352         SW_BREAKPOINT;
353     }
355     done = FALSE;
356     while (done==FALSE)
357     {
358         // wait for source select message from master
359         do {
360             status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
361         } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
362         if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
363             (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
364         {
365             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
366             SW_BREAKPOINT;
367         }            
368         hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
369         sourceSelect = *(Int32 *)&pAspMsg->buf[0];
370         TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
371         TRACE_MSG1("sourceSelect=%d.", sourceSelect);
372         // send source select complete message to master
373         queId = MessageQ_getReplyQueue(pAspMsg);
374         pAspMsg->procId = hAspMsgSlave->slaveProcId;
375         pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
376         pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
377         gSlaveSourceSelectCnt++;
378         TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
379         MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
380         
381         for (z=DECODE1; z < DECODEN; z++)
382         {
383             alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
384         }
385         alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
387         // FL: debug, reset IB capture buffer
388         //capIbReset();
389         //Log_info0("capIbReset()");
390         // FL: debug, reset audio frame capture buffer
391         //capAfReset();
392         
393         decDone = FALSE;
394         while (decDone==FALSE)
395         {
396             // wait for received message from master
397             do {
398                 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
399             } while (status < 0);
400             if (pAspMsg->procId != hAspMsgSlave->masterProcId)
401             {
402                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
403                 SW_BREAKPOINT;
404             }
405             hAspMsgSlave->masterMessageId = pAspMsg->messageId; 
406             slaveCmd = pAspMsg->cmd;
407             TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
409             switch (slaveCmd)
410             {
411                 case ASP_SLAVE_NULL:
412                 case ASP_SLAVE_START:
413                     gSlaveStartErrCnt++;
414                     TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
415                     
416                     break;
417                     
418                 case ASP_SLAVE_EXIT:
419                     gSlaveExitCnt++;
420                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
421                     
422                     decDone = TRUE;
423                     done = TRUE;
424                     break;
425                     
426                 case ASP_SLAVE_DEC_EXIT:
427                     gSlaveDecExitCnt++;
428                     TRACE_TERSE1("slaveCmd=%d", slaveCmd);
429                     
430                     // send dec exit complete message to master
431                     queId = MessageQ_getReplyQueue(pAspMsg);
432                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
433                     pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
434                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
435                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
436                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
437                     if (status != MessageQ_S_SUCCESS)
438                     {
439                         SW_BREAKPOINT;
440                     }
441                     
442                     decDone=TRUE;
443                     break;
444                     
445                 case ASP_SLAVE_DEC_CONTROL:
446                     gSlaveDecControlCnt++;
447                     // simulate dec control load
448                     //simLoad(DEC_CONTROL_LOAD);
449                     
450                     argIdx = 0; // get decIdx
451                     z = *(Int32 *)&pAspMsg->buf[argIdx];
452                     argIdx += sizeof(Int32);
453                     decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
454                     TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
455                     
456                     decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
458                     // send dec control complete message to master
459                     queId = MessageQ_getReplyQueue(pAspMsg);
460                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
461                     pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
462                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
463                     argIdx = 0; // set decCtrlRet
464                     *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
465                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
466                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
467                     if (status != MessageQ_S_SUCCESS)
468                     {
469                         SW_BREAKPOINT;
470                     }
472                     break;
473                     
474                 case ASP_SLAVE_DEC_ACTIVATE:
475                     gSlaveDecActivateCnt++;
476                     // simulate dec activate load
477                     //simLoad(DEC_ACTIVATE_LOAD);
478                     
479                     // (***) FL: revisit
480                     // invalidate Status structures for shared Beta Units
481                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
482                     //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
483                     /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
484                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
485                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
486                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
487                     Cache_wait();*/
488                     
489                     argIdx = 0; // get decIdx
490                     z = *(Int32 *)&pAspMsg->buf[argIdx];
491                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
492                     
493                     // invalidate Dec configuration
494                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
495                     Cache_wait();
496                     
497                     if (alg[z]->fxns->algActivate)
498                     {
499                         alg[z]->fxns->algActivate(alg[z]);
500                     }
502                     // Start writes to circular buffer
503                     //pCb = &pAstCfg->xDecOpCb[z];
504                     cbErrno = cbWriteStart(pCbCtl, z);
505                     if (cbErrno < 0)
506                     {
507                         SW_BREAKPOINT;
508                     }
509                     gCbWrtAfErrCnt=0;       // reset write circular buffer error count
510                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
511                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
512                     gSlaveCbResetCnt=0;     // reset slave circular buffer reset count
513                     // FL: debug, log circular buffer control variables
514                     cbLog(pCbCtl, z, 1, "cbWriteStart");
515                     
516                     // Reset audio frame
517                     resetAf(pP, z, sourceSelect);
518                     
519                     // send dec activate complete message to master
520                     queId = MessageQ_getReplyQueue(pAspMsg);
521                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
522                     pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
523                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
524                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
525                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
526                     if (status != MessageQ_S_SUCCESS)
527                     {
528                         SW_BREAKPOINT;
529                     }
530                    
531                     break;
532                     
533                 case ASP_SLAVE_DEC_RESET:
534                     gSlaveDecResetCnt++;
535                     // simulate dec reset load
536                     //simLoad(DEC_RESET_LOAD);
537                     
538                     argIdx = 0; // get decIdx
539                     z = *(Int32 *)&pAspMsg->buf[argIdx];
540                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
541                     
542                     dec = (DEC_Handle)alg[z];
543                     errno = 0;
544                     if (dec->fxns->reset)
545                     {
546                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
547                     }
549                     // write back Dec configuration
550                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
551                     Cache_wait();            
553                     // (***) FL: revisit
554                     // write back Status structures for shared Beta Units
555                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
556                     //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
557                    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
558                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
559                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
560                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
561                     Cache_wait();*/
562                     
563                     // send dec reset complete message to master
564                     queId = MessageQ_getReplyQueue(pAspMsg);
565                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
566                     pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
567                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
568                     argIdx = 0; // set decErrno
569                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
570                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
571                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
572                     if (status != MessageQ_S_SUCCESS)
573                     {
574                         SW_BREAKPOINT;
575                     }
577                     break;
578                     
579                 case ASP_SLAVE_DEC_INFO:
580                     gSlaveDecInfoCnt++;
581                     // simulate dec info load
582                     //simLoad(DEC_INFO_LOAD);
583                     
584                     argIdx = 0; // get decIdx
585                     z = *(Int32 *)&pAspMsg->buf[argIdx];
586                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
587                     // Get input associated w/ decoder
588                     zI = pP->inputsFromDecodes[z];
590                     // (***) FL: revisit
591                     // invalidate Inp configuration
592                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
593                     Cache_wait();
594                     // invalidate input data
595                     pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
596                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
597                     if (sourceSelect == PAF_SOURCE_PCM)
598                     {
599                         size *= pIpBufConfig->stride;
600                     }
602                     bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
603                     currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
604                     if (currentBufSize >= size)
605                     {
606                         chunkSize = size;
607                     }
608                     else
609                     {
610                         chunkSize = currentBufSize;
611                     }
612                     wrapSize = size - chunkSize;
613                     // invalidate input data
614                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
615                     // invalidate Dec configuration
616                     TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
617                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
618                     // status for selected decoder should be invalidated
619                     Cache_wait();
621                     /* Circular buffer wrap condition*/
622                     //if(((Int) pIpBufConfig->head.pVoid + size)  > bufEnd)
623                     if(wrapSize > 0)
624                     {
625                         // invalidate input data
626                         Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
627                         TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
628                         // status for selected decoder should be invalidated
629                         Cache_wait();
630                     }
631                     /* Circular buffer wrap condition */
633                     dec = (DEC_Handle)alg[z];
634                     errno = 0;
635                     if (dec->fxns->info)
636                     {
637                         pfpBegin(PFP_ID_ASDT_1, pAsdtCfg->taskHandle);
638                         errno = dec->fxns->info(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
639                         pfpEnd(PFP_ID_ASDT_1, PFP_FINISH_MEAS);
640                     }
641                     
642                     // write back Dec configuration
643                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
644                     Cache_wait();            
645                     
646 #ifdef NON_CACHE_STATUS
647                     statusOp_read(&(temp8),
648                                   &(pAstCfg->xDec[z].decodeStatus.mode),
649                                   sizeof(Int8),
650                                   GATEMP_INDEX_DEC);
651                     // Re-initialize audio frame if decoder is disabled or
652                     // doesn't have a valid input
653                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
654                     {
655                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
656                     }
657 #else
658                     // Re-initialize audio frame if decoder is disabled or
659                     // doesn't have a valid input
660                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
661                     {
662                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
663                     }
664 #endif
666                     // send dec info complete message to master
667                     queId = MessageQ_getReplyQueue(pAspMsg);
668                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
669                     pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
670                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
671                     argIdx = 0; // set decErrno
672                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
673                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
674                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
675                     if (status != MessageQ_S_SUCCESS)
676                     {
677                         SW_BREAKPOINT;
678                     }
679                     
680                     break;
681                     
682                 case ASP_SLAVE_DEC_DECODE:
683                     gSlaveDecDecodeCnt++;
684                     // simulate dec info load
685                     //simLoad(DEC_DECODE_LOAD);
686                     
687                     argIdx = 0; // get decIdx
688                     z = *(Int32 *)&pAspMsg->buf[argIdx];
689                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
690                     // Get input associated w/ decoder
691                     zI = pP->inputsFromDecodes[z];
692                     
693                     // Reset AF samsiz
694                     resetAfSamsiz(z);
695                     
696                     // invalidate Dec configuration
697                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
698                     Cache_wait();
699                     //TRACE_TERSE0("Dec:cache wb done");
700             
701                     dec = (DEC_Handle)alg[z];
702                     //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
704                     errno = 0;
705                     cbErrno = 0;
706                     if (dec->fxns->decode)
707                     {
708                         // FL: debug, capture input buffer
709                         //capIb(pAstCfg->xInp[z].pInpBuf);
710                     
711                         pfpBegin(PFP_ID_ASDT_2, pAsdtCfg->taskHandle);
712                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
713                         pfpEnd(PFP_ID_ASDT_2, PFP_FINISH_MEAS);
714                         if (errno < 0)
715                         {
716                             //SW_BREAKPOINT;
717                         }
718                         TRACE_TERSE0("Dec:decode done");
719                         
720                         // copy decoder output to decoder output circular buffers
721                         //pCb = &pAstCfg->xDecOpCb[z];
722                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
723                         
724                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
725                         TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
726                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
727                         
728                         // FL: debug, capture audio frame
729                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
730                         //{
731                         //    Log_info0("capAfWrite() error");
732                         //}                        
734                         #ifdef CAPTURE_DECODER_OUTSAMPLES_PP
736                         if (tempCap_frameCnt < CAP_FRAME_MAX)
737                         {
738                             tempCap_decSampleOut[tempCap_frameCnt] = pAfWrt->sampleCount;
739                             tempCap_frameCnt++;
740                         }
741                         #endif
743                         //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
744                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
745                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
746                         {
747                             gCbWrtAfErrCnt++;
748                             //SW_BREAKPOINT; // FL: debug
749                         }
750                         
751                         // Handle overflows
752                         if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
753                         {
754                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
755                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
756                             {
757                                 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
758                                 gDecOpCbWrtAfOvr = 0; // reset overflow count
759                                 
760                                 // Reset circular buffer
761                                 cbReset(pCbCtl, z);
762                                 gSlaveCbResetCnt++; // increment slave circular buffer reset count
763                                 Log_info0("ASDT:cbReset");
764                             }
765                         }
766                         else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
767                         {
768                             // No overflow detected.
769                             // update max overflow count,
770                             // reset overflow count
771                             
772                             if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
773                             {
774                                 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
775                             }
776                             gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
777                             
778                             cbErrno = 0; // don't return error condition
779                         }
780                         //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
781                         TRACE_TERSE0("Dec:cbWriteAf() complete");
782                         
783 #if 0 // (***) FL: shows timing of CB write
784                         // (***) debug // B9
785                         {
786                             static Uint8 toggleState = 0;
787                             if (toggleState == 0)
788                                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
789                             else
790                                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
791                             toggleState = ~(toggleState);
792                         }
793 #endif        
794                         
795                         // FL: debug, log circular buffer control variables
796                         cbLog(pCbCtl, z, 1, "cbWriteAf");
797                     }
798                     
799                     // write back Dec configuration
800                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
801                     Cache_wait();
802                     
803 #ifdef NON_CACHE_STATUS
804                     statusOp_read(&(temp8),
805                                   &(pAstCfg->xDec[z].decodeStatus.mode),
806                                   sizeof(Int8),
807                                   GATEMP_INDEX_DEC);
808                     // Re-initialize audio frame if decoder is disabled or 
809                     // doesn't have a valid input 
810                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
811                     {
812                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
813                     }
814 #else
815                     // Re-initialize audio frame if decoder is disabled or
816                     // doesn't have a valid input
817                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
818                     {
819                         pP->fxns->initFrame1(pP, pQ, pAsdtCfg, z, 0);
820                     }
821 #endif
822                     // send dec info complete message to master
823                     queId = MessageQ_getReplyQueue(pAspMsg);
824                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
825                     pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
826                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
827                     argIdx = 0; // set decErrno
828                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
829                     argIdx += sizeof(Int32); // set cbErrno
830                     *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;                    
831                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
832                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
833                     if (status != MessageQ_S_SUCCESS)
834                     {
835                         SW_BREAKPOINT;
836                     }
837                     
838                     break;
839                     
840                 case ASP_SLAVE_DEC_DEACTIVATE:
841                     gSlaveDecDeactivateCnt++;
842                     // simulate dec info load
843                     //simLoad(DEC_DEACTIVATE_LOAD);
844                     
845                     argIdx = 0; // get decIdx
846                     z = *(Int32 *)&pAspMsg->buf[argIdx];
847                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
848                     
849                     if (alg[z]->fxns->algDeactivate)
850                     {
851                         alg[z]->fxns->algDeactivate(alg[z]);
852                     }
853                     
854                     // Stop writes to circular buffer
855                     //pCb = &pAstCfg->xDecOpCb[z];
856                     cbErrno = cbWriteStop(pCbCtl, z);
857                     if (cbErrno < 0)
858                     {
859                         SW_BREAKPOINT;
860                     }
861                     // FL: debug, log circular buffer control variables
862                     cbLog(pCbCtl, z, 1, "cbWriteStop");
863                     
864                     // send dec deactivate complete message to master
865                     queId = MessageQ_getReplyQueue(pAspMsg);
866                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
867                     pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
868                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
869                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
870                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
871                     if (status != MessageQ_S_SUCCESS)
872                     {
873                         SW_BREAKPOINT;
874                     }
875                     
876                     break;
877                     
878                 default:
879                     TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
880                     break;
881             }
882         }
883     }
884     
885     Log_info0("exit taskAsdpFxn()");   
889 // -----------------------------------------------------------------------------
890 // AST Initialization Function - Memory Allocation
891 //
892 //   Name:      PAF_AST_initPhaseMalloc
893 //   Purpose:   Audio Stream Task Function for initialization of data pointers
894 //              by allocation of memory.
895 //   From:      audioStream1Task or equivalent
896 //   Uses:      See code.
897 //   States:    x
898 //   Return:    0 on success.
899 //              Source code line number on MEM_calloc failure.
900 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
901 //              * State information as per parent.
902 //              * Memory allocation errors.
903 //
904 Int
905 PAF_ASDT_initPhaseMalloc(
906     const PAF_ASDT_Params *pP, 
907     const PAF_ASDT_Patchs *pQ, 
908     PAF_ASDT_Config *pAsdtCfg
911     PAF_AST_Config *pAstCfg;
912     Int as;                     /* Audio Stream Number (1, 2, etc.) */
913     Int zMS;
914     Error_Block eb;
916     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
917     as = pAstCfg->as;
918     zMS = pAstCfg->masterStr;
919     
920     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
922     // Initialize error block
923     Error_init(&eb); 
925     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL,
926         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
927     {
928         TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
929         SW_BREAKPOINT;
930         return __LINE__;
931     }
932     TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
933             DECODEN * sizeof (PAF_AudioFrame),
934             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
936     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
937     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
938     return 0;
939 } //PAF_ASDT_initPhaseMalloc
941 // -----------------------------------------------------------------------------
942 // AST Initialization Function - Memory Initialization from Configuration
943 //
944 //   Name:      PAF_AST_initPhaseConfig
945 //   Purpose:   Audio Stream Task Function for initialization of data values
946 //              from parameters.
947 //   From:      audioStream1Task or equivalent
948 //   Uses:      See code.
949 //   States:    x
950 //   Return:    0 on success.
951 //              Other as per initFrame0 and initFrame1.
952 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
953 //              * State information as per parent.
954 //
956 Int
957 PAF_ASDT_initPhaseConfig(
958     const PAF_ASDT_Params *pP, 
959     const PAF_ASDT_Patchs *pQ, 
960     PAF_ASDT_Config *pAsdtCfg
963     PAF_AST_Config *pAstCfg;
964     Int as;                    /* Audio Stream Number (1, 2, etc.) */
965     Int zMS;
966     Int z;
968     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
969     as = pAstCfg->as;
970     zMS = pAstCfg->masterStr;
971     
972     TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
974     // overwrite pointer to audio frame in framework decode control
975     for (z=DECODE1; z < DECODEN; z++) 
976     {
977         //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
978         //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
979         //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
980         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
981         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
982         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
983         pP->fxns->initFrame0(pP, pQ, pAsdtCfg, z);
984     }
986     return 0;
987 }  //PAF_ASDT_initPhaseConfig
989 // -----------------------------------------------------------------------------
990 // AST Initialization Function - ACP Algorithm Instantiation
991 //
992 //   Name:      PAF_AST_initPhaseAcpAlg
993 //   Purpose:   Audio Stream Task Function for initialization of ACP by
994 //              instantiation of the algorithm.
995 //   From:      audioStream1Task or equivalent
996 //   Uses:      See code.
997 //   States:    x
998 //   Return:    0 on success.
999 //              Source code line number on ACP Algorithm creation failure.
1000 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1001 //              * State information as per parent.
1002 //              * Memory allocation errors.
1003 //
1004 Int
1005 PAF_ASDT_initPhaseAcpAlg(
1006     const PAF_ASDT_Params *pP, 
1007     const PAF_ASDT_Patchs *pQ, 
1008     PAF_ASDT_Config *pAsdtCfg
1011     PAF_AST_Config *pAstCfg;
1012     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1013     Int z;                     /* input/encode/stream/decode/output counter */
1014     Int betaPrimeOffset;
1015     ACP_Handle acp;
1016     Int zMS;
1017     Int zS; //, zX;
1019     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1020     as = pAstCfg->as;
1021     zMS = pAstCfg->masterStr;    
1023     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1025     ACP_MDS_init();
1027     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1028     {
1029         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
1030         return __LINE__;
1031     }
1032     pAsdtCfg->acp = acp;
1034     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1035         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1037     for (z=DECODE1; z < DECODEN; z++) 
1038     {
1039         zS = pP->streamsFromDecodes[z];
1040         acp->fxns->attach(acp, ACP_SERIES_STD,
1041             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1042             (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1043         /* Ignore errors, not reported. */
1044     }
1046     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1048     return 0;
1049 } //PAF_AST_initPhaseAcpAlg
1051 // -----------------------------------------------------------------------------
1052 // AST Initialization Function - Common Memory and Algorithms
1053 //
1054 //   Name:      PAF_AST_initPhaseCommon
1055 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1056 //              by allocation for common memory and by instantiation for
1057 //              algorithms.
1058 //   From:      audioStream1Task or equivalent
1059 //   Uses:      See code.
1060 //   States:    x
1061 //   Return:    0 on success.
1062 //              Source code line number on PAF_ALG_alloc failure.
1063 //              Source code line number on PAF_ALG_mallocMemory failure.
1064 //              Source code line number on Decode Chain initialization failure.
1065 //              Source code line number on ASP Chain initialization failure.
1066 //              Source code line number on Encode Chain initialization failure.
1067 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1068 //              * State information as per parent.
1069 //              * Memory allocation errors.
1070 //
1072 #include <pafsio_ialg.h>
1074 Int
1075 PAF_ASDT_initPhaseCommon(
1076     const PAF_ASDT_Params *pP, 
1077     const PAF_ASDT_Patchs *pQ, 
1078     PAF_ASDT_Config *pAsdtCfg
1081     PAF_AST_Config *pAstCfg;
1082     Int as;                         /* Audio Stream Number (1, 2, etc.) */
1083     Int z;                          /* stream counter */
1084     //Int g;                        /* gear */
1085     ACP_Handle acp;
1086     PAF_IALG_Config pafAlgConfig;
1087     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1088    
1089     acp = pAsdtCfg->acp; // get acp handle
1090     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1091     as = pAstCfg->as;
1092     
1093     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1095     //
1096     // Determine memory needs and instantiate algorithms across audio streams
1097     //
1099     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1100     PAF_ALG_setup(&pafAlgConfig, 
1101         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1102         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1103         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1104         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1105         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1106         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1107         HEAP_CLEAR);
1109     if (pP->fxns->headerPrint)
1110         pP->fxns->headerPrint();
1112     for (z=STREAM1; z < STREAMN; z++) 
1113     {
1114         //Int zD, zE, zX;
1115         Int zD, zX;
1117         TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1119         //
1120         // Determine common memory needs of Decode Algorithms
1121         //
1122         PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1124         zD = -1;
1125         for (zX = DECODE1; zX < DECODEN; zX++) 
1126         {
1127             if (pP->streamsFromDecodes[zX] == z) 
1128             {
1129                 zD = zX;
1130                 break;
1131             }
1132         }
1134         if (zD >= 0) 
1135         {
1136             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1137             if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z])) 
1138             {
1139                 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1140                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1142                 SW_BREAKPOINT;
1143                 return __LINE__;
1144             }
1145             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1146             if(pP->fxns->allocPrint)
1147                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1148         }
1150 #if 0 // FL: master
1151         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1152         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1153         if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z])) 
1154         {
1155             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1156             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1157             SW_BREAKPOINT;
1158             return __LINE__;
1159         }
1160         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1161         if(pP->fxns->allocPrint)
1162             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1163 #endif
1164         
1165     }
1166     {
1167         // Changes made to share scratch between zones
1168         // Assume maximum 3 zones and scratch common memory is at offset 0;
1169         int max=0;
1170         for (z=STREAM1; z < STREAMN; z++)
1171         {
1172             if (max<common[z][0].size)
1173                 max=common[z][0].size;
1174         }
1175         common[STREAM1][0].size=max;
1176         for (z=STREAM1+1; z < STREAMN; z++)
1177             common[z][0].size=0;
1178     }
1179     
1180     //
1181     // Provide common memory needs of Decode Algorithms
1182     //
1183     for (z=STREAM1; z < STREAMN; z++) 
1184     {
1185         //Int zD, zE, zX;
1186         Int zD, zX;
1188         zD = -1;        
1189         for (zX = DECODE1; zX < DECODEN; zX++) 
1190         {
1191            if (pP->streamsFromDecodes[zX] == z) 
1192            {
1193                zD = zX;
1194                break;
1195            }
1196         }
1198         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1199         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
1200         {
1201             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1202             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1203             SW_BREAKPOINT;
1204             return __LINE__;
1205         }
1206         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1207         // share zone0 scratch with all zones 
1208         common[z][0].base=common[0][0].base;
1209         if (pP->fxns->commonPrint)
1210                 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1212         //
1213         // Instantiate Decode Algorithms
1214         //
1215         if (zD >= 0) 
1216         {
1217             PAF_ASP_Chain *chain;
1218             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1219             chain =
1220                 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1221                                    HEAP_INTERNAL, as+z, acp, &trace,
1222                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1223             if (!chain) 
1224             {
1225                 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1226                 return __LINE__;
1227             }
1228         }
1230 #if 0 // FL: master
1231         pC->xStr[z].aspChain[0] = NULL;
1232         for (g=0; g < GEARS; g++) 
1233         {
1234             PAF_ASP_Chain *chain;
1235             TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1236             chain =
1237                 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1238                                    HEAP_INTERNAL, as+z, acp, &trace,
1239                                    aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1240             if (! chain) 
1241             {
1242                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1243                 return __LINE__;
1244             }
1245             else
1246                 pC->xStr[z].aspChain[g] = chain;
1247         }
1248 #endif
1250     }
1251     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1253     return 0;
1254 } //PAF_ASDT_initPhaseCommon
1256 // -----------------------------------------------------------------------------
1257 // AST Initialization Function - Algorithm Keys
1258 //
1259 //   Name:      PAF_AST_initPhaseAlgKey
1260 //   Purpose:   Audio Stream Task Function for initialization of data values
1261 //              from parameters for Algorithm Keys.
1262 //   From:      audioStream1Task or equivalent
1263 //   Uses:      See code.
1264 //   States:    x
1265 //   Return:    0.
1266 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1267 //              * State information as per parent.
1268 //
1269 // .............................................................................
1270 Int
1271 PAF_ASDT_initPhaseAlgKey(
1272     const PAF_ASDT_Params *pP, 
1273     const PAF_ASDT_Patchs *pQ, 
1274     PAF_ASDT_Config *pAsdtCfg
1277     PAF_AST_Config *pAstCfg;
1278     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1279     Int z;                      /* decode/encode counter */
1280     Int s;                      /* key number */
1281     PAF_ASP_Link *that;
1283     (void)as;  // clear warning.
1285     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1286     as = pAstCfg->as;
1287     
1288     TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1290     for (z=DECODE1; z < DECODEN; z++) 
1291     {
1292         for (s=0; s < pP->pDecAlgKey->length; s++) 
1293         {
1294             if ((pP->pDecAlgKey->code[s].full != 0)
1295                 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1296             {
1297                 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1298                     /* Cast in interface, for now --Kurt */
1299             }
1300             else
1301                 pAstCfg->xDec[z].decAlg[s] = NULL;
1302         }
1303     }
1305     return 0;
1306 } //PAF_AST_initPhaseAlgKey
1308 //   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
1309 //              Frame(s) by memory allocation and loading of data pointers
1310 //              and values.
1311 Int
1312 PAF_ASDT_initFrame0(
1313     const PAF_ASDT_Params *pP, 
1314     const PAF_ASDT_Patchs *pQ, 
1315     PAF_ASDT_Config *pAsdtCfg, 
1316     Int z
1319     PAF_AST_Config *pAstCfg;
1320     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1321     Int aLen;
1322     Int aSize = sizeof(PAF_AudioData);
1323     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1324     Int maxFrameLength = pP->maxFramelength;
1325     PAF_AudioData *aBuf=NULL;
1326     XDAS_UInt8 *metadataBuf;
1327     Error_Block    eb;
1328     PAF_AudioFrame *pAudioFrame;
1329     Int i;
1331     pAstCfg = pAsdtCfg->pAstCfg; // get pointer to AST common (shared) configuration
1332     as = pAstCfg->as;
1334     pAudioFrame = &gpDecAudioFrame[z];
1335     if (pAudioFrame == NULL)
1336     {
1337         SW_BREAKPOINT;
1338     }
1339     
1340     // Initialize error block
1341     Error_init(&eb); 
1342     
1343     //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1344     //aLen = numchan[z] * maxFrameLength;
1345     aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1346                                                                                   See line 1301 */
1348     //
1349     // Initialize audio frame elements directly
1350     //
1351     pAudioFrame->fxns = pP->pAudioFrameFunctions;
1352     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1353     pAudioFrame->data.nSamples = FRAMELENGTH;
1354     pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1355     pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1356     pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1358     //
1359     // Allocate memory for and initialize pointers to audio data buffers
1360     //
1361     //   The NUMCHANMASK is used to identify the channels for which data
1362     //   buffers can be allocated. Using this mask and switch statement
1363     //   rather than some other construct allows efficient code generation,
1364     //   providing just the code necessary (with significant savings).
1365     //
1366     if (pP->fxns->bufMemPrint)
1367     {
1368         pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1369     }
1371     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1372     
1373     if (aLen != 0)
1374     {
1375         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1376         {
1377             TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1378             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
1379             SW_BREAKPOINT;
1380             return __LINE__;
1381         }
1382     }
1384     TRACE_TERSE3("  maxFrameLength: %d.  aLen*aSize: %d.  aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1386     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1387     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1388     {
1389         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1390         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1391         SW_BREAKPOINT;
1392         return __LINE__;
1393     }
1395     for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1396     {
1397         gDecAudioFrameChannelPointers[i] = NULL;
1398     }
1400     if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1401     {
1402         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1403         return __LINE__;
1404     }
1405     else 
1406     {
1407         Int j = 0;
1408         TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1409         for (i=0; i<numchan[z]; i++)
1410         {
1411             Int8 chan = AFChanPtrMap[numchan[z]][i];
1412             if (chan != -1)
1413             {
1414                 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1415                 j++;
1416                 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1417                 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1418             }
1419         }
1420     }
1422     // Initialize original audio frame channel pointers
1423     for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++) 
1424     {
1425         if (gDecAudioFrameChannelPointers[i])
1426         {
1427             gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1428         }
1429     }
1431     //
1432     // Initialize meta data elements
1433     //
1434     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1435     pAudioFrame->numPrivateMetadata = 0;
1436     pAudioFrame->bsMetadata_offset = 0;
1437     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1438     pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1439     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1440     {
1441         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1442         pAudioFrame->pafPrivateMetadata[i].size = 0;
1443         pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1444     }
1446     return 0;
1447 } //PAF_ASDT_initFrame0
1449 // -----------------------------------------------------------------------------
1450 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1451 // AST Decoding Function              - Reinitialization of Audio Frame
1452 //
1453 //   Name:      PAF_ASOT_initFrame1
1454 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1455 //              zation of the Audio Frame(s) by loading of data values of a
1456 //              time-varying nature.
1457 //   From:      audioStream1Task or equivalent
1458 //              AST Parameter Function -> decodeInfo
1459 //              AST Parameter Function -> decodeDecode
1460 //   Uses:      See code.
1461 //   States:    x
1462 //   Return:    0.
1463 //   Trace:     None.
1464 //
1465 Int
1466 PAF_ASDT_initFrame1(
1467     const PAF_ASDT_Params *pP, 
1468     const PAF_ASDT_Patchs *pQ, 
1469     PAF_ASDT_Config *pAsdtCfg, 
1470     Int z, 
1471     Int apply
1474     PAF_AudioFrame *pAudioFrame;
1476     //
1477     // Reinitialize audio frame elements:
1478     //
1479     //   Channel Configurations during sys init                 = Unknown
1480     //      "          "        during info or decode           = None
1481     //
1482     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1483     //
1485     pAudioFrame = &gpDecAudioFrame[z];
1487     if (apply < 0) 
1488     {
1489         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1490         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1491     }
1492     else 
1493     {
1494         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1495         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1496     }
1498     if (apply < 1) 
1499     {
1500         pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1501         pAudioFrame->sampleCount = 0;
1502     }
1504     return 0;
1505 } //PAF_ASDT_initFrame1
1507 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1508 Int resetAf(
1509     const PAF_ASDT_Params *pP, 
1510     Int z, 
1511     Int sourceSelect
1514     PAF_AudioFrame *pAudioFrame;
1515     Int ch;
1516     Int i;
1518     // Get audio frame
1519     pAudioFrame = &gpDecAudioFrame[z];
1520     if (pAudioFrame == NULL)
1521     {
1522         SW_BREAKPOINT;
1523     }
1525     // Reinitialize audio frame elements
1526     pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1527     pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1528     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1529     pAudioFrame->sampleCount = 0;
1530     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1531     
1532     switch (sourceSelect)
1533     {
1534         case PAF_SOURCE_PCM:
1535             pAudioFrame->data.nSamples = FRAMELENGTH;
1536             break;
1537         case PAF_SOURCE_AC3:
1538         case PAF_SOURCE_DDP:
1539             pAudioFrame->data.nSamples = 1536;
1540             break;
1541         case PAF_SOURCE_THD:
1542             pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1543             break;
1544         case PAF_SOURCE_DTS:
1545         case PAF_SOURCE_DTSHD:
1546         case PAF_SOURCE_DTS12:
1547         case PAF_SOURCE_DTS13:
1548         case PAF_SOURCE_DTS14:
1549         case PAF_SOURCE_DTS16:
1550         case PAF_SOURCE_DTSALL:
1551             pAudioFrame->data.nSamples = 8192; // TODO: Need to set correct value, max Sample output
1552             break;
1553         default:  
1554             pAudioFrame->data.nSamples = FRAMELENGTH;
1555             break;
1556     }
1558     // Reset audio frame channel pointers
1559     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1560     {
1561         if (gDecAudioFrameChannelPointers[ch])
1562         {
1563             gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1564         }
1565     }
1566     
1567     // Reset audio frame meta data elements
1568     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1569     pAudioFrame->numPrivateMetadata = 0;
1570     pAudioFrame->bsMetadata_offset = 0;
1571     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1572     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1573     {
1574         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1575         pAudioFrame->pafPrivateMetadata[i].size = 0;
1576     }
1577     
1578     return 0;
1581 // Reset AF samsiz, invoked during DECODE
1582 Int resetAfSamsiz(
1583     Int z
1586     PAF_AudioFrame *pAudioFrame;
1587     Int ch;
1588     
1589     // Get audio frame
1590     pAudioFrame = &gpDecAudioFrame[z];
1591     if (pAudioFrame == NULL)
1592     {
1593         SW_BREAKPOINT;
1594     }
1595     
1596     // Clear samsiz for all channels - MID 208.
1597     for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
1598     {
1599         pAudioFrame->data.samsiz[ch] = 0;
1600     }
1602     return 0;