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