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