]> 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
Add support for DDR shared heap. Note:algs use IALG_EXTERNAL_SHM, which is IALG_ESDATA.
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_arm / framework / audioStreamDecodeProc.c
index ceb9ea9d01277bd699f1b6d93a16e5d333b90747..7a7c0c8c874496a02d756d89e11bdaf96c2a5035 100644 (file)
@@ -57,7 +57,7 @@ All rights reserved.
 #include "common.h"
 #include "aspMsg_common.h"
 #include "aspMsg_slave.h"
-#include "paf_decOpCircBuf.h"
+#include "aspDecOpCircBuf_slave.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamDecodeProc.h"
 
@@ -74,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];
@@ -85,15 +82,27 @@ 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,               // acp
+    {NULL, NULL},       // decOpCircBufCtl
+    &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
+};
 
 PAF_AudioFrame *gpDecAudioFrame=NULL;
 PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
-// Debug counters
+// Underflow threshold before returning error to Top-Level FSM
+#define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
+UInt32 gDecOpCbWrtAfOvr  =0; // decoder output circular buffer overflow count
+
+// Global debug counters */
 UInt32 gSlaveStartErrCnt        =0;
 UInt32 gSlaveStartCnt           =0;
 UInt32 gSlaveSourceSelectCnt    =0;
@@ -113,10 +122,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 */
@@ -133,7 +144,8 @@ Void taskAsdpFxn(
     Int size;
     Int argIdx;
     // Decoder output circular buffer
-    PAF_DecodeOpCircBuf *pCb;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    //PAF_AST_DecOpCircBuf *pCb;
     PAF_AudioFrame *pAfWrt;
     Int cbErrno;    
     // Messaging
@@ -163,6 +175,13 @@ Void taskAsdpFxn(
         return;
     }    
 
+    //
+    // Audio Framework Configuration (*pC):
+    //
+    pC = &gPAF_ASDT_config;
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration 
+    pCbCtl = &pC->decOpCircBufCtl; // get pointer to circular buffer control
+
     // wait for initialization message from master
     do {
         status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
@@ -179,27 +198,25 @@ 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);
+    // invalidate AST shared configuration
+    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);
+    // invalidate Dec configuration for all Decoder zones
+    Cache_inv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
     Cache_wait();
 
     // (***) FL: revisit
+    // invalidate Beta Table status pointers
     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
@@ -211,15 +228,19 @@ 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.
+    //   - Malloc: Memory Allocation
+    //   - Config: Configuration Initialization
     //   - AcpAlg: ACP Algorithm Initialization and Local Attachment
     //   - Common: Common Algorithm Initialization
     //   - AlgKey: Dec/Enc chain to Array Initialization
     //   - Unused: (available)
+    //   - Unused: (available)
+    //   - Unused: (available)
     //
     LINNO_RPRT(TaskAsdp, -2);
     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
@@ -274,7 +295,7 @@ Void taskAsdpFxn(
 
     // (***) 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
@@ -317,9 +338,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();
@@ -428,7 +449,8 @@ Void taskAsdpFxn(
                     TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, 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();
                     
                     if (alg[z]->fxns->algActivate)
                     {
@@ -436,14 +458,14 @@ Void taskAsdpFxn(
                     }
 
                     // Start writes to circular buffer
-                    pCb = &pC->xDec[z].decOpCb;
-                    cbErrno = cbWriteStart(pCb);
+                    //pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStart(pCbCtl, z);
                     if (cbErrno < 0)
                     {
                         SW_BREAKPOINT;
                     }
                     // FL: debug, log circular buffer control variables
-                    cbLog(pCb, 1, "cbWriteStart");
+                    cbLog(pCbCtl, z, 1, "cbWriteStart");
                     // Reset audio frame
                     resetAf(pP, z, sourceSelect);
                     
@@ -474,11 +496,11 @@ 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(&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();            
 
                     // (***) FL: revisit
@@ -520,9 +542,10 @@ 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);
+                    Cache_wait();
                     // 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)
                     {
@@ -530,7 +553,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();
             
@@ -538,16 +561,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);
                     }
@@ -583,7 +606,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");
             
@@ -595,21 +618,21 @@ 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;
                         }
-                        //TRACE_TERSE0("Dec:decode done");
+                        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;
-                        //TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
+                        pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
+                        TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
                         //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
                         
                         // FL: debug, capture audio frame
@@ -618,24 +641,40 @@ Void taskAsdpFxn(
                         //    Log_info0("capAfWrite() error");
                         //}                        
 
-                        cbErrno = cbWriteAf(pCb, pAfWrt);
+                        cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if (cbErrno < 0)
                         {
-                            SW_BREAKPOINT;
+                            SW_BREAKPOINT; // FL: debug
+                            
+                            if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
+                            {
+                                // Reset circular buffer
+                                cbReset(pCbCtl, z);
+                                // Update underflow count, return if above threshold
+                                gDecOpCbWrtAfOvr++;
+                                if (gDecOpCbWrtAfOvr < DEC_OP_CB_WRTAF_OVR_THR)
+                                {
+                                    cbErrno = 0;
+                                }
+                                else 
+                                {
+                                    gDecOpCbWrtAfOvr = 0;
+                                }
+                            }
                         }
-                        //TRACE_TERSE0("Dec:cbWriteAf() complete");
+                        TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
                         // FL: debug, log circular buffer control variables
-                        cbLog(pCb, 1, "cbWriteAf");
+                        cbLog(pCbCtl, z, 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);
                     }
@@ -673,14 +712,14 @@ Void taskAsdpFxn(
                     }
                     
                     // Stop writes to circular buffer
-                    pCb = &pC->xDec[z].decOpCb;
-                    cbErrno = cbWriteStop(pCb);
+                    //pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStop(pCbCtl, z);
                     if (cbErrno < 0)
                     {
                         SW_BREAKPOINT;
                     }
                     // FL: debug, log circular buffer control variables
-                    cbLog(pCb, 1, "cbWriteStop");
+                    cbLog(pCbCtl, z, 1, "cbWriteStop");
                     
                     // send dec deactivate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
@@ -724,15 +763,20 @@ 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;
-
+    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
@@ -771,22 +815,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: 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
-        pC->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
-        pC->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
-        pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
+        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);
     }
 
@@ -810,94 +863,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;
@@ -928,19 +933,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_ASDT_initPhaseCommon: 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
@@ -952,6 +962,7 @@ PAF_ASDT_initPhaseCommon(
         HEAP_ID_INTERNAL1,      HEAP_INTERNAL1, 
         HEAP_ID_EXTERNAL,       HEAP_EXTERNAL, 
         HEAP_ID_INTERNAL1_SHM,  HEAP_INTERNAL1_SHM, 
+        HEAP_ID_EXTERNAL_SHM,   HEAP_EXTERNAL_SHM, 
         HEAP_CLEAR);
 
     if (pP->fxns->headerPrint)
@@ -979,18 +990,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);
@@ -1022,63 +1021,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
@@ -1112,18 +1054,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)) 
         {
@@ -1146,7 +1076,7 @@ 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) 
@@ -1176,59 +1106,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);
 
@@ -1251,18 +1128,22 @@ 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.
 
+    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++) 
@@ -1270,43 +1151,32 @@ PAF_ASDT_initPhaseAlgKey(
         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;
+                pAstCfg->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;
-        }
-    }
-#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;
@@ -1317,6 +1187,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)
     {
@@ -1448,9 +1321,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
 )
@@ -1490,7 +1363,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
 )
@@ -1513,18 +1386,19 @@ Int resetAf(
     pAudioFrame->sampleCount = 0;
     pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
     
-    if (sourceSelect == PAF_SOURCE_PCM)
-    {
-        pAudioFrame->data.nSamples = FRAMELENGTH;
-    }
-    else if (sourceSelect == PAF_SOURCE_DDP)
+    switch (sourceSelect)
     {
-        pAudioFrame->data.nSamples = 1536;        
+        case PAF_SOURCE_PCM:
+            pAudioFrame->data.nSamples = FRAMELENGTH;
+            break;
+        case PAF_SOURCE_AC3:
+        case PAF_SOURCE_DDP:
+            pAudioFrame->data.nSamples = 1536;
+            break;
+        default:  
+            pAudioFrame->data.nSamples = FRAMELENGTH;
+            break;
     }
-    else
-    {
-        pAudioFrame->data.nSamples = FRAMELENGTH;
-    }   
 
     // Reset audio frame channel pointers
     for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)