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