]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/audioStreamDecodeProc.c
Split Decoder Output Circular Buffer code between Master (DSP:init,read) and Slave...
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_arm / framework / audioStreamDecodeProc.c
index ac7fa4b6d4b85ed022032498c5e690b98574a556..cdd23ce0a961dcc74d11ad3f03c88835dd798971 100644 (file)
@@ -53,12 +53,11 @@ All rights reserved.
 #include "audioStreamProc_params.h"
 #include "audioStreamProc_patchs.h"
 #include "audioStreamProc_config.h"
-#include "paf_decOpCircBuf.h"
 
 #include "common.h"
 #include "aspMsg_common.h"
 #include "aspMsg_slave.h"
-
+#include "aspDecOpCircBuf_slave.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamDecodeProc.h"
 
@@ -75,9 +74,6 @@ All rights reserved.
 
 #define __TASK_NAME__  "TaskAsdp"
 
-LINNO_DEFN(TaskAsdp); /* Line number macros */
-ERRNO_DEFN(TaskAsdp); /* Error number macros */
-
 extern struct {
     Int size;
     IALG_Status *pStatus[512];
@@ -86,15 +82,22 @@ extern struct {
 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
 
-// Global debug counters */
-extern Uint32 gTaskAsdpCnt; // debug counter for ASDP task
+LINNO_DEFN(TaskAsdp); /* Line number macros */
+ERRNO_DEFN(TaskAsdp); /* Error number macros */
+
+// ASDT configuration
+PAF_ASDT_Config gPAF_ASDT_config 
+__attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
+    NULL,
+    &gPAF_AST_config
+};
 
 PAF_AudioFrame *gpDecAudioFrame=NULL;
 PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
-// Debug counters
+// Global debug counters */
 UInt32 gSlaveStartErrCnt        =0;
 UInt32 gSlaveStartCnt           =0;
 UInt32 gSlaveSourceSelectCnt    =0;
@@ -114,10 +117,12 @@ UInt32 gSlaveDecDeactivateCnt   =0;
  */
 Void taskAsdpFxn(
 //    Int betaPrimeValue, // FL: revisit
-    const PAF_AST_Params *pP,
-    const PAF_AST_Patchs *pQ
+    const PAF_ASDT_Params *pP,
+    const PAF_ASDT_Patchs *pQ
 )
 {
+    PAF_ASDT_Config *pC;            /* Local configuration pointer */
+    PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
     Int as;                         /* Audio Stream Number (1, 2, etc.) */
     Int z;                          /* input/encode/stream/decode/output counter */
     Int i;                          /* phase */
@@ -134,7 +139,7 @@ Void taskAsdpFxn(
     Int size;
     Int argIdx;
     // Decoder output circular buffer
-    PAF_DecodeOpCircBuf *pCb;
+    PAF_AST_DecOpCircBuf *pCb;
     PAF_AudioFrame *pAfWrt;
     Int cbErrno;    
     // Messaging
@@ -164,6 +169,12 @@ Void taskAsdpFxn(
         return;
     }    
 
+    //
+    // Audio Framework Configuration (*pC):
+    //
+    pC = &gPAF_ASDT_config;
+    pAstCfg = pC->pAstCfg;
+
     // wait for initialization message from master
     do {
         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
@@ -180,27 +191,23 @@ Void taskAsdpFxn(
     gSlaveStartCnt++;
     TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
 
-    Cache_inv(&gPAF_AST_config, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
-    Cache_inv(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
+    Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
+    // FL: no need to share this pointer, can be local
+    //Cache_inv(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
     Cache_wait();
-    if (!pC)
-    {
-        TRACE_TERSE0("TaskAsdp: No Configuration defined. Exiting.");
-        LINNO_RPRT(TaskAsdp, -1);
-        return;
-    }
     
     // (***) FL: revisit
     // invalidate Dec configuration
-    Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+    Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
     Cache_wait();
 
     // (***) FL: revisit
     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
     Cache_wait();
 
-    // Audio Framework Configuration (*pC):
-    as = pC->as; // obtain audio stream number
+    /* Obtain Audio Stream Number (1, 2, etc.) */
+    as = pAstCfg->as;
+    TRACE_TERSE1("TaskAsdp: Started with AS%d.", as);
     
     //
     // Initialize message log trace and line number reporting
@@ -212,8 +219,8 @@ Void taskAsdpFxn(
     LINNO_RPRT(TaskAsdp, -1);
 
     // Get decoder and stream index associated with the master input
-    zMD = pC->masterDec;
-    zMS = pC->masterStr;
+    zMD = pAstCfg->masterDec;
+    zMS = pAstCfg->masterStr;
 
     // 
     // Initialize per parameterized phases.
@@ -221,6 +228,10 @@ Void taskAsdpFxn(
     //   - Common: Common Algorithm Initialization
     //   - AlgKey: Dec/Enc chain to Array Initialization
     //   - Unused: (available)
+    //   - Unused: (available)
+    //   - Unused: (available)
+    //   - Unused: (available)
+    //   - Unused: (available)
     //
     LINNO_RPRT(TaskAsdp, -2);
     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
@@ -249,14 +260,14 @@ Void taskAsdpFxn(
     {
         pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
     }
-
+    
     // (***) FL: revisit
     // write back Status structure addresses for Beta Units initialized on Slave
     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
-    //Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
-    //Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
+    Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
+    Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_wait();
     
     // (***) FL: revisit
@@ -267,15 +278,15 @@ Void taskAsdpFxn(
     Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
     Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
-    //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
-    //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
-    //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
-    //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
+    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
+    Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
+    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
+    Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
     Cache_wait();
 
     // (***) FL: revisit
     // write back Dec configuration
-    Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+    Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
     Cache_wait();
     
     // Send initialization complete message to master
@@ -318,9 +329,9 @@ Void taskAsdpFxn(
         
         for (z=DECODE1; z < DECODEN; z++)
         {
-            alg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
+            alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
         }
-        alg[zMD] = pC->xDec[zMD].decAlg[sourceSelect];
+        alg[zMD] = pAstCfg->xDec[zMD].decAlg[sourceSelect];
 
         // FL: debug, reset IB capture buffer
         //capIbReset();
@@ -416,24 +427,36 @@ Void taskAsdpFxn(
                     
                     // (***) FL: revisit
                     // invalidate Status structures for shared Beta Units
-                    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
-                    Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
+                    //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
+                    //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
                     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
+                    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
+                    Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
                     Cache_wait();
                     
                     argIdx = 0; // get decIdx
                     z = *(Int32 *)&pAspMsg->buf[argIdx];
                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
                     
+                    // invalidate Dec configuration
+                    Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_wait();
+                    
                     if (alg[z]->fxns->algActivate)
                     {
                         alg[z]->fxns->algActivate(alg[z]);
                     }
 
                     // Start writes to circular buffer
-                    pCb = &pC->xDec[z].decOpCb;
-                    cbWriteStart(pCb);
+                    pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStart(pCb);
+                    if (cbErrno < 0)
+                    {
+                        SW_BREAKPOINT;
+                    }
+                    // FL: debug, log circular buffer control variables
+                    cbLog(pCb, 1, "cbWriteStart");
                     // Reset audio frame
                     resetAf(pP, z, sourceSelect);
                     
@@ -464,15 +487,21 @@ Void taskAsdpFxn(
                     errno = 0;
                     if (dec->fxns->reset)
                     {
-                        errno = dec->fxns->reset(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
+                        errno = dec->fxns->reset(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
                     }
 
+                    // write back Dec configuration
+                    Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_wait();            
+
                     // (***) FL: revisit
                     // write back Status structures for shared Beta Units
-                    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
-                    Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
+                    //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
+                    //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
                     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
                     Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
+                    size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
+                    Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
                     Cache_wait();
                     
                     // send dec reset complete message to master
@@ -504,9 +533,9 @@ Void taskAsdpFxn(
                     
                     // (***) FL: revisit
                     // invalidate Inp configuration
-                    Cache_inv(&gPAF_AST_config.xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
+                    Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
                     // invalidate input data
-                    pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
+                    pIpBufConfig = &pAstCfg->xInp[zI].inpBufConfig;
                     size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
                     if (sourceSelect == PAF_SOURCE_PCM)
                     {
@@ -514,7 +543,7 @@ Void taskAsdpFxn(
                     }
                     Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
                     // invalidate Dec configuration
-                    Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
                     // status for selected decoder should be invalidated
                     Cache_wait();
             
@@ -522,16 +551,16 @@ Void taskAsdpFxn(
                     errno = 0;
                     if (dec->fxns->info)
                     {
-                        errno = dec->fxns->info(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
+                        errno = dec->fxns->info(dec, NULL, &pAstCfg->xDec[z].decodeControl, &pAstCfg->xDec[z].decodeStatus);
                     }
                     
                     // write back Dec configuration
-                    Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
                     Cache_wait();            
                     
                     // Re-initialize audio frame if decoder is disabled or 
                     // doesn't have a valid input 
-                    if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
+                    if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
                     {
                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
                     }
@@ -567,7 +596,7 @@ Void taskAsdpFxn(
                     resetAfSamsiz(z);
                     
                     // invalidate Dec configuration
-                    Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
                     Cache_wait();
                     //TRACE_TERSE0("Dec:cache wb done");
             
@@ -579,9 +608,9 @@ Void taskAsdpFxn(
                     if (dec->fxns->decode)
                     {
                         // FL: debug, capture input buffer
-                        //capIb(pC->xInp[z].pInpBuf);
+                        //capIb(pAstCfg->xInp[z].pInpBuf);
                     
-                        errno = dec->fxns->decode(dec, NULL, &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct);
+                        errno = dec->fxns->decode(dec, NULL, &pAstCfg->xDec[z].decodeInStruct, &pAstCfg->xDec[z].decodeOutStruct);
                         if (errno < 0)
                         {
                             SW_BREAKPOINT;
@@ -589,10 +618,10 @@ Void taskAsdpFxn(
                         //TRACE_TERSE0("Dec:decode done");
                         
                         // copy decoder output to decoder output circular buffers
-                        pCb = &pC->xDec[z].decOpCb;
+                        pCb = &pAstCfg->xDecOpCb[z];
                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
                         
-                        pAfWrt = pC->xDec[z].decodeOutStruct.pAudioFrame;
+                        pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
                         //TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
                         
@@ -610,16 +639,16 @@ Void taskAsdpFxn(
                         //TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
                         // FL: debug, log circular buffer control variables
-                        cbLog(pCb, 0);
+                        cbLog(pCb, 1, "cbWriteAf");
                     }
                     
                     // write back Dec configuration
-                    Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+                    Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
                     Cache_wait();
                     
                     // Re-initialize audio frame if decoder is disabled or 
                     // doesn't have a valid input 
-                    if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
+                    if (!pAstCfg->xDec[z].decodeStatus.mode || !pAstCfg->xInp[zI].hRxSio)
                     {
                         pP->fxns->initFrame1(pP, pQ, pC, z, 0);
                     }
@@ -657,8 +686,14 @@ Void taskAsdpFxn(
                     }
                     
                     // Stop writes to circular buffer
-                    pCb = &pC->xDec[z].decOpCb;
-                    cbWriteStop(pCb);
+                    pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStop(pCb);
+                    if (cbErrno < 0)
+                    {
+                        SW_BREAKPOINT;
+                    }
+                    // FL: debug, log circular buffer control variables
+                    cbLog(pCb, 1, "cbWriteStop");
                     
                     // send dec deactivate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
@@ -702,16 +737,21 @@ Void taskAsdpFxn(
 //
 Int
 PAF_ASDT_initPhaseMalloc(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC
 )
 {
-    Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
-    Int zMS = pC->masterStr;
-    Error_Block    eb;
-
-    TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: initialization phase - memory allocation", as+zMS);
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int zMS;
+    Error_Block eb;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;
+    
+    TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
 
     // Initialize error block
     Error_init(&eb); 
@@ -719,15 +759,16 @@ PAF_ASDT_initPhaseMalloc(
     if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL1,
         DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
     {
-        TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: Memory_calloc failed", as+zMS);
+        TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
         SW_BREAKPOINT;
         return __LINE__;
     }
-    TRACE_TERSE3("PAF_AST_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
+    TRACE_TERSE3("PAF_ASDT_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
             DECODEN * sizeof (PAF_AudioFrame),
             HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
 
-    TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: initialization phase - memory allocation complete.", as+zMS);
+    TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
+    TRACE_TERSE1("PAF_ASDT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
     return 0;
 } //PAF_ASDT_initPhaseMalloc
 
@@ -748,21 +789,31 @@ PAF_ASDT_initPhaseMalloc(
 
 Int
 PAF_ASDT_initPhaseConfig(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC
 )
 {
+    PAF_AST_Config *pAstCfg;
+    Int as;                    /* Audio Stream Number (1, 2, etc.) */
+    Int zMS;
     Int z;
 
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;
+    
+    TRACE_TERSE1("PAF_ASDT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
+
     // overwrite pointer to audio frame in framework decode control
     for (z=DECODE1; z < DECODEN; z++) 
     {
-        //Int zS = pP->streamsFromDecodes[z]; // FL: slave
-        //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; // FL: slave
-        //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; // FL: slave        
-        pC->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
-        pC->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
+        //Int zS = pP->streamsFromDecodes[z]; // FL: formerly on master
+        //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
+        //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; FL: formerly on master
+        pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
+        pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
+        pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
         pP->fxns->initFrame0(pP, pQ, pC, z);
     }
 
@@ -786,94 +837,46 @@ PAF_ASDT_initPhaseConfig(
 //
 Int
 PAF_ASDT_initPhaseAcpAlg(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC
 )
 {
-    Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
-    Int z;                              /* input/encode/stream/decode/output */
-                                        /* counter                           */
+    PAF_AST_Config *pAstCfg;
+    Int as;                    /* Audio Stream Number (1, 2, etc.) */
+    Int z;                     /* input/encode/stream/decode/output counter */
     Int betaPrimeOffset;
     ACP_Handle acp;
-    Int zMS = pC->masterStr;
+    Int zMS;
     Int zS; //, zX;
 
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;    
+
     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
 
     ACP_MDS_init();
 
-    if (!(acp = (ACP_Handle )ACP_MDS_create (NULL))) 
+    if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
     {
         TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
         return __LINE__;
     }
-    pC->acpSlave = acp;
+    pC->acp = acp;
 
     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
 
-#if 0 // FL: master
-    for (z=INPUT1; z < INPUTN; z++) 
-    {
-        zS = z;
-        for (zX = DECODE1; zX < DECODEN; zX++) 
-        {
-            if (pP->inputsFromDecodes[zX] == z) 
-            {
-                zS = pP->streamsFromDecodes[zX];
-                break;
-            }
-        }
-        acp->fxns->attach(acp, ACP_SERIES_STD,
-            STD_BETA_IB + betaPrimeOffset * (as-1+zS),
-            (IALG_Status *)&pC->xInp[z].inpBufStatus);
-        /* Ignore errors, not reported. */
-    }
-#endif
-
     for (z=DECODE1; z < DECODEN; z++) 
     {
         zS = pP->streamsFromDecodes[z];
         acp->fxns->attach(acp, ACP_SERIES_STD,
             STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
-            (IALG_Status *)&pC->xDec[z].decodeStatus);
+            (IALG_Status *)&pAstCfg->xDec[z].decodeStatus);
         /* Ignore errors, not reported. */
     }
 
-#if 0 // FL: master
-    for (z=ENCODE1; z < ENCODEN; z++) 
-    {
-        zS = pP->streamsFromEncodes[z];
-        acp->fxns->attach(acp, ACP_SERIES_STD,
-            STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
-            (IALG_Status *)&pC->xEnc[z].encodeStatus);
-        acp->fxns->attach(acp, ACP_SERIES_STD,
-            STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
-            (IALG_Status *)&pC->xEnc[z].volumeStatus);
-        /* Ignore errors, not reported. */
-    }
-#endif
-    
-#if 0 // FL: master
-    for (z=OUTPUT1; z < OUTPUTN; z++) 
-    {
-        zS = z;
-        for (zX = ENCODE1; zX < ENCODEN; zX++) 
-        {
-            if (pP->outputsFromEncodes[zX] == z) 
-            {
-                zS = pP->streamsFromEncodes[zX];
-                break;
-            }
-        }
-        acp->fxns->attach(acp, ACP_SERIES_STD,
-            STD_BETA_OB + betaPrimeOffset * (as-1+zS),
-            (IALG_Status *)&pC->xOut[z].outBufStatus);
-        /* Ignore errors, not reported. */
-    }
-#endif
-    
     TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
 
     return 0;
@@ -904,19 +907,24 @@ PAF_ASDT_initPhaseAcpAlg(
 
 Int
 PAF_ASDT_initPhaseCommon(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC
 )
 {
-    Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
-    Int z;                              /* stream counter */
-    //Int g;                              /* gear */
-    ACP_Handle acp = pC->acpSlave;
+    PAF_AST_Config *pAstCfg;
+    Int as;                         /* Audio Stream Number (1, 2, etc.) */
+    Int z;                          /* stream counter */
+    //Int g;                        /* gear */
+    ACP_Handle acp;
     PAF_IALG_Config pafAlgConfig;
     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
    
-    TRACE_TERSE0("PAF_AST_initPhaseCommonSlav: initialization phase - Common Algorithms");
+    acp = pC->acp; // get acp handle
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    
+    TRACE_TERSE0("PAF_ASDT_initPhaseCommon: initialization phase - Common Memory");
 
     //
     // Determine memory needs and instantiate algorithms across audio streams
@@ -955,18 +963,6 @@ PAF_ASDT_initPhaseCommon(
             }
         }
 
-#if 0 // FL: master
-        zE = -1;
-        for (zX = ENCODE1; zX < ENCODEN; zX++) 
-        {
-            if (pP->streamsFromEncodes[zX] == z) 
-            {
-                zE = zX;
-                break;
-            }
-        }
-#endif
-
         if (zD >= 0) 
         {
             TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
@@ -998,63 +994,6 @@ PAF_ASDT_initPhaseCommon(
             pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
 #endif
         
-#if 0 // FL: master
-        if (zE >= 0) 
-        {
-            TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC/ for encoder common[%d].", (IArg)__FUNCTION__, __LINE__, z);
-            if (PAF_ALG_ALLOC (encLinkInit[zE-ENCODE1], common[z])) 
-            {
-                TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed",
-                             as+z, (IArg)__FUNCTION__, __LINE__);
-                SW_BREAKPOINT;
-                return __LINE__;
-            }
-            TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
-            if(pP->fxns->allocPrint)
-                pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
-        }
-#endif
-
-        //
-        // Determine common memory needs of Logical IO drivers
-        //
-
-#if 0 // FL: master
-        // really need to loop over all inputs for this stream using the tables
-        // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
-        // patch, and not needed for FS11, since there is only one input.
-        if (INPUT1 <= z && z < INPUTN) 
-        {
-            TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: alloc inpLinkInit common[%d]", as+z, __LINE__, z);
-            if (PAF_ALG_ALLOC (inpLinkInit[z-INPUT1], common[z])) 
-            {
-                TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
-                TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
-                SW_BREAKPOINT;
-                return __LINE__;
-            }
-            TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
-            if(pP->fxns->allocPrint)
-                pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
-        }
-#endif        
-
-#if 0 // FL: master
-        if (OUTPUT1 <= z && z < OUTPUTN) 
-        {
-            TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC outLinkInit common[%d].", (IArg)__FUNCTION__, __LINE__, z);
-            if (PAF_ALG_ALLOC (outLinkInit[z-OUTPUT1], common[z])) 
-            {
-                TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
-                TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
-                SW_BREAKPOINT;
-                return __LINE__;
-            }
-            TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
-            if(pP->fxns->allocPrint)
-                pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
-        }
-#endif        
     }
     {
         // Changes made to share scratch between zones
@@ -1088,18 +1027,6 @@ PAF_ASDT_initPhaseCommon(
            }
         }
 
-#if 0 // FL: master
-        zE = -1;
-        for (zX = ENCODE1; zX < ENCODEN; zX++) 
-        {
-           if (pP->streamsFromEncodes[zX] == z) 
-           {
-               zE = zX;
-               break;
-           }
-        }
-#endif
-
         TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
         if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig)) 
         {
@@ -1122,12 +1049,12 @@ PAF_ASDT_initPhaseCommon(
             PAF_ASP_Chain *chain;
             TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
             chain =
-                PAF_ASP_chainInit (&pC->xDec[zD].decChainData, pP->pChainFxns,
+                PAF_ASP_chainInit (&pAstCfg->xDec[zD].decChainData, pP->pChainFxns,
                                    HEAP_INTERNAL, as+z, acp, &trace,
                                    decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
             if (!chain) 
             {
-                TRACE_TERSE1("AS%d: Decode chain initialization failed", as+z);
+                TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Decode chain initialization failed", as+z);
                 return __LINE__;
             }
         }
@@ -1152,59 +1079,6 @@ PAF_ASDT_initPhaseCommon(
         }
 #endif
 
-#if 0 // FL: master
-        if (zE >= 0) 
-        {
-            PAF_ASP_Chain *chain;
-            TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for encode.", (IArg)__FUNCTION__, __LINE__);
-            chain =
-                PAF_ASP_chainInit (&pC->xEnc[zE].encChainData, pP->pChainFxns,
-                                   HEAP_INTERNAL, as+z, acp, &trace,
-                                   encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
-            if (!chain) 
-            {
-                TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
-                return __LINE__;
-            }
-        }
-#endif
-
-#if 0 // FL: master
-        //
-        // Allocate non-common memories for Logical IO drivers
-        //    Since these structures are used at run-time we allocate from external memory
-        if (INPUT1 <= z && z < INPUTN) 
-        {
-            PAF_ASP_Chain *chain;
-            TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common input chain init for %d",
-                           as+z, __LINE__, z);
-            chain = PAF_ASP_chainInit (&pC->xInp[z].inpChainData, pP->pChainFxns,
-                    HEAP_EXTERNAL, as+z, acp, &trace,
-                    inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
-            if (!chain) 
-            {
-                TRACE_TERSE1("AS%d: Input chain initialization failed", as+z);
-                return __LINE__;
-            }
-        }
-#endif        
-
-#if 0 // FL: master
-        if (OUTPUT1 <= z && z < OUTPUTN) 
-        {
-            PAF_ASP_Chain *chain;
-            TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common output chain init for %d",
-                           as+z, __LINE__, z);
-            chain = PAF_ASP_chainInit (&pC->xOut[z].outChainData, pP->pChainFxns,
-                    HEAP_EXTERNAL, as+z, acp, &trace,
-                    outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
-            if (!chain) 
-            {
-                TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
-                return __LINE__;
-            }
-        }
-#endif        
     }
     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
 
@@ -1227,62 +1101,55 @@ PAF_ASDT_initPhaseCommon(
 // .............................................................................
 Int
 PAF_ASDT_initPhaseAlgKey(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC
 )
 {
-    Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
-    Int z;                              /* decode/encode counter */
-    Int s;                              /* key number */
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* decode/encode counter */
+    Int s;                      /* key number */
     PAF_ASP_Link *that;
 
     (void)as;  // clear warning.
 
-    TRACE_VERBOSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Algorithm Keys", as);
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    
+    TRACE_VERBOSE1("PAF_ASDT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
 
     for (z=DECODE1; z < DECODEN; z++) 
     {
         for (s=0; s < pP->pDecAlgKey->length; s++) 
         {
             if ((pP->pDecAlgKey->code[s].full != 0)
-                && (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
+                && (that = PAF_ASP_chainFind (&pAstCfg->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
             {
-                pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
+                pAstCfg->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
                     /* Cast in interface, for now --Kurt */
             }
             else
-                pC->xDec[z].decAlg[s] = NULL;
-        }
-    }
-
-#if 0 // FL: master
-    for (z=ENCODE1; z < ENCODEN; z++) 
-    {
-        for (s=0; s < pP->pEncAlgKey->length; s++) 
-        {
-            if (pP->pEncAlgKey->code[s].full != 0
-                && (that = PAF_ASP_chainFind (&pC->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
-                pC->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
-            /* Cast in interface, for now --Kurt */
-            else
-                pC->xEnc[z].encAlg[s] = NULL;
+                pAstCfg->xDec[z].decAlg[s] = NULL;
         }
     }
-#endif    
 
     return 0;
 } //PAF_AST_initPhaseAlgKey
 
+//   Purpose:   Audio Stream Decode Task Function for initialization of the Audio
+//              Frame(s) by memory allocation and loading of data pointers
+//              and values.
 Int
 PAF_ASDT_initFrame0(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC, 
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC, 
     Int z
 )
 {
-    Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
+    PAF_AST_Config *pAstCfg;
+    Int as;                    /* Audio Stream Number (1, 2, etc.) */
     Int aLen;
     Int aSize = sizeof(PAF_AudioData);
     Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
@@ -1293,6 +1160,9 @@ PAF_ASDT_initFrame0(
     PAF_AudioFrame *pAudioFrame;
     Int i;
 
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+
     pAudioFrame = &gpDecAudioFrame[z];
     if (pAudioFrame == NULL)
     {
@@ -1334,7 +1204,7 @@ PAF_ASDT_initFrame0(
     {
         if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
         {
-            TRACE_TERSE2("AS%d: %s: MEM_calloc failed", as+z, (IArg)__FUNCTION__);
+            TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
             TRACE_TERSE2("  maxFrameLength: %d.  aLen*aSize: %d", maxFrameLength, aLen*aSize);
             SW_BREAKPOINT;
             return __LINE__;
@@ -1424,9 +1294,9 @@ PAF_ASDT_initFrame0(
 //
 Int
 PAF_ASDT_initFrame1(
-    const PAF_AST_Params *pP, 
-    const PAF_AST_Patchs *pQ, 
-    PAF_AST_Config *pC, 
+    const PAF_ASDT_Params *pP, 
+    const PAF_ASDT_Patchs *pQ, 
+    PAF_ASDT_Config *pC, 
     Int z, 
     Int apply
 )
@@ -1466,7 +1336,7 @@ PAF_ASDT_initFrame1(
 
 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
 Int resetAf(
-    const PAF_AST_Params *pP, 
+    const PAF_ASDT_Params *pP, 
     Int z, 
     Int sourceSelect
 )