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