]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_arm/framework/audioStreamDecodeProc.c
PASDK-258:Update code merged from 4573453 (PP PASDK-242) for default build.
[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 // Overflow 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 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
107 UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
108 UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
110 // Global debug counters */
111 UInt32 gSlaveStartErrCnt        =0;
112 UInt32 gSlaveStartCnt           =0;
113 UInt32 gSlaveSourceSelectCnt    =0;
114 UInt32 gSlaveExitCnt            =0;
115 UInt32 gSlaveDecExitCnt         =0;
116 UInt32 gSlaveDecControlCnt      =0;
117 UInt32 gSlaveDecActivateCnt     =0;
118 UInt32 gSlaveDecResetCnt        =0;
119 UInt32 gSlaveDecInfoCnt         =0;
120 UInt32 gSlaveDecDecodeCnt       =0;
121 UInt32 gSlaveDecDeactivateCnt   =0;
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;       // reset write circular buffer error count
503                     gDecOpCbWrtAfOvr=0;     // reset decoder output circular buffer overflow count
504                     gMaxDecOpCbWrtAfOvr=0;  // reset max decoder output circular buffer overflow count
505                     // FL: debug, log circular buffer control variables
506                     cbLog(pCbCtl, z, 1, "cbWriteStart");
507                     // Reset audio frame
508                     resetAf(pP, z, sourceSelect);
509                     
510                     // send dec activate complete message to master
511                     queId = MessageQ_getReplyQueue(pAspMsg);
512                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
513                     pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
514                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
515                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
516                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
517                     if (status != MessageQ_S_SUCCESS)
518                     {
519                         SW_BREAKPOINT;
520                     }
521                    
522                     break;
523                     
524                 case ASP_SLAVE_DEC_RESET:
525                     gSlaveDecResetCnt++;
526                     // simulate dec reset load
527                     //simLoad(DEC_RESET_LOAD);
528                     
529                     argIdx = 0; // get decIdx
530                     z = *(Int32 *)&pAspMsg->buf[argIdx];
531                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
532                     
533                     dec = (DEC_Handle)alg[z];
534                     errno = 0;
535                     if (dec->fxns->reset)
536                     {
537                         errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
538                     }
540                     // write back Dec configuration
541                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
542                     Cache_wait();            
544                     // (***) FL: revisit
545                     // write back Status structures for shared Beta Units
546                     //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
547                     //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
548                    /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
549                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
550                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
551                     Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
552                     Cache_wait();*/
553                     
554                     // send dec reset complete message to master
555                     queId = MessageQ_getReplyQueue(pAspMsg);
556                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
557                     pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
558                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
559                     argIdx = 0; // set decErrno
560                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
561                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
562                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
563                     if (status != MessageQ_S_SUCCESS)
564                     {
565                         SW_BREAKPOINT;
566                     }
568                     break;
569                     
570                 case ASP_SLAVE_DEC_INFO:
571                     gSlaveDecInfoCnt++;
572                     // simulate dec info load
573                     //simLoad(DEC_INFO_LOAD);
574                     
575                     argIdx = 0; // get decIdx
576                     z = *(Int32 *)&pAspMsg->buf[argIdx];
577                     TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
578                     // Get input associated w/ decoder
579                     zI = pP->inputsFromDecodes[z];
581                     // (***) FL: revisit
582                     // invalidate Inp configuration
583                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
584                     Cache_wait();
585                     // invalidate input data
586                     pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
587                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
588                     if (sourceSelect == PAF_SOURCE_PCM)
589                     {
590                         size *= pIpBufConfig->stride;
591                     }
593                     bufEnd = (Int) pIpBufConfig->base.pVoid + pIpBufConfig->sizeofBuffer;
594                     currentBufSize = (bufEnd - (Int)pIpBufConfig->pntr.pSmInt);
595                     if (currentBufSize >= size)
596                     {
597                         chunkSize = size;
598                     }
599                     else
600                     {
601                         chunkSize = currentBufSize;
602                     }
603                     wrapSize = size - chunkSize;
604                     // invalidate input data
605                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
606                     // invalidate Dec configuration
607                     TRACE_MSG2("IBUF : pIpBufConfig->pntr.pSmInt: 0x%x and chunkSize: %d", (IArg)pIpBufConfig->pntr.pSmInt, chunkSize);
608                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
609                     // status for selected decoder should be invalidated
610                     Cache_wait();
612                     /* Circular buffer wrap condition*/
613                     //if(((Int) pIpBufConfig->head.pVoid + size)  > bufEnd)
614                     if(wrapSize > 0)
615                     {
616                         // invalidate input data
617                         Cache_inv((Ptr)pIpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
618                         TRACE_MSG2("IBUF : pIpBufConfig->base.pSmInt: 0x%x and wrapSize: %d", (IArg)pIpBufConfig->base.pSmInt, wrapSize);
619                         // status for selected decoder should be invalidated
620                         Cache_wait();
621                     }
622                     /* Circular buffer wrap condition */
624                     dec = (DEC_Handle)alg[z];
625                     errno = 0;
626                     if (dec->fxns->info)
627                     {
628                         errno = dec->fxns->info(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
629                     }
630                     
631                     // write back Dec configuration
632                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
633                     Cache_wait();            
634                     
635 #ifdef NON_CACHE_STATUS
636                     statusOp_read(&(temp8),
637                                   &(pAstCfg->xDec[z].decodeStatus.mode),
638                                   sizeof(Int8),
639                                   GATEMP_INDEX_DEC);
640                     // Re-initialize audio frame if decoder is disabled or
641                     // doesn't have a valid input
642                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
643                     {
644                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
645                     }
646 #else
647                     // Re-initialize audio frame if decoder is disabled or
648                     // doesn't have a valid input
649                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
650                     {
651                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
652                     }
653 #endif
655                     // send dec info complete message to master
656                     queId = MessageQ_getReplyQueue(pAspMsg);
657                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
658                     pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
659                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
660                     argIdx = 0; // set decErrno
661                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
662                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
663                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
664                     if (status != MessageQ_S_SUCCESS)
665                     {
666                         SW_BREAKPOINT;
667                     }
668                     
669                     break;
670                     
671                 case ASP_SLAVE_DEC_DECODE:
672                     gSlaveDecDecodeCnt++;
673                     // simulate dec info load
674                     //simLoad(DEC_DECODE_LOAD);
675                     
676                     argIdx = 0; // get decIdx
677                     z = *(Int32 *)&pAspMsg->buf[argIdx];
678                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
679                     // Get input associated w/ decoder
680                     zI = pP->inputsFromDecodes[z];
681                     
682                     // Reset AF samsiz
683                     resetAfSamsiz(z);
684                     
685                     // invalidate Dec configuration
686                     Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
687                     Cache_wait();
688                     //TRACE_TERSE0("Dec:cache wb done");
689             
690                     dec = (DEC_Handle)alg[z];
691                     //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
693                     errno = 0;
694                     cbErrno = 0;
695                     if (dec->fxns->decode)
696                     {
697                         // FL: debug, capture input buffer
698                         //capIb(pAstCfg->xInp[z].pInpBuf);
699                     
700                         errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
701                         if (errno < 0)
702                         {
703                             //SW_BREAKPOINT;
704                         }
705                         TRACE_TERSE0("Dec:decode done");
706                         
707                         // copy decoder output to decoder output circular buffers
708                         //pCb = &pAstCfg->xDecOpCb[z];
709                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
710                         
711                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
712                         TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
713                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
714                         
715                         // FL: debug, capture audio frame
716                         //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
717                         //{
718                         //    Log_info0("capAfWrite() error");
719                         //}                        
721                         GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
722                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
723                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
724                         {
725                             gCbWrtAfErrCnt++;
726                             //SW_BREAKPOINT; // FL: debug
727                         }
728                         
729                         // Handle overflows
730                         if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
731                         {
732                             gDecOpCbWrtAfOvr++; // increment circular buffer overflow count
733                             if (gDecOpCbWrtAfOvr >= DEC_OP_CB_WRTAF_OVR_THR)
734                             {
735                                 gMaxDecOpCbWrtAfOvr = DEC_OP_CB_WRTAF_OVR_THR; // update max overflow count
736                                 gDecOpCbWrtAfOvr = 0; // reset overflow count
737                                 
738                                 // Reset circular buffer
739                                 cbReset(pCbCtl, z);
740                             }
741                         }
742                         else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbWrtAfOvr > 0))
743                         {
744                             // No overflow detected.
745                             // update max overflow count,
746                             // reset overflow count
747                             
748                             if (gDecOpCbWrtAfOvr > gMaxDecOpCbWrtAfOvr)
749                             {
750                                 gMaxDecOpCbWrtAfOvr = gDecOpCbWrtAfOvr;
751                             }
752                             gDecOpCbWrtAfOvr = 0; // reset circular buffer overflow count
753                             
754                             cbErrno = 0; // don't return error condition
755                         }
756                         GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
757                         TRACE_TERSE0("Dec:cbWriteAf() complete");
758                         
759 #if 0 // (***) FL: shows timing of CB write
760                         // (***) debug // B9
761                         {
762                             static Uint8 toggleState = 0;
763                             if (toggleState == 0)
764                                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
765                             else
766                                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
767                             toggleState = ~(toggleState);
768                         }
769 #endif        
770                         
771                         // FL: debug, log circular buffer control variables
772                         cbLog(pCbCtl, z, 1, "cbWriteAf");
773                     }
774                     
775                     // write back Dec configuration
776                     Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
777                     Cache_wait();
778                     
779 #ifdef NON_CACHE_STATUS
780                     statusOp_read(&(temp8),
781                                   &(pAstCfg->xDec[z].decodeStatus.mode),
782                                   sizeof(Int8),
783                                   GATEMP_INDEX_DEC);
784                     // Re-initialize audio frame if decoder is disabled or 
785                     // doesn't have a valid input 
786                     if (!temp8 || !pAstCfg->xInp[zI].hRxSio)
787                     {
788                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
789                     }
790 #else
791                     // Re-initialize audio frame if decoder is disabled or
792                     // doesn't have a valid input
793                     if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
794                     {
795                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
796                     }
797 #endif
798                     // send dec info complete message to master
799                     queId = MessageQ_getReplyQueue(pAspMsg);
800                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
801                     pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
802                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
803                     argIdx = 0; // set decErrno
804                     *(Int32 *)&pAspMsg->buf[argIdx] = errno;
805                     argIdx += sizeof(Int32); // set cbErrno
806                     *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;                    
807                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
808                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
809                     if (status != MessageQ_S_SUCCESS)
810                     {
811                         SW_BREAKPOINT;
812                     }
813                     
814                     break;
815                     
816                 case ASP_SLAVE_DEC_DEACTIVATE:
817                     gSlaveDecDeactivateCnt++;
818                     // simulate dec info load
819                     //simLoad(DEC_DEACTIVATE_LOAD);
820                     
821                     argIdx = 0; // get decIdx
822                     z = *(Int32 *)&pAspMsg->buf[argIdx];
823                     TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
824                     
825                     if (alg[z]->fxns->algDeactivate)
826                     {
827                         alg[z]->fxns->algDeactivate(alg[z]);
828                     }
829                     
830                     // Stop writes to circular buffer
831                     //pCb = &pAstCfg->xDecOpCb[z];
832                     cbErrno = cbWriteStop(pCbCtl, z);
833                     if (cbErrno < 0)
834                     {
835                         SW_BREAKPOINT;
836                     }
837                     // FL: debug, log circular buffer control variables
838                     cbLog(pCbCtl, z, 1, "cbWriteStop");
839                     
840                     // send dec deactivate complete message to master
841                     queId = MessageQ_getReplyQueue(pAspMsg);
842                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
843                     pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
844                     pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
845                     TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
846                     status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
847                     if (status != MessageQ_S_SUCCESS)
848                     {
849                         SW_BREAKPOINT;
850                     }
851                     
852                     break;
853                     
854                 default:
855                     TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
856                     break;
857             }
858         }
859     }
860     
861     Log_info0("exit taskAsdpFxn()");   
865 // -----------------------------------------------------------------------------
866 // AST Initialization Function - Memory Allocation
867 //
868 //   Name:      PAF_AST_initPhaseMalloc
869 //   Purpose:   Audio Stream Task Function for initialization of data pointers
870 //              by allocation of memory.
871 //   From:      audioStream1Task or equivalent
872 //   Uses:      See code.
873 //   States:    x
874 //   Return:    0 on success.
875 //              Source code line number on MEM_calloc failure.
876 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
877 //              * State information as per parent.
878 //              * Memory allocation errors.
879 //
880 Int
881 PAF_ASDT_initPhaseMalloc(
882     const PAF_ASDT_Params *pP, 
883     const PAF_ASDT_Patchs *pQ, 
884     PAF_ASDT_Config *pC
887     PAF_AST_Config *pAstCfg;
888     Int as;                     /* Audio Stream Number (1, 2, etc.) */
889     Int zMS;
890     Error_Block eb;
892     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
893     as = pAstCfg->as;
894     zMS = pAstCfg->masterStr;
895     
896     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
898     // Initialize error block
899     Error_init(&eb); 
901 //    if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL1,
902     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, //Qin - moved to external memory
903         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
904     {
905         TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
906         SW_BREAKPOINT;
907         return __LINE__;
908     }
909     TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
910             DECODEN * sizeof (PAF_AudioFrame),
911             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
913     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
914     TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
915     return 0;
916 } //PAF_ASDT_initPhaseMalloc
918 // -----------------------------------------------------------------------------
919 // AST Initialization Function - Memory Initialization from Configuration
920 //
921 //   Name:      PAF_AST_initPhaseConfig
922 //   Purpose:   Audio Stream Task Function for initialization of data values
923 //              from parameters.
924 //   From:      audioStream1Task or equivalent
925 //   Uses:      See code.
926 //   States:    x
927 //   Return:    0 on success.
928 //              Other as per initFrame0 and initFrame1.
929 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
930 //              * State information as per parent.
931 //
933 Int
934 PAF_ASDT_initPhaseConfig(
935     const PAF_ASDT_Params *pP, 
936     const PAF_ASDT_Patchs *pQ, 
937     PAF_ASDT_Config *pC
940     PAF_AST_Config *pAstCfg;
941     Int as;                    /* Audio Stream Number (1, 2, etc.) */
942     Int zMS;
943     Int z;
945     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
946     as = pAstCfg->as;
947     zMS = pAstCfg->masterStr;
948     
949     TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
951     // overwrite pointer to audio frame in framework decode control
952     for (z=DECODE1; z < DECODEN; z++) 
953     {
954         //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
955         //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
956         //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
957         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
958         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
959         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
960         pP->fxns->initFrame0(pP, pQ, pC, z);
961     }
963     return 0;
964 }  //PAF_ASDT_initPhaseConfig
966 // -----------------------------------------------------------------------------
967 // AST Initialization Function - ACP Algorithm Instantiation
968 //
969 //   Name:      PAF_AST_initPhaseAcpAlg
970 //   Purpose:   Audio Stream Task Function for initialization of ACP by
971 //              instantiation of the algorithm.
972 //   From:      audioStream1Task or equivalent
973 //   Uses:      See code.
974 //   States:    x
975 //   Return:    0 on success.
976 //              Source code line number on ACP Algorithm creation failure.
977 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
978 //              * State information as per parent.
979 //              * Memory allocation errors.
980 //
981 Int
982 PAF_ASDT_initPhaseAcpAlg(
983     const PAF_ASDT_Params *pP, 
984     const PAF_ASDT_Patchs *pQ, 
985     PAF_ASDT_Config *pC
988     PAF_AST_Config *pAstCfg;
989     Int as;                    /* Audio Stream Number (1, 2, etc.) */
990     Int z;                     /* input/encode/stream/decode/output counter */
991     Int betaPrimeOffset;
992     ACP_Handle acp;
993     Int zMS;
994     Int zS; //, zX;
996     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
997     as = pAstCfg->as;
998     zMS = pAstCfg->masterStr;    
1000     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1002     ACP_MDS_init();
1004     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1005     {
1006         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
1007         return __LINE__;
1008     }
1009     pC->acp = acp;
1011     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
1012         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1014     for (z=DECODE1; z < DECODEN; z++) 
1015     {
1016         zS = pP->streamsFromDecodes[z];
1017         acp->fxns->attach(acp, ACP_SERIES_STD,
1018             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
1019             (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
1020         /* Ignore errors, not reported. */
1021     }
1023     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1025     return 0;
1026 } //PAF_AST_initPhaseAcpAlg
1028 // -----------------------------------------------------------------------------
1029 // AST Initialization Function - Common Memory and Algorithms
1030 //
1031 //   Name:      PAF_AST_initPhaseCommon
1032 //   Purpose:   Audio Stream Task Function for initialization of data pointers
1033 //              by allocation for common memory and by instantiation for
1034 //              algorithms.
1035 //   From:      audioStream1Task or equivalent
1036 //   Uses:      See code.
1037 //   States:    x
1038 //   Return:    0 on success.
1039 //              Source code line number on PAF_ALG_alloc failure.
1040 //              Source code line number on PAF_ALG_mallocMemory failure.
1041 //              Source code line number on Decode Chain initialization failure.
1042 //              Source code line number on ASP Chain initialization failure.
1043 //              Source code line number on Encode Chain initialization failure.
1044 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1045 //              * State information as per parent.
1046 //              * Memory allocation errors.
1047 //
1049 #include <pafsio_ialg.h>
1051 Int
1052 PAF_ASDT_initPhaseCommon(
1053     const PAF_ASDT_Params *pP, 
1054     const PAF_ASDT_Patchs *pQ, 
1055     PAF_ASDT_Config *pC
1058     PAF_AST_Config *pAstCfg;
1059     Int as;                         /* Audio Stream Number (1, 2, etc.) */
1060     Int z;                          /* stream counter */
1061     //Int g;                        /* gear */
1062     ACP_Handle acp;
1063     PAF_IALG_Config pafAlgConfig;
1064     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1065    
1066     acp = pC->acp; // get acp handle
1067     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1068     as = pAstCfg->as;
1069     
1070     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
1072     //
1073     // Determine memory needs and instantiate algorithms across audio streams
1074     //
1076     TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
1077     PAF_ALG_setup(&pafAlgConfig, 
1078         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1079         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1080         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1081         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1082         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1083         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1084         HEAP_CLEAR);
1086     if (pP->fxns->headerPrint)
1087         pP->fxns->headerPrint();
1089     for (z=STREAM1; z < STREAMN; z++) 
1090     {
1091         //Int zD, zE, zX;
1092         Int zD, zX;
1094         TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
1096         //
1097         // Determine common memory needs of Decode Algorithms
1098         //
1099         PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
1101         zD = -1;
1102         for (zX = DECODE1; zX < DECODEN; zX++) 
1103         {
1104             if (pP->streamsFromDecodes[zX] == z) 
1105             {
1106                 zD = zX;
1107                 break;
1108             }
1109         }
1111         if (zD >= 0) 
1112         {
1113             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
1114             if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z])) 
1115             {
1116                 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1117                 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
1119                 SW_BREAKPOINT;
1120                 return __LINE__;
1121             }
1122             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1123             if(pP->fxns->allocPrint)
1124                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
1125         }
1127 #if 0 // FL: master
1128         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1129         TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1130         if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z])) 
1131         {
1132             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1133             TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1134             SW_BREAKPOINT;
1135             return __LINE__;
1136         }
1137         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1138         if(pP->fxns->allocPrint)
1139             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1140 #endif
1141         
1142     }
1143     {
1144         // Changes made to share scratch between zones
1145         // Assume maximum 3 zones and scratch common memory is at offset 0;
1146         int max=0;
1147         for (z=STREAM1; z < STREAMN; z++)
1148         {
1149             if (max<common[z][0].size)
1150                 max=common[z][0].size;
1151         }
1152         common[STREAM1][0].size=max;
1153         for (z=STREAM1+1; z < STREAMN; z++)
1154             common[z][0].size=0;
1155     }
1156     
1157     //
1158     // Provide common memory needs of Decode Algorithms
1159     //
1160     for (z=STREAM1; z < STREAMN; z++) 
1161     {
1162         //Int zD, zE, zX;
1163         Int zD, zX;
1165         zD = -1;        
1166         for (zX = DECODE1; zX < DECODEN; zX++) 
1167         {
1168            if (pP->streamsFromDecodes[zX] == z) 
1169            {
1170                zD = zX;
1171                break;
1172            }
1173         }
1175         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1176         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
1177         {
1178             TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1179             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1180             SW_BREAKPOINT;
1181             return __LINE__;
1182         }
1183         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1184         // share zone0 scratch with all zones 
1185         common[z][0].base=common[0][0].base;
1186         if (pP->fxns->commonPrint)
1187                 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1189         //
1190         // Instantiate Decode Algorithms
1191         //
1192         if (zD >= 0) 
1193         {
1194             PAF_ASP_Chain *chain;
1195             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1196             chain =
1197                 PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
1198                                    HEAP_INTERNAL, as+z, acp, &trace,
1199                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1200             if (!chain) 
1201             {
1202                 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
1203                 return __LINE__;
1204             }
1205         }
1207 #if 0 // FL: master
1208         pC->xStr[z].aspChain[0] = NULL;
1209         for (g=0; g < GEARS; g++) 
1210         {
1211             PAF_ASP_Chain *chain;
1212             TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1213             chain =
1214                 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1215                                    HEAP_INTERNAL, as+z, acp, &trace,
1216                                    aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1217             if (! chain) 
1218             {
1219                 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1220                 return __LINE__;
1221             }
1222             else
1223                 pC->xStr[z].aspChain[g] = chain;
1224         }
1225 #endif
1227     }
1228     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1230     return 0;
1231 } //PAF_ASDT_initPhaseCommon
1233 // -----------------------------------------------------------------------------
1234 // AST Initialization Function - Algorithm Keys
1235 //
1236 //   Name:      PAF_AST_initPhaseAlgKey
1237 //   Purpose:   Audio Stream Task Function for initialization of data values
1238 //              from parameters for Algorithm Keys.
1239 //   From:      audioStream1Task or equivalent
1240 //   Uses:      See code.
1241 //   States:    x
1242 //   Return:    0.
1243 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1244 //              * State information as per parent.
1245 //
1246 // .............................................................................
1247 Int
1248 PAF_ASDT_initPhaseAlgKey(
1249     const PAF_ASDT_Params *pP, 
1250     const PAF_ASDT_Patchs *pQ, 
1251     PAF_ASDT_Config *pC
1254     PAF_AST_Config *pAstCfg;
1255     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1256     Int z;                      /* decode/encode counter */
1257     Int s;                      /* key number */
1258     PAF_ASP_Link *that;
1260     (void)as;  // clear warning.
1262     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1263     as = pAstCfg->as;
1264     
1265     TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1267     for (z=DECODE1; z < DECODEN; z++) 
1268     {
1269         for (s=0; s < pP->pDecAlgKey->length; s++) 
1270         {
1271             if ((pP->pDecAlgKey->code[s].full != 0)
1272                 && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1273             {
1274                 pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1275                     /* Cast in interface, for now --Kurt */
1276             }
1277             else
1278                 pAstCfg->xDec[z].decAlg[s] = NULL;
1279         }
1280     }
1282     return 0;
1283 } //PAF_AST_initPhaseAlgKey
1285 //   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
1286 //              Frame(s) by memory allocation and loading of data pointers
1287 //              and values.
1288 Int
1289 PAF_ASDT_initFrame0(
1290     const PAF_ASDT_Params *pP, 
1291     const PAF_ASDT_Patchs *pQ, 
1292     PAF_ASDT_Config *pC, 
1293     Int z
1296     PAF_AST_Config *pAstCfg;
1297     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1298     Int aLen;
1299     Int aSize = sizeof(PAF_AudioData);
1300     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1301     Int maxFrameLength = pP->maxFramelength;
1302     PAF_AudioData *aBuf=NULL;
1303     XDAS_UInt8 *metadataBuf;
1304     Error_Block    eb;
1305     PAF_AudioFrame *pAudioFrame;
1306     Int i;
1308     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1309     as = pAstCfg->as;
1311     pAudioFrame = &gpDecAudioFrame[z];
1312     if (pAudioFrame == NULL)
1313     {
1314         SW_BREAKPOINT;
1315     }
1316     
1317     // Initialize error block
1318     Error_init(&eb); 
1319     
1320     //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1321     //aLen = numchan[z] * maxFrameLength;
1322     aLen = numchan[z] * maxFrameLength + (maxFrameLength - FRAMELENGTH); /* Qin - need additional memory for starting offset
1323                                                                                       See line 1301 */
1325     //
1326     // Initialize audio frame elements directly
1327     //
1328     pAudioFrame->fxns = pP->pAudioFrameFunctions;
1329     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1330     pAudioFrame->data.nSamples = FRAMELENGTH;
1331     pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1332     pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1333     pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1335     //
1336     // Allocate memory for and initialize pointers to audio data buffers
1337     //
1338     //   The NUMCHANMASK is used to identify the channels for which data
1339     //   buffers can be allocated. Using this mask and switch statement
1340     //   rather than some other construct allows efficient code generation,
1341     //   providing just the code necessary (with significant savings).
1342     //
1343     if (pP->fxns->bufMemPrint)
1344     {
1345         pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1346     }
1348     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1349     
1350     if (aLen != 0)
1351     {
1352         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1353         {
1354             TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1355             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
1356             SW_BREAKPOINT;
1357             return __LINE__;
1358         }
1359     }
1361     TRACE_TERSE3("  maxFrameLength: %d.  aLen*aSize: %d.  aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1363     TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1364     if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1365     {
1366         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1367         TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1368         SW_BREAKPOINT;
1369         return __LINE__;
1370     }
1372     for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1373     {
1374         gDecAudioFrameChannelPointers[i] = NULL;
1375     }
1377     if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
1378     {
1379         TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1380         return __LINE__;
1381     }
1382     else 
1383     {
1384         Int j = 0;
1385         TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1386         for (i=0; i<numchan[z]; i++)
1387         {
1388             Int8 chan = AFChanPtrMap[numchan[z]][i];
1389             if (chan != -1)
1390             {
1391                 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1392                 j++;
1393                 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1394                 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1395             }
1396         }
1397     }
1399     // Initialize original audio frame channel pointers
1400     for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++) 
1401     {
1402         if (gDecAudioFrameChannelPointers[i])
1403         {
1404             gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1405         }
1406     }
1408     //
1409     // Initialize meta data elements
1410     //
1411     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1412     pAudioFrame->numPrivateMetadata = 0;
1413     pAudioFrame->bsMetadata_offset = 0;
1414     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1415     pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1416     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1417     {
1418         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1419         pAudioFrame->pafPrivateMetadata[i].size = 0;
1420         pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1421     }
1423     return 0;
1424 } //PAF_ASDT_initFrame0
1426 // -----------------------------------------------------------------------------
1427 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1428 // AST Decoding Function              - Reinitialization of Audio Frame
1429 //
1430 //   Name:      PAF_ASOT_initFrame1
1431 //   Purpose:   Audio Stream Task Function for initialization or reinitiali-
1432 //              zation of the Audio Frame(s) by loading of data values of a
1433 //              time-varying nature.
1434 //   From:      audioStream1Task or equivalent
1435 //              AST Parameter Function -> decodeInfo
1436 //              AST Parameter Function -> decodeDecode
1437 //   Uses:      See code.
1438 //   States:    x
1439 //   Return:    0.
1440 //   Trace:     None.
1441 //
1442 Int
1443 PAF_ASDT_initFrame1(
1444     const PAF_ASDT_Params *pP, 
1445     const PAF_ASDT_Patchs *pQ, 
1446     PAF_ASDT_Config *pC, 
1447     Int z, 
1448     Int apply
1451     PAF_AudioFrame *pAudioFrame;
1453     //
1454     // Reinitialize audio frame elements:
1455     //
1456     //   Channel Configurations during sys init                 = Unknown
1457     //      "          "        during info or decode           = None
1458     //
1459     //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
1460     //
1462     pAudioFrame = &gpDecAudioFrame[z];
1464     if (apply < 0) 
1465     {
1466         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1467         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1468     }
1469     else 
1470     {
1471         pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1472         pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1473     }
1475     if (apply < 1) 
1476     {
1477         pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1478         pAudioFrame->sampleCount = 0;
1479     }
1481     return 0;
1482 } //PAF_ASDT_initFrame1
1484 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1485 Int resetAf(
1486     const PAF_ASDT_Params *pP, 
1487     Int z, 
1488     Int sourceSelect
1491     PAF_AudioFrame *pAudioFrame;
1492     Int ch;
1493     Int i;
1495     // Get audio frame
1496     pAudioFrame = &gpDecAudioFrame[z];
1497     if (pAudioFrame == NULL)
1498     {
1499         SW_BREAKPOINT;
1500     }
1502     // Reinitialize audio frame elements
1503     pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1504     pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1505     pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1506     pAudioFrame->sampleCount = 0;
1507     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1508     
1509     switch (sourceSelect)
1510     {
1511         case PAF_SOURCE_PCM:
1512             pAudioFrame->data.nSamples = FRAMELENGTH;
1513             break;
1514         case PAF_SOURCE_AC3:
1515         case PAF_SOURCE_DDP:
1516             pAudioFrame->data.nSamples = 1536;
1517             break;
1518         case PAF_SOURCE_THD:
1519             pAudioFrame->data.nSamples = 5120; //QIN FIX ME
1520             break;
1521         default:  
1522             pAudioFrame->data.nSamples = FRAMELENGTH;
1523             break;
1524     }
1526     // Reset audio frame channel pointers
1527     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
1528     {
1529         if (gDecAudioFrameChannelPointers[ch])
1530         {
1531             gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1532         }
1533     }
1534     
1535     // Reset audio frame meta data elements
1536     pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1537     pAudioFrame->numPrivateMetadata = 0;
1538     pAudioFrame->bsMetadata_offset = 0;
1539     pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1540     for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1541     {
1542         pAudioFrame->pafPrivateMetadata[i].offset = 0;
1543         pAudioFrame->pafPrivateMetadata[i].size = 0;
1544     }
1545     
1546     return 0;
1549 // Reset AF samsiz, invoked during DECODE
1550 Int resetAfSamsiz(
1551     Int z
1554     PAF_AudioFrame *pAudioFrame;
1555     Int ch;
1556     
1557     // Get audio frame
1558     pAudioFrame = &gpDecAudioFrame[z];
1559     if (pAudioFrame == NULL)
1560     {
1561         SW_BREAKPOINT;
1562     }
1563     
1564     // Clear samsiz for all channels - MID 208.
1565     for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
1566     {
1567         pAudioFrame->data.samsiz[ch] = 0;
1568     }
1570     return 0;