Merge branch 'dev_pasdk_frank_pasdk516AsotRefactoring' into dev_pasdk_pasdk29Integration
authorFrank Livingston <frank-livingston@ti.com>
Fri, 16 Feb 2018 23:02:23 +0000 (17:02 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Fri, 16 Feb 2018 23:02:23 +0000 (17:02 -0600)
38 files changed:
pasdk/common/aspDecOpCircBuf_common.h
pasdk/common/aspOutInitSync_common.c
pasdk/common/dbgDib.c
pasdk/common/fwkPort.c
pasdk/common/paf_alg_malloc.c
pasdk/common/paf_alg_print.c
pasdk/paf
pasdk/test_arm/application/board_utils.c
pasdk/test_arm/application/main.c
pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_arm/framework/itopo/params.c
pasdk/test_arm/framework/itopo/patchs.c
pasdk/test_dsp/application/acp_main_cus.c
pasdk/test_dsp/application/app.cfg
pasdk/test_dsp/application/itopo/evmk2g/edma_cfg.c
pasdk/test_dsp/framework/alphaFuncProc.c
pasdk/test_dsp/framework/as0.c
pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
pasdk/test_dsp/framework/audioStreamInpDec.c
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamInpProc.h
pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
pasdk/test_dsp/framework/audioStreamOutDec.c
pasdk/test_dsp/framework/audioStreamOutDec.h [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutInit.c [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutInit.h [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutIo.c [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutIo.h [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutProc.c
pasdk/test_dsp/framework/audioStreamOutProc.h
pasdk/test_dsp/framework/audioStreamOutProcNewIO.c [deleted file]
pasdk/test_dsp/framework/audioStreamOutProc_paramsFxns.c
pasdk/test_dsp/framework/itopo/params.c
pasdk/test_dsp/framework/itopo/patchs.c
pasdk/test_dsp/framework/systemInit.c
pasdk/test_dsp/framework/systemStream.c
pasdk/test_dsp/mib/mib.c

index e84ecc872f81f5f08416d464ae2e23b9ad44f0a8..cea2d7239d3718957c2412b5a24805bcb1abe581 100644 (file)
@@ -155,8 +155,6 @@ typedef struct PAF_AST_DecOpCircBuf
     Int16 deltaSamps;                       // number of 256 (N) sample output frames to block reader
     Int8 afRdIdx;                           // audio frame CB read index
     Int8 afWrtIdx;                          // audio frame CB write index
-    //Int8 afLagIdx;                          // audio frame CB Lag idx,
-    //Int8 afInitialLag;                      // Initial delay/lag between CB write and read
     Int16 pcmRdIdx;                         // pcm buffer read index
     Int8 prvMdRdIdx;                        // private metadata read index
     Int8 numAfCb;                           // current number frames in CB
index bad31fc57c4c92c4f57f78dd633c77e273460c60..27e71f71608a1b78e7fa19cffcd059eca8963499 100644 (file)
@@ -97,7 +97,6 @@ Int outIsCtlInit(
 
 // Copy audio frame
 // See CPL_setAudioFrame_
-// (***) FL: Note similar functionality present in CB, check usage there.
 Void outIsCpyAf(
     PAF_AudioFrame *pSrcAf,
     PAF_AudioFrame *pDstAf
index fbe0dd2cda8e0f7c80793e11b9aad896df6549c3..5eeb64261c405832034af85e9c67e0984df782cc 100644 (file)
@@ -220,16 +220,7 @@ Void capIb(
     UInt32 nBytes, bufEnd, currentBufSize, chunkSize, wrapSize;
     
     nBytes = pInpBufConfig->frameLength * pInpBufConfig->sizeofElement;
-    
-#if 0
-    // FL: DDP debug
-    if (nBytes != 24576)
-    {
-        Log_info1("capIb(): nBytes=%d", nBytes);
-        gNumDiffFrame[gCapIbBufPingPongSel]++;
-    }
-#endif    
-    
+        
     bufEnd = (Int) pInpBufConfig->base.pVoid + pInpBufConfig->sizeofBuffer;
     currentBufSize = (bufEnd - (Int)pInpBufConfig->pntr.pSmInt);
 
index f3c59180e89a748b557ab4da3e32d78211ff8046..a492b7cd8ab0b859720d3f58803b02821e0b709f 100644 (file)
@@ -37,8 +37,6 @@ All rights reserved.
 
 #include "fwkPort.h"
 
-// FL: Temporary, 1st parameter for audioStream1Task().
-// FL: Need to remove first task parameter since SYS/BIOS 6.45 doesn't allow more than 2 parameters for a task.
 Int gBetaPrimeValue=0;
 
 far LoggerBuf_Struct trace;
index 86563a3e63fc5e70a8c00dfd54b8a609e532e492..910b3a592604ad5dfea09f80baeecf58a8a06212 100644 (file)
@@ -405,39 +405,39 @@ PAF_ALG_memSpaceToHeapId_ (
 {
     switch(space)
     {
-        case IALG_SARAM:    /* IALG_SARAM0 = IALG_SARAM :  Normally used for IRAM */ // FL: K2G: used for L2 on DSP
+        case IALG_SARAM:    // PASDK: DSP L2
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_SARAM (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->iHeapId;
 
-        case IALG_EXTERNAL: // normally external SDRAM // FL: K2G: used for DDR local memory
+        case IALG_EXTERNAL: // PASDK: DDR local memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_EXTERNAL (0x%x) 0x%x", __LINE__, space, p->eHeapId));
             return p->eHeapId;
 
-        case IALG_SARAM1: // FL: K2G: used for MSMC local memory
+        case IALG_SARAM1:   // PASDK: MSMC local memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_SARAM1 (0x%x) 0x%x", __LINE__, space, p->lHeapId));
             return p->lHeapId;
 
-        case IALG_SARAM2:  // FL: K2G: used for MSMC shared memory
+        case IALG_SARAM2:   // PASDK: MSMC shared memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_SARAM2 (IALG_SARAM_SHM) (0x%x) 0x%x", __LINE__, space, p->lHeapIdShm));
             return p->lHeapIdShm;
 
-        case IALG_DARAM0:   // Can't use this because it is zero and overridden
+        case IALG_DARAM0:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_DARAM0 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->iHeapId;
 
-        case IALG_DARAM1:   // not normally used.
+        case IALG_DARAM1:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_DARAM1 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->iHeapId;
 
-        case IALG_DARAM2:   // not normally used.
+        case IALG_DARAM2:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_DARAM2 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->iHeapId;    // not normally used.
 
-        case IALG_ESDATA:   // FL: K2G: used for DDR shared memory
+        case IALG_ESDATA:   // PASDK: DDR shared memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_ESDATA (IALG_EXTERNAL_SHM) (0x%x) 0x%x", __LINE__, space, p->eHeapIdShm));
             return p->eHeapIdShm;
 
-        case IALG_ENCSDATA:   // K2G: used for DDR shared non-cacheable memory
+        case IALG_ENCSDATA: // PASDK: DDR shared non-cacheable memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeapId_.%d: IALG_ENCSDATA (PAF_HEAP_ID_EXT_NON_CACHED_SHM) (0x%x) 0x%x", __LINE__, space, p->eHeapIdNCShm));
             return p->eHeapIdNCShm;
 
@@ -455,15 +455,15 @@ PAF_ALG_memSpaceToHeap_ (
 {
     switch(space)
     {
-        case IALG_SARAM:    /* IALG_SARAM0 = IALG_SARAM :  Normally used for IRAM. */ // FL: K2G: used for L2 on DSP
+        case IALG_SARAM:    // PASDK: DSP L2
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_SARAM (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->hIHeap;
 
-        case IALG_EXTERNAL: // normally external SDRAM // FL: K2G: used for DDR local memory
+        case IALG_EXTERNAL: // PASDK: DDR local memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_EXTERNAL (0x%x) 0x%x", __LINE__, space, p->eHeapId));
             return p->hEHeap;
 
-        case IALG_SARAM1:   // FL: K2G: used for MSMC local memory
+        case IALG_SARAM1:   // PASDK: MSMC local memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_SARAM1 (0x%x) 0x%x", __LINE__, space, p->lHeapId));
             return p->hLHeap;
 
@@ -471,23 +471,23 @@ PAF_ALG_memSpaceToHeap_ (
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_SARAM2 (IALG_SARAM_SHM) (0x%x) 0x%x", __LINE__, space, p->lHeapIdShm));
             return p->hLHeapShm;
 
-        case IALG_DARAM0:   // Can't use this because it is zero and overridden
+        case IALG_DARAM0:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_DARAM0 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->hIHeap;
 
-        case IALG_DARAM1:   // not normally used.
+        case IALG_DARAM1:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_DARAM1 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->hIHeap;
 
-        case IALG_DARAM2:   // not normally used.
+        case IALG_DARAM2:   // PASDK: not used
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_DARAM2 (0x%x) 0x%x", __LINE__, space, p->iHeapId));
             return p->hIHeap;    // not normally used.
 
-        case IALG_ESDATA:   // FL: K2G: used for DDR shared memory
+        case IALG_ESDATA:   // PASDK: DDR shared memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_ESDATA (0x%x) 0x%x", __LINE__, space, p->eHeapIdShm));
             return p->hEHeapShm;
 
-        case IALG_ENCSDATA:   // K2G: used for DDR shared non-cacheable memory
+        case IALG_ENCSDATA: // PASDK: DDR shared non-cacheable memory
             TRACE_GEN((&TR_MOD, "PAF_ALG_memSpaceToHeap_.%d: IALG_ENCSDATA (0x%x) 0x%x", __LINE__, space, p->eHeapIdNCShm));
             return p->hEHeapNCShm;
 
index aa105ab6460d19d993575e1932e354f1134b8c4a..47e969dc4672fcf40ac7bacfbc843a186bdc7de1 100644 (file)
@@ -83,12 +83,12 @@ PAF_ALG_allocPrint(const PAF_ALG_AllocInit *pInit, Int sizeofInit, PAF_IALG_Conf
                         (commonCount[memTab[i].attrs] ? memTab[i].alignment : 0);
                     commonCount[memTab[i].attrs]++;
                 }
-                // (***) FL: this is broken for printout of persistent memory
-                // The code was broken before addition of persist memory in INT1 SHM (MSMC).
-                // commonSize[] and commonCount[] are correct, but here persist is treated like common memory, i.e.
-                //     persistent memory is treated as through it's combined into a single memory space.
-                //     For example, printout can only show persist memory as belonging to one space.
-                //     This isn't true for persistent memory since it can be in multiple spaces.
+                // FL: This is broken for printout of persistent memory
+                //  The code was broken before addition of persist memory in INT1 SHM (MSMC).
+                //  commonSize[] and commonCount[] are correct, but here persist is treated like common memory, i.e.
+                //      persistent memory is treated as through it's combined into a single memory space.
+                //      For example, printout can only show persist memory as belonging to one space.
+                //      This isn't true for persistent memory since it can be in multiple spaces.
                 if (commonSpace[memTab[i].attrs] < (Int)memTab[i].space) 
                 {
                     commonSpace[memTab[i].attrs] = (Int)memTab[i].space;
index 6bbe169c2ad8e81412593cf2f879f08b04c47f76..6ae9257cdb624df7a5b2cd51d8ae22e32bd84658 160000 (submodule)
--- a/pasdk/paf
+++ b/pasdk/paf
@@ -1 +1 @@
-Subproject commit 6bbe169c2ad8e81412593cf2f879f08b04c47f76
+Subproject commit 6ae9257cdb624df7a5b2cd51d8ae22e32bd84658
index b7ec85b606280db933cacecba984af6204b8d2c4..6a417343f16a79f17166bbe8487c7d8484c0e606 100644 (file)
@@ -1,106 +1,6 @@
-// FL: Obtained this code from Ivan Pang, 
-//     https://bitbucket.itg.ti.com/projects/PROCESSOR-SDK/repos/board/browse/src/evmKeystone/board_utils.c
-//
-
-// FL: added this locally
 #include <xdc/std.h>
 #define uint32_t UInt32
 
-#if 0 // FL: remove everything but code for PMCR
-/**
- * @file   board_utils.c
- *
- * @brief  This file includes the Keystone board level functions
- */
-/*
- * Copyright (c) 2017, Texas Instruments Incorporated
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * *  Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * *  Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * *  Neither the name of Texas Instruments Incorporated nor the names of
- *    its contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ti/csl/csl_bootcfg.h>
-#include <ti/csl/csl_bootcfgAux.h>
-#if defined (_TMS320C6X)
-#include <ti/csl/csl_chipAux.h>
-#endif
-
-#include "board_utils.h"
-
-/**
-* \brief  This API gets the input clock frequency.
-*
-* \param  pll         PLL controller type.
-*
-* \return input clock to the PLL controller.
-*
-* \note   This API gets the input clock frequency based on the
-*         PLL controller type.\n
-*/
-/** ============================================================================
- *   @n@b BOARD_getExternalClk
- *
- *   @b Description
- *   @n  This function is used to get the exteranl clock frequency.
- *
- *
- *   @b Arguments
- *   @verbatim
-            pll             Specifies the PLL controller type.
-      @endverbatim
- *
- *   <b> Return Value </b>
- *   @n external clock frequency to the PLL controller, if 0, means failure
- *
- *   <b> Pre Condition </b>
- *   @n  None
- *
- *   <b> Post Condition </b>
- *   @n   None
- *
- *   @b Affects
- *   @n None.
- *
- *   @b Example
- *   @verbatim
-        uint32_t     ext_clk;
-
-        ext_clk = BOARD_getExternalClk(CSL_PLL_SYS);
-
-    @endverbatim
- * ===========================================================================
- */
-uint32_t BOARD_getExternalClk(CSL_PllcType pll)
-{
-    return Board_ext_clk[pll];
-}
-#endif
-
 /** ============================================================================
  *   @n@b BOARD_initPerfCounters
  *
@@ -157,7 +57,6 @@ void BOARD_initPerfCounters()
 #endif
 }
 
-//static uint32_t readTime32(void) // FL: static function??
 uint32_t readTime32(void)
 {
     uint32_t timeVal;
@@ -169,64 +68,3 @@ uint32_t readTime32(void)
 #endif
     return timeVal;
 }
-
-#if 0 // FL: remove everything but code for PMCR
-/** ============================================================================
- *   @n@b BOARD_delay
- *
- *   @b Description
- *   @n  This function delays a certain period of time in micro seconds.
- *
- *
- *   @b Arguments
- *   @verbatim
-            usecs           Specifies the time to delay in micro second.
-      @endverbatim
- *   @n To prevent 32-bit counter roll over, the delay time should be less than 2^32/freq_in_mhz (usec)
- *      e.g. for 1000Mhz PLL clock, delay time should be less than ~4.2 seconds.
- *
- *   <b> Return Value </b>
- *   @n None
- *
- *   <b> Pre Condition </b>
- *   @n  None
- *
- *   <b> Post Condition </b>
- *   @n   None
- *
- *   @b Affects
- *   @n None.
- *
- *   @b Example
- *   @verbatim
-        uint32_t     delay = 5;
-
-        BOARD_delay(delay);
-
-    @endverbatim
- * ===========================================================================
- */
-void BOARD_delay(uint32_t usecs)
-{
-    uint32_t ext_clk, freq, start, delayCount;
-    CSL_PllcType pllType;
-
-#if defined (_TMS320C6X)
-    pllType = CSL_PLL_SYS;
-    CSL_chipWriteTSCL(0);
-#else
-#if defined(SOC_K2E)
-    pllType = CSL_PLL_SYS;
-#else
-    pllType = CSL_PLL_ARM;
-#endif
-#endif
-
-    start = readTime32();
-    ext_clk = BOARD_getExternalClk(pllType);
-    freq = CSL_BootCfgGetPllFreq(pllType, ext_clk);
-
-    delayCount = usecs * (freq / 1000000);
-    while ((readTime32() - start) < delayCount);
-}
-#endif
index f6f7a0ec0625290d36a15d0addfe1655fd293357..031319fefd54b8edf5cbbb5a6152679de6409539 100644 (file)
@@ -56,8 +56,6 @@ All rights reserved.
 #include <ti/sysbios/heaps/HeapMem.h>
 // Number of control bytes used in heap buffer after heap initialized by SYSBIOS before main()
 #define HEAP_CONTROL_SZ ( 8 )
-// ARM open loop delay count
-#define OPEN_LOOP_DELAY_CNT ( 10000000 )
 
 extern void BOARD_initPerfCounters();
 extern uint32_t readTime32(void);
@@ -76,11 +74,11 @@ Int main()
     
     Log_info0("Enter main()");
 
-    // (***) FL: clear ARM dedicated heap buffers
-    // Temporary workaround to avoid including 0's in ARM image.
-    // If heaps aren't cleared:
-    //   1) DSP:ASIT: IPC state is corrupted because of incorrect memory segments for PCM2, DDP2 & THD2 beta table entries.
-    //   2) DSP:ASIT: DSP hangs in GateMP_open() inside first call to statusOp_Init().
+    // FL: Temporary code for ARM image size reduction
+    //  Clear ARM dedicated heap buffers
+    //  If heaps aren't cleared:
+    //      1) DSP:ASIT: IPC state is corrupted because of incorrect memory segments for PCM2, DDP2 & THD2 beta table entries.
+    //      2) DSP:ASIT: DSP hangs in GateMP_open() inside first call to statusOp_Init().
     HeapMem_getExtendedStats(heapMemMsmcSram, &heapmem_stats);
     buf = (Ptr)heapmem_stats.buf+HEAP_CONTROL_SZ;
     size = (SizeT)heapmem_stats.size-HEAP_CONTROL_SZ;
index 45a59506304401b62495336cbfe04f50860ebe75..937d4f2a5c4a510c1f715552e4d8369fc2d23954 100644 (file)
@@ -54,39 +54,8 @@ static Void cbInitLastAfInfo(
 );
 
 
-#if 0 // FL: moved to common
-// Initialize circular buffer control
-Int cbCtlInit(
-    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
-    PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
-)
-{
-    GateMP_Handle gateHandle;
-    Int status;
-    
-    do {
-        status = GateMP_open(ASP_DECODE_CB_GATE_NAME, &gateHandle);
-    } while (status == GateMP_E_NOTFOUND);
-    if (status == GateMP_S_SUCCESS)
-    {
-        pCbCtl->gateHandle = gateHandle;
-    }
-    else
-    {
-        pCbCtl->gateHandle = NULL;
-        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
-    }
-    
-    pCbCtl->numCb = numCb;          // init number of circular buffers
-    pCbCtl->pXDecOpCb = pXDecOpCb;  // init base address of circular buffers
-    
-    return ASP_DECOP_CB_SOK;
-}
-#endif
-
 // debug
 //Int8 gCbInitDecWriteCnt=0;
-//Int8 gCbInitDecWriteThdCnt=0;
 
 /// Initialize circular buffer for Decoder writes
 Int cbInitDecWrite(
@@ -129,8 +98,6 @@ Int cbInitDecWrite(
     // Set input frame length
     pCb->decOpFrameLen = decOpFrameLen;
     
-    //pCb->afInitialLag = 0;  // default No lag
-    //pCb->afLagIdx = 0;
     // Initialize CB primed flag
     pCb->primedFlag = 0;
     // Initialize delta samples
@@ -146,7 +113,6 @@ Int cbInitDecWrite(
     {
         pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
         
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_PCM;
         pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM;
         
         pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
@@ -161,7 +127,6 @@ Int cbInitDecWrite(
     {
         pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_AAC;
 
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_PCM;
         pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_AAC;
 
         pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_AAC;
@@ -176,7 +141,6 @@ Int cbInitDecWrite(
     {
         pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_DDP;
         
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_DDP;
         pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_DDP;
         
         pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
@@ -189,12 +153,9 @@ Int cbInitDecWrite(
     }
     else if (sourceSelect == PAF_SOURCE_THD)
     {
-        //gCbInitSourceSelThdCnt++; //debug
-        
         pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD;
         
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_THD;
-        // FL: (***) set nominal delay per sampling rate -- need to review these settings
+        // FL: set nominal delay per sampling rate -- these settings need to be reviewed
         switch (pDecInitAf->sampleRate)
         {
             case PAF_SAMPLERATE_44100HZ:
@@ -503,7 +464,6 @@ Int cbWriteStop(
 //Int32 gPcmOvershootWrap2=0;
 //Int32 gPcmOvershootNoWrap=0;
 
-// (***) FL: revisit
 // Write audio frame to circular buffer
 Int cbWriteAf(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
@@ -545,404 +505,357 @@ Int cbWriteAf(
     //Log_info1("cbWriteAf:afCb=0x%04x", (IArg)pCb->afCb); // debug
     //Log_info2("cbWriteAf:pCb->readerActiveFlag=%d, pCb->writerActiveFlag=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->writerActiveFlag); // debug
 
-    //if (pCb->readerActiveFlag == 1)
-    //{
-    //    //
-    //    // Normal case, reader active.
-    //    //
-        
-        if (pAfWrt->sampleCount != 0)
-        {
-            //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // debug
+    if (pAfWrt->sampleCount != 0)
+    {
+        //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // debug
 
-            // check AF overflow
-            if (pCb->numAfCb >= pCb->maxNumAfCb)
-            {
-                pCb->errAfOvrCnt++;
+        // check AF overflow
+        if (pCb->numAfCb >= pCb->maxNumAfCb)
+        {
+            pCb->errAfOvrCnt++;
 
-                //SW_BREAKPOINT;
-                Log_info1("cbWriteAf: ERROR: AF CB overflow, numAfCb=%d", pCb->numAfCb);
+            //SW_BREAKPOINT;
+            Log_info1("cbWriteAf: ERROR: AF CB overflow, numAfCb=%d", pCb->numAfCb);
 
-                // Write back circular buffer configuration
-                Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-                Cache_wait();
+            // Write back circular buffer configuration
+            Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+            Cache_wait();
 
-                // Leave the gate
-                GateMP_leave(gateHandle, key);
+            // Leave the gate
+            GateMP_leave(gateHandle, key);
 
-                //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // debug
+            //Log_info2("cbWriteAf:gate leave, gateHandle=0x%04x, key=%d", (IArg)gateHandle, (IArg)key); // debug
 
-                return ASP_DECOP_CB_AF_WRITE_OVERFLOW;
-            }
-            
-            // FL: this won't reliably detect overflow because of PCM buffer write address wrap
-            // check PCM overflow
-            //if ((pCb->numPcmSampsPerCh + pAfWrt->sampleCount) > pCb->maxNumPcmSampsPerCh)
-            //{
-            //    pCb->errPcmOvrCnt++;
-            //
-            //    Log_info3("cbWriteAf: ERROR: PCM CB overflow, sampleCount=%d, numPcmSampsPerCh=%d, maxNumPcmSampsPerCh=%d",
-            //        pCb->numPcmSampsPerCh, pAfWrt->sampleCount, pCb->maxNumPcmSampsPerCh);
-            //
-            //    // Write back circular buffer configuration
-            //    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-            //    Cache_wait();
+            return ASP_DECOP_CB_AF_WRITE_OVERFLOW;
+        }
+        
+        // get CB AF write info
+        pAfCb = &pCb->afCb[pCb->afWrtIdx];                      // get CB AF to be written
+        pPcmBufWrt = pAfCb->data.sample[0];                     // get current location in PCM buffer to be written
+        // currently no metadata buffer overflow detection
+        pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;         // get current location in MD buffer to be written
+        
+        // get CB AF read info
+        pAfCbRd = &pCb->afCb[pCb->afRdIdx];                     // get CB AF being read
+        pPcmBufRd = pAfCbRd->data.sample[0] + pCb->pcmRdIdx;    // current location of PCM samples for AF being read
+        
+        // Check PCM buffer overflow
+        pPcmBuf = pPcmBufWrt;
+        pcmOvr = 0;
+        for (i = 0; i < pCb->maxAFChanNum; i++)
+        {
             //
-            //    // Leave the gate
-            //    GateMP_leave(gateHandle, key);
+            // Writes of PCM to PCM CB use CC stream, but this isn't considered here.
+            // For each channel which *can* be written, check the current reader location won't be overwritten.
+            // The current reader location is the earliest channel which *could have been* written for that CB AF.
             //
-            //    return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
-            //}
-
-            // get CB AF write info
-            pAfCb = &pCb->afCb[pCb->afWrtIdx];                      // get CB AF to be written
-            pPcmBufWrt = pAfCb->data.sample[0];                     // get current location in PCM buffer to be written
-            // (***) FL: currently no metadata buffer overflow detection
-            pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;         // get current location in MD buffer to be written
-            
-            // get CB AF read info
-            pAfCbRd = &pCb->afCb[pCb->afRdIdx];                     // get CB AF being read
-            //pPcmBufRd = pAfCbRd->data.sample[0];                    // FL: starting location of PCM samples for AF being read
-            pPcmBufRd = pAfCbRd->data.sample[0] + pCb->pcmRdIdx;    // FL: current location of PCM samples for AF being read
-            
-            // Check PCM buffer overflow
-            pPcmBuf = pPcmBufWrt;
-            pcmOvr = 0;
-            for (i = 0; i < pCb->maxAFChanNum; i++)
+            if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
             {
-                //
-                // Writes of PCM to PCM CB use CC stream, but this isn't considered here.
-                // For each channel which *can* be written, check the current reader location won't be overwritten.
-                // The current reader location is the earliest channel which *could have been* written for that CB AF.
-                //
-                if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
-                {
-                    // this write will wrap
-                    
-                    // check OVR before wrap
-                    if ((pPcmBuf < pPcmBufRd) && 
-                        ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
-                    {
-                        pCb->errPcmOvrCnt++;
-                        //gPcmOvershootWrap1 = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
-                        pcmOvr = 1;
-                    }
-                    
-                    if (pcmOvr == 0)
-                    {
-                        // wrap pointer
-                        pPcmBuf = pCb->pcmBuf;   
-                        // check OVR after wrap
-                        if ((pPcmBuf < pPcmBufRd) && 
-                            ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
-                        {
-                            pCb->errPcmOvrCnt++;
-                            //gPcmOvershootWrap2 = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
-                            pcmOvr = 1;
-                        }                                                                
-                    }
-                }
-                else if ((pPcmBuf < pPcmBufRd) && 
+                // this write will wrap
+                
+                // check OVR before wrap
+                if ((pPcmBuf < pPcmBufRd) && 
                     ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
                 {
-                    // this write won't wrap
-                    
-                    //gPcmOvershootNoWrap = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
                     pCb->errPcmOvrCnt++;
+                    //gPcmOvershootWrap1 = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
                     pcmOvr = 1;
                 }
-                else
-                {
-                    // update pointer
-                    pPcmBuf += pAfWrt->sampleCount;                                        
-                }
                 
-                if (pcmOvr == 1)
+                if (pcmOvr == 0)
                 {
-                    Log_info2("cbWriteAf: ERROR: PCM CB overflow, sampleCount=%d, numPcmSampsPerCh=%d", 
-                         pAfWrt->sampleCount, pCb->numPcmSampsPerCh);
-            
-                    //SW_BREAKPOINT; // debug
-                    
-                    // Write back circular buffer configuration
-                    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-                    Cache_wait();
-            
-                    // Leave the gate
-                    GateMP_leave(gateHandle, key);
-            
-                    return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
+                    // wrap pointer
+                    pPcmBuf = pCb->pcmBuf;   
+                    // check OVR after wrap
+                    if ((pPcmBuf < pPcmBufRd) && 
+                        ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
+                    {
+                        pCb->errPcmOvrCnt++;
+                        //gPcmOvershootWrap2 = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
+                        pcmOvr = 1;
+                    }                                                                
                 }
             }
-            
-            // (***) FL: !!! REVISIT!!! 
-            //           Allocating memory for max # channels (e.g. 32 for THD).
-            //           GROSS over allocation for THD 192 kHz, 6ch max.
-            // configure AF sample pointers
-            pPcmBuf = pPcmBufWrt;
-            for (i = 0; i < pCb->maxAFChanNum; i++)
+            else if ((pPcmBuf < pPcmBufRd) && 
+                ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
             {
-                // check PCM buffer wrap
-                if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
-                {
-                    pPcmBuf = pCb->pcmBuf;
-                }
+                // this write won't wrap
                 
-                pAfCb->data.sample[i] = pPcmBuf;                
-                pPcmBuf += pAfWrt->sampleCount;
-                pAfCb->data.samsiz[i] = 0;
+                //gPcmOvershootNoWrap = pPcmBuf + pAfWrt->sampleCount - pPcmBufRd; // debug
+                pCb->errPcmOvrCnt++;
+                pcmOvr = 1;
             }
-            Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate??
-            Cache_wait();
-
-            // FL: brute force reset of all metadata in CB AF?
-            for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
+            else
             {
-                pAfCb->pafPrivateMetadata[i].offset = 0;
-                pAfCb->pafPrivateMetadata[i].size   = 0;
-                pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
-                pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
+                // update pointer
+                pPcmBuf += pAfWrt->sampleCount;                                        
             }
-
-#if 0 // FL: unused
-            nextWrtIdx = 0;
-            if ((pCb->afWrtIdx + 1) >= pCb->maxNumAfCb)
+            
+            if (pcmOvr == 1)
             {
-                //Log_info0("cbWriteAf: AF Wrap around **** ");
-                // next audio frame will be audio frame 0
-                nextWrtIdx = 0;
+                Log_info2("cbWriteAf: ERROR: PCM CB overflow, sampleCount=%d, numPcmSampsPerCh=%d", 
+                     pAfWrt->sampleCount, pCb->numPcmSampsPerCh);
+        
+                //SW_BREAKPOINT; // debug
+                
+                // Write back circular buffer configuration
+                Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+                Cache_wait();
+        
+                // Leave the gate
+                GateMP_leave(gateHandle, key);
+        
+                return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
             }
-            else
+        }
+        
+        //
+        // FL: over allocating memory for PCM CB
+        //  Allocating memory for max # channels (e.g. 32 for THD).
+        //  Over allocation for THD 192 kHz, 6ch max.
+        //
+        
+        // configure AF sample pointers
+        pPcmBuf = pPcmBufWrt;
+        for (i = 0; i < pCb->maxAFChanNum; i++)
+        {
+            // check PCM buffer wrap
+            if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
             {
-                // next audio frame will be current audio frame + 1
-                nextWrtIdx = pCb->afWrtIdx + 1;
+                pPcmBuf = pCb->pcmBuf;
             }
             
-            pAfCbNextAf = &pCb->afCb[nextWrtIdx]; // +1 or last AF if overflow
-            pAfCbNextAf->data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount]; // pAfCb->data.sample[15] + (pAfCb->sampleCount * sizeof(PAF_AudioData));
-#endif
-            
-            // write audio frame information updated by decoder
-            pAfCb->sampleDecode = pAfWrt->sampleDecode;
-            PAF_PROCESS_COPY(pAfCb->sampleProcess, pAfWrt->sampleProcess);
-            pAfCb->sampleRate = pAfWrt->sampleRate;
-            pAfCb->sampleCount = pAfWrt->sampleCount;
-            pAfCb->channelConfigurationRequest = pAfWrt->channelConfigurationRequest;
-            pAfCb->channelConfigurationStream = pAfWrt->channelConfigurationStream;
-            // write metadata information updated by decoder
-            pAfCb->bsMetadata_type     = pAfWrt->bsMetadata_type;        /* non zero if metadata is attached. */
-            pAfCb->pafBsMetadataUpdate = pAfWrt->pafBsMetadataUpdate;    /* indicates whether bit-stream metadata update */
-            pAfCb->numPrivateMetadata  = pAfWrt->numPrivateMetadata;     /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-            pAfCb->bsMetadata_offset   = pAfWrt->bsMetadata_offset;      /* offset into audio frame for change in bsMetadata_type field */
-            
-                       pAfCb->mode = pAfWrt->mode;                                       /* mode is used in DTSX to pass info to PARMA */
-                       pAfCb->numChansUsedForMetadata = pAfWrt->numChansUsedForMetadata; /* if metadata is used in DTSX*/
-                       pAfCb->pafBsFixedData = pAfWrt->pafBsFixedData;                   /* if true, do not convert float to fixed in DTSX metadata transfer */
-                       pAfCb->root = pAfWrt->root;                                       /* used for channel MASK in DTSX . BAD IDEA, need fix */
-                       pAfCb->resetCount = pAfWrt->resetCount;                           /* used for communication between DTSX and PARMA */
-                       pAfCb->data.nChannels = pAfWrt->data.nChannels;                   /* number of channels used */
-            // write PCM samples
-
-                       if (pAfCb->bsMetadata_type == PAF_bsMetadata_DTS_X)
-                       {
-                               //DTSX needs up to 8 to 16 channels to transfer metadata depends on sampling rate.
-                               for (i = 0; i < pAfWrt->data.nChannels; i++)
-                               { 
-                                       for (j = 0; j < pAfWrt->sampleCount; j++)
-                                       {
-                                               pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j];
-                                       }
-
-                                       pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i];
-                               }
-                       }
-                       else
-                       {
-                               streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream);
-                               for (i = 0; i < pCb->maxAFChanNum; i++)
-                               {
-
-                                       if ((streamMask >> i) & 0x1)
-                                       { //DTSX needs up to 16 channels to transfer metadata.
-                                               for (j = 0; j < pAfWrt->sampleCount; j++)
-                                               {
-                                                       pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j];
-                                               }
-
-                                               pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i];
-                                       }
-                               }
-                       }
-            // Update PCM samples per channel
-            pCb->numPcmSampsPerCh += pAfWrt->sampleCount;
-            
-            #ifdef CB_RW_OP_CAP_PP // debug
-            if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
-            {
-                if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
-                {
-                    // log sample count
-                    pCb->cb_samples_op[pCb->cb_opCnt] = pAfWrt->sampleCount;
-                    pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_W;
-                    // log idxs
-                    pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
-                    pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
-                    pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
-                    pCb->cb_opCnt++;
-                }
-            }
-            #endif
+            pAfCb->data.sample[i] = pPcmBuf;                
+            pPcmBuf += pAfWrt->sampleCount;
+            pAfCb->data.samsiz[i] = 0;
+        }
+        Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
+        Cache_wait();
 
-            // prepare metadata buffer pointers according to the metadata and buffer sizes
-            for (i = 0; i < pAfWrt->numPrivateMetadata; i++)
-            {
-                UInt8 *nextMdBuf;
-                if (i == 0)
-                {
-                    nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size);                    
-                }
-                else
-                {
-                    nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size);                    
-                }
-                if (nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow
-                {
-                    pAfCb->pafPrivateMetadata[i].pMdBuf = pCb->metaBuf;
-                }
-                else if (i != 0)
+        // FL: brute force reset of all metadata in CB AF
+        for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
+        {
+            pAfCb->pafPrivateMetadata[i].offset = 0;
+            pAfCb->pafPrivateMetadata[i].size   = 0;
+            pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
+            pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
+        }
+        
+        // write audio frame information updated by decoder
+        pAfCb->sampleDecode = pAfWrt->sampleDecode;
+        PAF_PROCESS_COPY(pAfCb->sampleProcess, pAfWrt->sampleProcess);
+        pAfCb->sampleRate = pAfWrt->sampleRate;
+        pAfCb->sampleCount = pAfWrt->sampleCount;
+        pAfCb->channelConfigurationRequest = pAfWrt->channelConfigurationRequest;
+        pAfCb->channelConfigurationStream = pAfWrt->channelConfigurationStream;
+        // write metadata information updated by decoder
+        pAfCb->bsMetadata_type     = pAfWrt->bsMetadata_type;        /* non zero if metadata is attached. */
+        pAfCb->pafBsMetadataUpdate = pAfWrt->pafBsMetadataUpdate;    /* indicates whether bit-stream metadata update */
+        pAfCb->numPrivateMetadata  = pAfWrt->numPrivateMetadata;     /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
+        pAfCb->bsMetadata_offset   = pAfWrt->bsMetadata_offset;      /* offset into audio frame for change in bsMetadata_type field */
+        
+        pAfCb->mode = pAfWrt->mode;                                       /* mode is used in DTSX to pass info to PARMA */
+        pAfCb->numChansUsedForMetadata = pAfWrt->numChansUsedForMetadata; /* if metadata is used in DTSX*/
+        pAfCb->pafBsFixedData = pAfWrt->pafBsFixedData;                   /* if true, do not convert float to fixed in DTSX metadata transfer */
+        pAfCb->root = pAfWrt->root;                                       /* used for channel MASK in DTSX . BAD IDEA, need fix */
+        pAfCb->resetCount = pAfWrt->resetCount;                           /* used for communication between DTSX and PARMA */
+        pAfCb->data.nChannels = pAfWrt->data.nChannels;                   /* number of channels used */
+        // write PCM samples
+
+        if (pAfCb->bsMetadata_type == PAF_bsMetadata_DTS_X)
+        {
+            //DTSX needs up to 8 to 16 channels to transfer metadata depends on sampling rate.
+            for (i = 0; i < pAfWrt->data.nChannels; i++)
+            { 
+                for (j = 0; j < pAfWrt->sampleCount; j++)
                 {
-                    pAfCb->pafPrivateMetadata[i].pMdBuf = nextMdBuf;
+                    pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j];
                 }
-                Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0);
-            }
 
-            // Write metadata to circular buffer
-            for (i = 0; i < pAfWrt->numPrivateMetadata; i++) // only copy numPrivateMetadata
-            {
-                pAfCb->pafPrivateMetadata[i].offset = pAfWrt->pafPrivateMetadata[i].offset;
-                pAfCb->pafPrivateMetadata[i].size   = pAfWrt->pafPrivateMetadata[i].size;
-                memcpy(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].size);
+                pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i];
             }
-
-            Cache_inv(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0); // FL: this is write back and invalidate??
-            Cache_wait();
-            for (i = 0; i < pAfCb->numPrivateMetadata; i++) // only write back numPrivateMetadata
+        }
+        else
+        {
+            streamMask = pAfWrt->fxns->channelMask(pAfWrt, pAfCb->channelConfigurationStream);
+            for (i = 0; i < pCb->maxAFChanNum; i++)
             {
-                //Log_info4("cbWriteAf: AF: %d nummd: %d offset: %d size: %d ", pCb->afWrtIdx, pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[i].offset,  pAfCb->pafPrivateMetadata[i].size);
-                Cache_wb(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0);
+
+                if ((streamMask >> i) & 0x1)
+                { //DTSX needs up to 16 channels to transfer metadata.
+                    for (j = 0; j < pAfWrt->sampleCount; j++)
+                    {
+                        pAfCb->data.sample[i][j] = pAfWrt->data.sample[i][j];
+                    }
+
+                    pAfCb->data.samsiz[i] = pAfWrt->data.samsiz[i];
+                }
             }
-            // update audio frame write index
-            pCb->afWrtIdx++;
-            if (pCb->afWrtIdx >= pCb->maxNumAfCb)
+        }
+        // Update PCM samples per channel
+        pCb->numPcmSampsPerCh += pAfWrt->sampleCount;
+        
+        #ifdef CB_RW_OP_CAP_PP // debug
+        if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
+        {
+            if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
             {
-                pCb->afWrtIdx = 0;
+                // log sample count
+                pCb->cb_samples_op[pCb->cb_opCnt] = pAfWrt->sampleCount;
+                pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_W;
+                // log idxs
+                pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
+                pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
+                pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
+                pCb->cb_opCnt++;
             }
+        }
+        #endif
 
-            pCb->afCb[pCb->afWrtIdx].data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];
-            if (pAfWrt->numPrivateMetadata > 0)
+        // prepare metadata buffer pointers according to the metadata and buffer sizes
+        for (i = 0; i < pAfWrt->numPrivateMetadata; i++)
+        {
+            UInt8 *nextMdBuf;
+            if (i == 0)
             {
-                pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].pMdBuf + pAfWrt->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].size;
+                nextMdBuf = (pAfCb->pafPrivateMetadata[0].pMdBuf + pAfWrt->pafPrivateMetadata[0].size);                    
             }
             else
             {
-                pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;
-                Cache_wb(pCb->afCb , ASP_DECOP_CB_MAX_NUM_PCM_FRAMES*sizeof(PAF_AudioFrame *), Cache_Type_ALLD, 0);
-                Cache_wait();
+                nextMdBuf = (pAfCb->pafPrivateMetadata[i-1].pMdBuf + pAfWrt->pafPrivateMetadata[i-1].size);                    
             }
-            Cache_inv(pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0);
-            Cache_wait();
-            // update number of audio frames in circular buffer
-            pCb->numAfCb++;
-            
-            // Update CB Lag index 
-            //if (pCb->afLagIdx < pCb->afInitialLag)
-            //{
-            //    pCb->afLagIdx += 1;
-            //}
-            
-            // Update CB primed flag.
-            // Calculate number of delta samples before allowing CB read.
-            if (pCb->primedFlag == 0)
+            if (nextMdBuf >= pCb->metaBufEnd) // metadata buffer overflow
             {
-                pCb->primedFlag = 1;
-                
-                // THD has variable number of AUs per frame. 
-                // Some frames can be quite large (e.g. 96 AUs), and delta samples calculation small or even negative.
-                // In this case, there won't be any reader hold off, and no nominal delay in the CB.
-                pCb->deltaSamps = pCb->targetNDSamps;
-                
-                // debug
-                //gSampleCountBuf[gPrimedFlagCnt] = pAfWrt->sampleCount;
-                //gCalcDeltaSampsBuf[gPrimedFlagCnt] = pCb->deltaSamps;
-                //if (gPrimedFlagCnt < 10)
-                //    gPrimedFlagCnt++;
+                pAfCb->pafPrivateMetadata[i].pMdBuf = pCb->metaBuf;
             }
-
-            // Update delta samples using number of write audio frame samples.
-            if (pCb->deltaSamps > 0)
+            else if (i != 0)
             {
-               pCb->deltaSamps = pCb->deltaSamps - pAfWrt->sampleCount;
+                pAfCb->pafPrivateMetadata[i].pMdBuf = nextMdBuf;
             }
-            
-            // Write back circular buffer configuration
-            Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-            // write back audio frame
-            Cache_wb(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
-            Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
-            Cache_wb(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0);
-            Cache_wait();
-            // write back PCM data
-                       if (pAfCb->bsMetadata_type == PAF_bsMetadata_DTS_X)
-                       {       
-                               //DTSX needs up to 8 to 16 channels to transfer metadata depends on sampling rate.
-                               for (i = 0; i < pAfWrt->data.nChannels; i++)
-                               { 
-                                       Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
-                               }
-                       }
-                       else 
-                       {
-                               for (i = 0; i < pCb->maxAFChanNum; i++)
-                               {
-                                       if ((streamMask >> i) & 0x1)
-                                       {
-                                               Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
-                                       }
-                               }
-                       }
-            Cache_wait();
+            Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0);
+        }
 
-#if 0 // also for CB_RW_OP_CAP_PP (***) FL: shows timing of CB write
-            // debug
-            {
-                static Uint8 toggleState = 0;
-               if (toggleState == 0)
-                   GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
-               else
-                   GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
-               toggleState = ~(toggleState);
-            }
-#endif
+        // Write metadata to circular buffer
+        for (i = 0; i < pAfWrt->numPrivateMetadata; i++) // only copy numPrivateMetadata
+        {
+            pAfCb->pafPrivateMetadata[i].offset = pAfWrt->pafPrivateMetadata[i].offset;
+            pAfCb->pafPrivateMetadata[i].size   = pAfWrt->pafPrivateMetadata[i].size;
+            memcpy(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].pMdBuf, pAfWrt->pafPrivateMetadata[i].size);
+        }
+
+        Cache_inv(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0);
+        Cache_wait();
+        for (i = 0; i < pAfCb->numPrivateMetadata; i++) // only write back numPrivateMetadata
+        {
+            //Log_info4("cbWriteAf: AF: %d nummd: %d offset: %d size: %d ", pCb->afWrtIdx, pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[i].offset,  pAfCb->pafPrivateMetadata[i].size);
+            Cache_wb(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0);
+        }
+        // update audio frame write index
+        pCb->afWrtIdx++;
+        if (pCb->afWrtIdx >= pCb->maxNumAfCb)
+        {
+            pCb->afWrtIdx = 0;
+        }
 
-            Log_info3("wrote %d samples into AF %d sourceSel: %d", pAfCb->sampleCount, pCb->afWrtIdx, pCb->sourceSel);
-            Log_info4("CBWMETA num=%d  size=%d  offset=%d chrequest=0x%04x", pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[0].size, pAfCb->pafPrivateMetadata[0].offset, pAfCb->channelConfigurationRequest.full);
+        pCb->afCb[pCb->afWrtIdx].data.sample[0] = &pAfCb->data.sample[pCb->maxAFChanNum - 1][pAfWrt->sampleCount];
+        if (pAfWrt->numPrivateMetadata > 0)
+        {
+            pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].pMdBuf + pAfWrt->pafPrivateMetadata[pAfWrt->numPrivateMetadata - 1].size;
         }
         else
         {
-            //
-            // Skip write in case of 0 sample count
-            //
+            pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;
+            Cache_wb(pCb->afCb , ASP_DECOP_CB_MAX_NUM_PCM_FRAMES*sizeof(PAF_AudioFrame *), Cache_Type_ALLD, 0);
+            Cache_wait();
+        }
+        Cache_inv(pCb->afCb[pCb->afWrtIdx].pafPrivateMetadata[0].pMdBuf, sizeof(UInt8 *), Cache_Type_ALLD, 0);
+        Cache_wait();
+        // update number of audio frames in circular buffer
+        pCb->numAfCb++;
+        
+        // Update CB primed flag.
+        // Calculate number of delta samples before allowing CB read.
+        if (pCb->primedFlag == 0)
+        {
+            pCb->primedFlag = 1;
+            
+            // THD has variable number of AUs per frame. 
+            // Some frames can be quite large (e.g. 96 AUs), and delta samples calculation small or even negative.
+            // In this case, there won't be any reader hold off, and no nominal delay in the CB.
+            pCb->deltaSamps = pCb->targetNDSamps;
             
-            // writing audio frame w/ zero samples
-            // update stat
-            pCb->wrtAfZeroSampsCnt++;
+            // debug
+            //gSampleCountBuf[gPrimedFlagCnt] = pAfWrt->sampleCount;
+            //gCalcDeltaSampsBuf[gPrimedFlagCnt] = pCb->deltaSamps;
+            //if (gPrimedFlagCnt < 10)
+            //    gPrimedFlagCnt++;
+        }
 
-            // Write back circular buffer configuration
-            Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-            Cache_wait();
+        // Update delta samples using number of write audio frame samples.
+        if (pCb->deltaSamps > 0)
+        {
+            pCb->deltaSamps = pCb->deltaSamps - pAfWrt->sampleCount;
+        }
+        
+        // Write back circular buffer configuration
+        Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+        // write back audio frame
+        Cache_wb(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
+        Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
+        Cache_wb(pAfCb->pafPrivateMetadata, pAfWrt->numPrivateMetadata*sizeof(PAF_PrivateMetadata *), Cache_Type_ALLD, 0);
+        Cache_wait();
+        // write back PCM data
+        if (pAfCb->bsMetadata_type == PAF_bsMetadata_DTS_X)
+        {      
+            //DTSX needs up to 8 to 16 channels to transfer metadata depends on sampling rate.
+            for (i = 0; i < pAfWrt->data.nChannels; i++)
+            { 
+                Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
+            }
         }
-    //}
-    //else if (pCb->readerActiveFlag == 0)
+        else 
+        {
+            for (i = 0; i < pCb->maxAFChanNum; i++)
+            {
+                if ((streamMask >> i) & 0x1)
+                {
+                    Cache_wb(pAfCb->data.sample[i], pAfWrt->sampleCount * sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
+                }
+            }
+        }
+        Cache_wait();
+
+#if 0 // debug // also for CB_RW_OP_CAP_PP
+        // shows timing of CB write
+        // ADC B5
+        {
+            static Uint8 toggleState = 0;
+           if (toggleState == 0)
+               GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
+           else
+               GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
+           toggleState = ~(toggleState);
+        }
+#endif
+
+        Log_info3("wrote %d samples into AF %d sourceSel: %d", pAfCb->sampleCount, pCb->afWrtIdx, pCb->sourceSel);
+        Log_info4("CBWMETA num=%d  size=%d  offset=%d chrequest=0x%04x", pAfCb->numPrivateMetadata, pAfCb->pafPrivateMetadata[0].size, pAfCb->pafPrivateMetadata[0].offset, pAfCb->channelConfigurationRequest.full);
+    }
+    else
+    {
+        //
+        // Skip write in case of 0 sample count
+        //
+        
+        // writing audio frame w/ zero samples
+        // update stat
+        pCb->wrtAfZeroSampsCnt++;
+
+        // Write back circular buffer configuration
+        Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+        Cache_wait();
+    }
+        
     if (pCb->readerActiveFlag == 0)
     {
         //
index 23ea1dbc16442f20be61949eb94034a62a113093..370421c73ff3485ad84ea164ca0bf34bd0b831f5 100644 (file)
@@ -66,7 +66,7 @@ All rights reserved.
 #include "pfp/pfp.h"
 #include "pfp_app.h"        /* contains all PFP ID's */
 
-// FL: debug
+// debug
 #include "dbgCapAf.h"
 #include "dbgDib.h"
 #include "evmc66x_gpio_dbg.h"
@@ -110,7 +110,7 @@ PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
 // Overflow threshold before circular buffer reset and return error to Top-Level FSM
-#define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
+#define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // arbitrary setting
 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count, not including overflows
 UInt32 gDecOpCbWrtAfOvr         =0; // decoder output circular buffer overflow count
 UInt32 gMaxDecOpCbWrtAfOvr      =0; // max (consecutive) decoder output circular buffer overflow count
@@ -144,7 +144,6 @@ int tempCap_decSampleOut[CAP_FRAME_MAX] = {0};
  *  Audio Stream Decode Processing task function
  */
 Void taskAsdpFxn(
-//    Int betaPrimeValue, // FL: revisit
     const PAF_ASDT_Params *pP,
     const PAF_ASDT_Patchs *pQ
 )
@@ -234,12 +233,10 @@ Void taskAsdpFxn(
     Cache_inv(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
     Cache_wait();
     
-    // (***) FL: revisit
     // 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();
@@ -327,7 +324,6 @@ Void taskAsdpFxn(
             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_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);
@@ -341,25 +337,6 @@ Void taskAsdpFxn(
     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_AAC2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_wait();
     
-    // (***) FL: revisit
-    // write back Status structures for Beta Units initialized on Slave
-   /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
-    Cache_wbInv((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_wbInv((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_wbInv((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_wbInv((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_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
-    Cache_wait();
-
-    // (***) FL: revisit
-    // write back Dec configuration
-    Cache_wbInv(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
-    Cache_wait();*/
-    
     // Send initialization complete message to master
     queId = MessageQ_getReplyQueue(pAspMsg);
     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -498,16 +475,6 @@ Void taskAsdpFxn(
                 case ASP_SLAVE_DEC_ACTIVATE:
                     gSlaveDecActivateCnt++;
                     
-                    // (***) 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_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);
@@ -589,16 +556,6 @@ Void taskAsdpFxn(
                     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_PCM]->size;
-                    Cache_wbInv((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_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
-                    Cache_wait();*/
-
                     // send dec reset complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
                     pAspMsg->procId = hAspMsgSlave->slaveProcId;
@@ -624,7 +581,6 @@ Void taskAsdpFxn(
                     // Get input associated w/ decoder
                     zI = pP->inputsFromDecodes[z];
 
-                    // (***) FL: revisit
                     // invalidate Inp configuration
                     Cache_inv(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
                     Cache_wait();
@@ -818,11 +774,6 @@ Void taskAsdpFxn(
                         //
                         if (outIsDecDecode1Flag == 0)
                         {
-                            //
-                            // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
-                            //  frameLength: changed to decodeControl.frameLength.
-                            //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
-                            
                             // Initialize decoder output circular buffer
                             errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
                                 pAstCfg->xDec[z].decodeControl.frameLength, 
@@ -898,8 +849,9 @@ Void taskAsdpFxn(
                         //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);   // debug
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
-#if 0 // (***) FL: shows timing of CB write
-                        // (***) debug // B9
+#if 0 // debug
+                        // Shows timing of CB write
+                        // ADC B9
                         {
                             static Uint8 toggleState = 0;
                             if (toggleState == 0)
@@ -1096,9 +1048,6 @@ PAF_ASDT_initPhaseConfig(
     // 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
         pAstCfg->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
         pAstCfg->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
         pAstCfg->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z];
@@ -1268,22 +1217,6 @@ PAF_ASDT_initPhaseCommon(
             if(pP->fxns->allocPrint)
                 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
         }
-
-#if 0 // FL: master
-        TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
-        TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
-        if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], 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, 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 *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
-#endif
-        
     }
     {
         // Changes made to share scratch between zones
@@ -1348,27 +1281,6 @@ PAF_ASDT_initPhaseCommon(
                 return __LINE__;
             }
         }
-
-#if 0 // FL: master
-        pC->xStr[z].aspChain[0] = NULL;
-        for (g=0; g < GEARS; g++) 
-        {
-            PAF_ASP_Chain *chain;
-            TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
-            chain =
-                PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
-                                   HEAP_INTERNAL, as+z, acp, &trace,
-                                   aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
-            if (! chain) 
-            {
-                TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
-                return __LINE__;
-            }
-            else
-                pC->xStr[z].aspChain[g] = chain;
-        }
-#endif
-
     }
     TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
 
@@ -1728,7 +1640,7 @@ Int resetAfSamsiz(
     return 0;
 }
 
-// (***) FL: Check correct behavior for other decs, esp DTSHD & DXP
+// FL: Need to check correct behavior for other decoders, esp DTSHD & DXP
 // Check decoder sync using information in INFO audio frame
 static Int8 checkDecSync(
     PAF_AudioFrame *pAf
index e893dad419c5c637dbc00576503f54cf508157dd..9d540720cd3c3664b738d3955dd78f507368e580 100644 (file)
@@ -66,17 +66,11 @@ All rights reserved.
 //   External declarations to patched IROM provide standard functionality.
 //
 
-#if 1
-// FL: extern this, making it look like shared information between ARM/DSP.
-// FL: Note could just define the same thing in separate file for ARM application (i.e. add "Slave" at end of identifier).
 /* audio frame "width" in channels */
 const SmInt PAF_AST_params_numchan[1] =
 {
     32,
 };
-#else
-extern const SmInt PAF_AST_params_numchan[];
-#endif
 
 ///
 // Audio Stream Processing Function Table Definition
@@ -97,9 +91,6 @@ const PAF_AudioFunctions PAF_ASDT_params_audioFrameFunctions =
 //   External declarations to patched IROM provide standard functionality.
 //
 
-#if 1
-// FL: extern this, making it look like shared information between ARM/DSP.
-// FL: Note could just define the same thing in separate file for ARM application (i.e. add "Slave" at end of identifier).
 const PAF_ASP_AlgKey PAF_ASP_params_decAlgKey =
 {
     PAF_SOURCE_N,                                           // length
@@ -132,13 +123,7 @@ const PAF_ASP_AlgKey PAF_ASP_params_decAlgKey =
     PAF_ASP_ALPHACODE (STD, THD),                           // PAF_SOURCE_THD
     PAF_ASP_ALPHACODE (STD, DXP),                           // PAF_SOURCE_DXP
 };
-#else
-extern const PAF_ASP_AlgKey PAF_ASP_params_decAlgKey;
-#endif
 
-#if 1
-// FL: This MUST be shared between ARM/DSP.
-// FL: extern this, making it look like shared information between ARM/DSP.
 //
 // Mapping Declarations -- from *coders to *puts
 //
@@ -148,9 +133,6 @@ const SmInt PAF_AST_streamsFromDecodes_std[DECODEN_MAX] =
 {
     0, 1, 2,
 };
-#else
-extern const SmInt PAF_AST_streamsFromDecodes_std[DECODEN_MAX];
-#endif
 
 const SmInt PAF_AST_inputsFromDecodes_std[DECODEN_MAX] =
 {
@@ -165,9 +147,6 @@ const SmInt PAF_AST_inputsFromDecodes_std[DECODEN_MAX] =
 
 extern const PAF_ASDT_Fxns PAF_ASDT_params_fxns;
 
-#if 1
-// FL: This MUST be shared between ARM/DSP.
-// FL: extern this, making it look like shared information between ARM/DSP.
 const PAF_DecodeStatus PAF_AST_params_decodeStatus_primary =
 {
     sizeof (PAF_DecodeStatus),                              // size
@@ -280,21 +259,11 @@ const PAF_DecodeStatus PAF_AST_params_decodeStatus_primary =
     0,                                                      // programFormat.form
    
 };
-#else
-//extern const PAF_DecodeStatus PAF_AST_params_decodeStatus_primary;
-#endif
 
-#if 1
-// FL: extern this, making it look like shared information between ARM/DSP.
-// FL: Note could just define the same thing in separate file for ARM application (i.e. add "Slave" at end of identifier).
-/* audio frame "width" in channels */
 const PAF_DecodeStatus *const PAF_ASDT_params_decodeStatus[] =
 {
     &PAF_AST_params_decodeStatus_primary,
 };
-#else   
-//extern const PAF_DecodeStatus *const PAF_AST_params_decodeStatus[];
-#endif // FL: #if 0
 
 //
 // Common Space Parameter Declarations and Definitions
@@ -342,70 +311,6 @@ const PAF_MetadataBufStatus PAF_ASDT_params_MetadataBufStatus[] =
     &gPafHeapIdExt          // pHeapIdMdbuf
 };
 
-#if 0 // FL: maybe needed on ARM if there's an audio frame buffer defined for decode (and possible stream)
-// .............................................................................
-//
-// This structure defines the memory allocation of audio frame buffers (channel buffers). Users can customize this structure based
-// on their requirement. IALG_SARAM specifies the audio frame buffer is allocated in IRAM and IALG_EXTERNAL
-// specifies the audio frame buffer is allocated in SDRAM. By allocating few channel buffers in SDRAM, users can save internal memory
-// but trading performance
-// This structure defined for PAF_MAXNUMCHAN number of channels. But channel buffers will be allocated  for "PAF_AST_params_numchan"
-// number of channels only.
-//
-
-const PAF_AudioFrameBufStatus    PAF_AST_params_AudioFrameBufStatus[PAF_MAXNUMCHAN] =
-{
-    IALG_SARAM, // 0
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM, // 16
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM,
-    IALG_SARAM, // 31
-    //IALG_EXTERNAL, // 16
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL,
-    //IALG_EXTERNAL // 31
-};
-#endif // FL: #if 0
-
 // .............................................................................
 //
 // Audio Stream Parameter Definitions
index b329f3a47527f94601ba02f2652ed314b2a3b684..2afb14c2c820515875f6fa8c25e0352ad711993f 100644 (file)
@@ -123,88 +123,14 @@ const PAF_ASP_LinkInit *const patchs_decLinkInit[] =
     decLinkInitI13,
 };
 
-#if 0 // FL: master
-//
-// Audio Stream Processing Declarations & Definitions
-//
-
-//#include <ae.h>
-//#include <ae_mds.h>
-
-#include <aspstd.h>
-
-const PAF_ASP_LinkInit aspLinkInitAllI13[] =
-{
-#ifdef _SRC4_
-//    PAF_ASP_LINKINIT(STD, SRC, MDS),
-    PAF_ASP_LINKINITPARAMS (STD, SRC, TIH, &ISRC_PARAMS_DS_8CH_HBW),
-#endif
-
-    PAF_ASP_LINKNONE,
-};
-
-const PAF_ASP_LinkInit aspLinkInitNilI13[] =
-{
-    PAF_ASP_LINKNONE,
-};
-
-const PAF_ASP_LinkInit aspLinkInitStdI13[] =
-{
-    PAF_ASP_LINKNONE,
-};
-
-const PAF_ASP_LinkInit aspLinkInitCusI13[] =
-{
-    PAF_ASP_LINKNONE,
-};
-
-
-const PAF_ASP_LinkInit *const patchs_aspLinkInit[1][GEARS] =
-{
-    {
-        aspLinkInitAllI13,
-        aspLinkInitNilI13,
-        aspLinkInitStdI13,
-        aspLinkInitCusI13,
-    },
-};
-
-//
-// Encoder Definitions
-//
-
-#include <pce.h>
-#include <pce_tii.h>
-extern const IPCE_Params IPCE_PARAMS_NODELAY;
-
-const PAF_ASP_LinkInit encLinkInitI13[] =
-{
-    PAF_ASP_LINKINITPARAMS (STD, PCE, TII, &IPCE_PARAMS_NODELAY),
-    PAF_ASP_LINKNONE,
-};
-
-
-const PAF_ASP_LinkInit *const patchs_encLinkInit[] =
-{
-    encLinkInitI13,
-};
-#endif
 
 //
 // Audio Stream Patch Definition
 //
 
-// FL: master
-//extern const PAF_SIO_ParamsN patchs_devinp[];
-//extern const PAF_SIO_ParamsN patchs_devout[];
-
 const PAF_ASDT_Patchs asdp_patchs_PAi =
 {
-    //NULL, //patchs_devinp,
-    //NULL, //patchs_devout,
     patchs_decLinkInit,
-    //NULL, //patchs_aspLinkInit,
-    //NULL, //patchs_encLinkInit,
 };
 
 // EOF
index ebd3cbc45bffd4d64f5fa257fcdf0affecff4210..9aa9527ec215587a12a4f7f6578944ec50b1cbc3 100644 (file)
@@ -55,7 +55,7 @@ extern Void ACP_main_thx ();
 
 Void ACP_main_cus ()
 {
-#if 0 // FL: initially don't patch STD shortcuts    
+#if 0    
     // Patch for STD alpha codes. (Here only to reduce code size).
     {
         extern const ACP_Unit default_s[];
index ff3b78fca771d69626af954bcf5fbbe591ab60b7..9e145db620fd883a16ec02916a8fc1d869363d3c 100644 (file)
@@ -178,12 +178,6 @@ else
     //BIOS.libType = BIOS.LibType_Debug;
 }
  
-//BIOS.useSK = true;
-//BIOS.setupSecureContext = true;
-////BIOS.libType = BIOS.LibType_Custom;BIOS.libType = (RB ? BIOS.LibType_NonInstrumented : BIOS.LibType_Instrumented);
-//BIOS.libType = BIOS.LibType_Custom;
-//// BIOS.libType = BIOS.LibType_Debug;
-
 /* System stack size (used by ISRs and Swis) */
 Program.stack = 0x2000;
 Program.sectMap[".stack"] = "L2SRAM"
@@ -339,12 +333,17 @@ Program.global.TaskSystemStream = Task.create("&taskSystemStreamFxn", task5Param
 Program.sectMap[".far:taskStackSectionAudioStream"] = "CORE0_DDR3";
 
 /* Add idle functions */
-Idle.idleFxns[0] = "&SAP_watchDog";         // Idle function for DSP watchdog; formerly DAP_watchDog()
-// Remark: Moved idleAudioStream (idle function) to taskSystemStreamFxn (task)
+// Remark: original idle functions
+//Idle.idleFxns[0] = "&SAP_watchDog";         // Idle function for DSP watchdog; formerly DAP_watchDog()
 //Idle.idleFxns[1] = "&idleAudioStream";      // Idle function for audio stream; formerly audioStream1Idle()
 //Idle.idleFxns[2] = "&idleNotifyInfoChange"; // Idle function for Notify Information Change (NIC); formerly customSystemStreamIdleNIC()
-Idle.idleFxns[1] = "&idleNotifyInfoChange"; // Idle function for Notify Information Change (NIC); formerly customSystemStreamIdleNIC()
-Idle.idleFxns[2] = "&idleDebug"             // Idle function for debug code
+// Remark: Moved idleAudioStream (idle function) to taskSystemStreamFxn (task)
+//Idle.idleFxns[0] = "&SAP_watchDog";         // Idle function for DSP watchdog; formerly DAP_watchDog()
+//Idle.idleFxns[1] = "&idleNotifyInfoChange"; // Idle function for Notify Information Change (NIC); formerly customSystemStreamIdleNIC()
+//Idle.idleFxns[2] = "&idleDebug"             // Idle function for debug code
+// Remark: Removed SAP watch dog
+Idle.idleFxns[0] = "&idleNotifyInfoChange"; // Idle function for Notify Information Change (NIC)
+Idle.idleFxns[1] = "&idleDebug"             // Idle function for debug code
 
 /* Add L2 SRAM heap */ // formerly IRAM
 var heapMem0Params = new HeapMem.Params();
@@ -379,14 +378,20 @@ Program.sectMap[".ddr3Heap"] = "CORE0_DDR3";
 /* For DCS7, dcs7_cfg.c */
 Program.global.Heap = Program.global.heapMemDdr3;
 
-Program.sectMap["platform_lib"] = "L2SRAM";
 //Program.sectMap[".stack"]    = "L2SRAM";
 
+/* Map C66x INTC Event Combiner EVT 0-3 to HWI numbers */
 ECM.eventGroupHwiNum[0] = 7;
-ECM.eventGroupHwiNum[1] = 8;  // FL: conflict w/ UART LLD (intr-callback)
+ECM.eventGroupHwiNum[1] = 8; // FL: conflict w/ UART LLD, intr-callback mode
 ECM.eventGroupHwiNum[2] = 9;
 ECM.eventGroupHwiNum[3] = 10;
-//Clock.tickPeriod = 100;   // FL: UART LLD (intr-callback) unresponsive
+
+/* Add ASOT wake timer */
+var clockParams = new Clock.Params();
+clockParams.period = 1; // one clock tick period
+clockParams.startFlag = true;
+//clockParams.arg = 0x5555; // unused, default==NULL
+Program.global.clockAsot = Clock.create("&clkAsotFxn", 1, clockParams);
 
 /* Define HWI Hook Set for PFP */
 Hwi.addHookSet({
index 730517d051445dc5175b11b55d1937d39d4c6c32..62cc8294f30c941d0da6303d8158c8cd1c8a8659 100644 (file)
@@ -43,12 +43,8 @@ All rights reserved.
 #include "edma_cfg.h"
 
 #ifdef DCS7_UART_EDMA_ENABLE
-#if 0 // FL: PDK 1.0.1.2_eng
-#include <ti/drv/uart/src/v0/UART_dma_v0.h>   
-#else // FL: PDK 1.0.6 
 #include <ti/drv/uart/src/v0/UART_v0.h> 
 #endif
-#endif
 
 
 
@@ -98,12 +94,8 @@ EDMA3_DRV_Handle hEdma0;
 EDMA3_DRV_Handle hEdma1;
 
 #ifdef DCS7_UART_EDMA_ENABLE
-#if 0 // FL: PDK 1.0.1.2_eng
-extern UARTDMA_HwAttrs uartInitCfg[];
-#else // FL: PDK 1.0.6
 extern UART_HwAttrs uartInitCfg[];
 #endif
-#endif
 
 /**
  *  \brief    Configures eDMA module
index c9544284a961c5a7746d765c1692e0143d2bd264..90bf11cb808b8831ae5a5648c0c312ed2c50d5b7 100644 (file)
@@ -54,7 +54,8 @@ All rights reserved.
 #include "paf_alg_print.h"
 #endif /* MEMSTAT_REPORT */
 
-//#include "dbgIdle.h" // FL: debug -- initiate IDLE memstat
+// debug
+//#include "dbgIdle.h" // initiate IDLE memstat
 
 #define ENABLE_AE_TRACE
 #ifdef ENABLE_AE_TRACE
@@ -273,21 +274,14 @@ Void taskAfpFxn(AFP_Handle handle)
     handle->acp = ACP_create(&ACP_MDS_IACP,handle->acpParams);
     if (handle->acp == NULL)
     {
-        //handle->fxns->log(handle,handle->logObj,
-        //    "AFP6: ACP instance creation failed");
         Log_info0("TaskAfp: ACP instance creation failed");
     }
     else
     {
-        //extern struct {
-        //   int size;
-        //} pafIdentification;
-        
         // Get pointer to ACP Status structure
         ((ALG_Handle)handle->acp)->fxns->algControl((IALG_Handle)(handle->acp),
             ACP_GETSTATUSADDRESS1, 
             (IALG_Status *)&pStatus);
-        // FL: (*** ?) Why STD BETA UART? Why not STD_BETA_ACP?
         // Attach ACP Status structure to Beta Unit Id==STD_BETA_UART
         handle->acp->fxns->attach(handle->acp, 
             ACP_SERIES_STD, 
@@ -310,12 +304,6 @@ Void taskAfpFxn(AFP_Handle handle)
             STD_BETA_SIGMATABLE, 
             (IALG_Status *)((ACP_MDS_Obj *)handle->acp)->config.sigmaTable[ACP_SERIES_STD]);
             
-        // FL: (*** ?) STD_BETA_IDENTITY already attached in main()->systemStreamMain(), so remove this
-        // Attach PAF Identification structure to Beta Unit Id==STD_BETA_IDENTITY
-        //handle->acp->fxns->attach(handle->acp, ACP_SERIES_STD, STD_BETA_IDENTITY, 
-        //    (IALG_Status *)&pafIdentification);
-        
-        //handle->fxns->log(handle,handle->logObj,"AFP6: ACP initialized");
         Log_info0("TaskAfp: ACP initialized");
         
         // Initialize DCS
@@ -325,8 +313,6 @@ Void taskAfpFxn(AFP_Handle handle)
             handle->acp);
         if (handle == NULL)
         {
-            //handle->fxns->log(handle,handle->logObj,
-            //    "AFP6: DCS6 creation failed");
             Log_info0("TaskAfp: DCS7 creation failed");
         }
         else
@@ -345,13 +331,10 @@ Void taskAfpFxn(AFP_Handle handle)
                 4);
             if ((handle->rxBuf == NULL) || (handle->txBuf == NULL))
             {
-                //handle->fxns->log(handle,handle->logObj,
-                //    "AFP6: Buffer allocation failed");
                 Log_info0("TaskAfp: Buffer allocation failed");
             }
             else
             {
-                //handle->fxns->log(handle,handle->logObj,"AFP6: AFP6 initialized");
                 Log_info0("TaskAfp: Initialized");
 
 #ifdef MEMSTAT_REPORT
@@ -360,7 +343,7 @@ Void taskAfpFxn(AFP_Handle handle)
                     PAF_HEAP_INT, PAF_HEAP_INT1, PAF_HEAP_EXT, 
                         PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
 #endif /* MEMSTAT_REPORT */
-                //gRunIdleMemStatRpt=1; // FL: debug
+                //gRunIdleMemStatRpt=1; // debug, allow Idle mem stat to run
                
                 // Process alpha commands
                 handle->fxns->process(handle);
index e2b8a8c42a394d6748e9b5015d58ff0997695f0b..af7f4f0c07bda14fb7278be000f1dfc447b2bc6f 100644 (file)
@@ -259,13 +259,6 @@ PAF_DEC_deviceSelect(
 #define DEC_MAXSAMGEN PCM_MAXSAMGEN
 #endif
 
-// FL: change alg handle to decIdx, index is w.r.t. dec zones
-//Int
-//PAF_DEC_computeFrameLength(
-//    ALG_Handle alg, 
-//    Int frameLength, 
-//    Int bufferRatio
-//)
 Int
 PAF_DEC_computeFrameLength(
     Int decIdx, 
@@ -278,7 +271,7 @@ PAF_DEC_computeFrameLength(
     Int argIdx;
     char decMsgBuf[ASP_MSG_BUF_LEN];
 
-    // FL: dec control message to slave
+    // dec control message to slave
     argIdx = 0; //  set decIdx
     *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
@@ -286,7 +279,7 @@ PAF_DEC_computeFrameLength(
     if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
                   decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
     {
-        SW_BREAKPOINT;
+        SW_BREAKPOINT; // temporary
         return -1; // temporary        
     }    
     else 
@@ -296,11 +289,7 @@ PAF_DEC_computeFrameLength(
         TRACE_TERSE1("decCtrlRet (m)=%d", m);        
     }
 
-#if 0 // FL: decoder control call, slave
-    m = alg->fxns->algControl(alg, DEC_MINSAMGEN, NULL);
-#endif
-    
-    // FL: dec control message to slave
+    // dec control message to slave
     argIdx = 0; // set decIdx
     *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
@@ -308,7 +297,7 @@ PAF_DEC_computeFrameLength(
     if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
                   decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
     {
-        SW_BREAKPOINT;
+        SW_BREAKPOINT; // temporary
         return -1; // temporary        
     }    
     else 
@@ -317,11 +306,6 @@ PAF_DEC_computeFrameLength(
         n = *(Int *)&decMsgBuf[argIdx];
         TRACE_TERSE1("decCtrlRet (n)=%d", n);        
     }
-
-#if 0 // FL: decoder control call, slave
-    n = alg->fxns->algControl(alg, DEC_MAXSAMGEN, NULL);
-#endif
-
     
     if (m != n) {
         o = n < frameLength ? n : frameLength;
index 0d2c6726ef2bd4d29c637124acf3fe755d7d24bf..b54a0f979b4401d8410c251d3e4ab0d058acbbd9 100644 (file)
@@ -57,21 +57,6 @@ Uint8 *gCB_afWrtIdx = NULL;
 Uint8 *gCB_numAfCb = NULL;
 #endif
 
-#if 0
-// Generate mute AF on circular buffer read
-static Void cbReadAfMute(
-    PAF_AudioFrame *pAfRd,      // audio frame into which to read
-    Int16 strFrameLen           // stream frame length (output transaction size)
-);
-#endif
-
-#if 0
-// Init last audio frame configuration info 
-static Void cbInitLastAfInfo(
-    PAF_AudioFrame *pAfRd      // last audio frame stored in CB instance
-);
-#endif
-
 // Update last audio frame configuration info 
 static Void cbUpdateLastAfInfo(
     PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer control
@@ -84,170 +69,11 @@ static Void cbReadMuteWithLastAfInfo(
     PAF_AudioFrame *pAfRd         // audio frame into which to read
 );
 
-#if 0 // FL: moved to common
-// Initialize circular buffer control
-Int cbCtlInit(
-    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
-    Int8 numCb,                         // number of circular buffers
-    PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
-)
-{
-    GateMP_Params gateParams;
-    GateMP_Handle gateHandle;
-    
-    GateMP_Params_init(&gateParams);
-    gateParams.localProtect = GateMP_LocalProtect_THREAD;
-    gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM;
-    gateParams.name = ASP_DECODE_CB_GATE_NAME;
-    gateParams.regionId = ASP_DECODE_CB_GATE_REGION_ID;
-    gateHandle = GateMP_create(&gateParams);
-    if (gateHandle != NULL)
-    {
-        pCbCtl->gateHandle = gateHandle;
-    }
-    else
-    {
-        pCbCtl->gateHandle = NULL;
-        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
-    }
-    
-    pCbCtl->numCb = numCb;          // init number of circular buffers
-    pCbCtl->pXDecOpCb = pXDecOpCb;  // init base address of circular buffers
-    
-    return ASP_DECOP_CB_SOK;    
-}
-#endif
-
 // Initialize circular buffer
 Int cbInit(
     PAF_AST_DecOpCircBuf *pCb
 )
 {
-#if 0 // FL: unused
-    PAF_AudioFrame *pAfCb;
-    PAF_AudioData *pPcmBuf;
-    UInt8 *pMetaBuf;
-    Int8 n;
-    Int8 i;
-
-    // set source select
-    pCb->sourceSel = DEF_SOURCE_SEL;
-
-    // set input frame length
-    pCb->decOpFrameLen = DEF_DEC_OP_FRAME_LEN;
-    
-    // set output frame length
-    pCb->strFrameLen = DEF_STR_FRAME_LEN;
-    
-    // initialize circular buffer maximum number of audio frames
-    pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD; //ASP_DECOP_CB_MAX_NUM_AF_PCM;
-    pCb->afWrtIdx = ASP_DECOP_CB_INIT_LAG_PCM;
-    pCb->afRdIdx = 0;
-    pCb->pcmRdIdx = 0;
-
-    // Initialize CB primed flag
-    pCb->primedFlag = 0;
-    // Initialize delta samples
-    pCb->deltaSamps = 0;
-    
-    // set default value to PCM configuration
-    pCb->maxAFChanNum   = ASP_DECOP_CB_MAX_NUM_PCM_CH;
-    pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
-    // initialize audio frames
-    for (n=0; n<pCb->maxNumAfCb; n++)
-    {
-        pAfCb = &pCb->afCb[n];
-        pAfCb->sampleDecode = PAF_SOURCE_PCM;
-        PAF_PROCESS_ZERO(pAfCb->sampleProcess);
-        pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
-        pAfCb->sampleCount = DEF_DEC_OP_FRAME_LEN;
-        pAfCb->channelConfigurationRequest.full = 0;
-        pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-        pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-        pAfCb->channelConfigurationStream.full = 0;
-        pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-        pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-    }
-
-    // initialize circular buffer current number of frames
-    pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
-    
-    // initialize audio frame PCM buffers
-    pPcmBuf = pCb->pcmBuf;
-    pMetaBuf = pCb->metaBuf;
-    for (n=0; n<pCb->maxNumAfCb; n++)
-    {
-        pAfCb = &pCb->afCb[n];
-        pAfCb->data.nChannels = ASP_DECOP_CB_MAX_NUM_PCM_CH;
-        pAfCb->data.nSamples = DEF_DEC_OP_FRAME_LEN;
-        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
-        {
-            pAfCb->data.sample[i] = pPcmBuf;
-            memset(pAfCb->data.sample[i], 0, DEF_DEC_OP_FRAME_LEN);
-            pPcmBuf += DEF_DEC_OP_FRAME_LEN;
-            
-            pAfCb->data.samsiz[i] = 0;
-        }
-        
-        // write metadata information updated by decoder
-        pAfCb->bsMetadata_type     = PAF_bsMetadata_channelData;    /* non zero if metadata is attached. */
-        pAfCb->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-        pAfCb->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-        pAfCb->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-        
-        // Initialize metadata buffers
-        for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
-        {
-            pAfCb->pafPrivateMetadata[i].offset = 0; 
-            pAfCb->pafPrivateMetadata[i].size   = 0; 
-            pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
-            pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
-        }
-    }
-    
-    // reset read/write flags
-    pCb->writerActiveFlag = 0;
-    pCb->readerActiveFlag = 0;
-    pCb->drainFlag = 0;
-    
-    // reset stats
-    pCb->readAfWriterInactiveCnt = 0;
-    pCb->readAfNdCnt = 0;
-    pCb->wrtAfReaderInactiveCnt = 0;
-    pCb->wrtAfZeroSampsCnt = 0;
-    pCb->errUndCnt = 0;
-    pCb->errOvrCnt = 0;
-    
-    #ifdef CB_RW_OP_CAP_PP // debug
-    // Get address in global variables
-    gCB_samples_op = pCb->cb_samples_op;
-    gCB_op_owner = pCb->cb_op_owner;
-    gCB_opCnt = &pCb->cb_opCnt;
-    gCB_afRdIdx = pCb->cb_afRdIdx;
-    gCB_afWrtIdx = pCb->cb_afWrtIdx;
-    gCB_numAfCb = pCb->cb_numAfCb;
-    #endif
-
-    cbInitLastAfInfo(&pCb->lastAf);
-
-    // Write back circular buffer configuration
-    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-    // Write back AF circular buffer
-    Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
-    // Write back PCM data
-    for (n=0; n<pCb->maxNumAfCb; n++)
-    {
-        pAfCb = &pCb->afCb[n];
-        Cache_wb(pAfCb->data.samsiz, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
-        Cache_wb(pAfCb->data.sample, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
-        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
-        {
-            Cache_wb(pAfCb->data.sample[i], DEF_DEC_OP_FRAME_LEN*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
-        }
-    }
-    Cache_wait();
-#endif
-
     // set source select
     pCb->sourceSel = PAF_SOURCE_UNKNOWN;
 
@@ -268,256 +94,6 @@ Int cbInit(
     return ASP_DECOP_CB_SOK;
 }
 
-#if 0 // FL: moved to ARM
-// debug
-//Int8 gCbInitSourceSelCnt=0;
-//Int8 gCbInitSourceSelThdCnt=0;
-
-// Initialize circular buffer based on selected source
-Int cbInitSourceSel(
-    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
-    Int8 cbIdx,                         // decoder output circular buffer index
-    Int8 sourceSelect,                  // source select (PCM, DDP, etc.)
-    Int16 decOpFrameLen,                // decoder output frame length (PCM samples)
-    Int16 strFrameLen,                  // stream frame length (PCM samples)
-    Int8 resetRwFlags                   // whether to reset reader, writer, and drain flags
-)
-{
-    IArg key;
-    GateMP_Handle gateHandle;
-    PAF_AST_DecOpCircBuf *pCb;
-    PAF_AudioFrame *pAfCb;
-    PAF_AudioData *pPcmBuf;
-    UInt8 *pMetaBuf;
-    Int8 n;
-    Int8 i;
-
-    //gCbInitSourceSelCnt++; // debug
-    
-    // Get gate handle
-    gateHandle = pCbCtl->gateHandle;
-    // Enter gate
-    key = GateMP_enter(gateHandle);
-
-    // Get circular buffer base pointer
-    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
-    
-    // Invalidate circular buffer configuration
-    Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-    Cache_wait();
-
-    //Log_info1("cbInitSourceSel:afCb=0x%04x", (IArg)pCb->afCb); // debug
-
-    // set source select
-    pCb->sourceSel = sourceSelect;
-
-    // set input frame length
-    pCb->decOpFrameLen = decOpFrameLen;
-    
-    // set output frame length
-    pCb->strFrameLen = strFrameLen;
-
-    //pCb->afInitialLag = 0;  // default No lag
-    //pCb->afLagIdx = 0;
-    // Initialize CB primed flag
-    pCb->primedFlag = 0;
-    // Initialize delta samples
-    pCb->deltaSamps = 0;
-    
-    // initialize circular buffer maximum number of audio frames
-    if (sourceSelect == PAF_SOURCE_PCM)
-    {
-        pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
-        
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_PCM;
-        // Initialize target nominal delay
-        pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM;
-        
-        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
-        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
-        pCb->pcmRdIdx = 0;
-        
-        pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH;
-        pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
-        
-        // initialize audio frames
-        for (n=0; n<pCb->maxNumAfCb; n++)
-        {
-            pAfCb = &pCb->afCb[n];
-            pAfCb->sampleDecode = sourceSelect;
-            PAF_PROCESS_ZERO(pAfCb->sampleProcess);
-            pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
-            pAfCb->sampleCount = decOpFrameLen;
-            pAfCb->channelConfigurationRequest.full = 0;
-            pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-            pAfCb->channelConfigurationStream.full = 0;
-            pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-            
-            // write metadata information updated by decoder
-            pAfCb->bsMetadata_type     = PAF_bsMetadata_channelData;    /* non zero if metadata is attached. */
-            pAfCb->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-            pAfCb->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-            pAfCb->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-        }
-    }
-    else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
-    {
-        pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_DDP;
-        
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_DDP;
-        // Initialize target nominal delay
-        pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kDDP;
-        
-        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
-        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
-        pCb->pcmRdIdx = 0;
-        
-        pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP;
-        pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP;
-        
-        // initialize audio frames
-        for (n=0; n<pCb->maxNumAfCb; n++)
-        {
-            pAfCb = &pCb->afCb[n];
-            pAfCb->sampleDecode = sourceSelect;
-            PAF_PROCESS_ZERO(pAfCb->sampleProcess);
-            pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
-            pAfCb->sampleCount = decOpFrameLen;
-            pAfCb->channelConfigurationRequest.full = 0;
-            pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-            pAfCb->channelConfigurationStream.full = 0;
-            pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-            
-            // write metadata information updated by decoder
-            pAfCb->bsMetadata_type     = PAF_bsMetadata_channelData;    /* non zero if metadata is attached. */
-            pAfCb->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-            pAfCb->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-            pAfCb->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-        }
-    }
-    else if (sourceSelect == PAF_SOURCE_THD)
-    {
-        //gCbInitSourceSelThdCnt++; //debug
-        
-        pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD;
-        
-        //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_THD;
-        // Initialize target nominal delay
-        pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD;
-        
-        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_THD;
-        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_THD;
-        pCb->pcmRdIdx = 0;
-        
-        pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT;
-        pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT;
-        
-        // initialize audio frames
-        for (n=0; n<pCb->maxNumAfCb; n++)
-        {
-            pAfCb = &pCb->afCb[n];
-            pAfCb->sampleDecode = sourceSelect;
-            PAF_PROCESS_ZERO(pAfCb->sampleProcess);
-            pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
-            pAfCb->sampleCount = decOpFrameLen;
-            pAfCb->channelConfigurationRequest.full = 0;
-            pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-            pAfCb->channelConfigurationStream.full = 0;
-            pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-            pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-            
-            // write metadata information updated by decoder
-            pAfCb->bsMetadata_type     = PAF_bsMetadata_channelData;    /* non zero if metadata is attached. */
-            pAfCb->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-            pAfCb->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-            pAfCb->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-        }
-    }
-    else
-    {
-        SW_BREAKPOINT;
-        
-        // Leave the gate
-        GateMP_leave(gateHandle, key);
-
-        return ASP_DECOP_CB_INIT_INV_SOURCE_SEL;
-    }
-
-    // initialize circular buffer current number of frames
-    pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
-    
-    // initialize audio frame PCM buffers
-    pPcmBuf = pCb->pcmBuf;
-    pMetaBuf = pCb->metaBuf;
-    for (n=0; n<pCb->maxNumAfCb; n++)
-    {
-        pAfCb = &pCb->afCb[n];
-        pAfCb->data.nChannels = pCb->maxAFChanNum;
-        pAfCb->data.nSamples = decOpFrameLen;
-        for (i=0; i<pCb->maxAFChanNum; i++)
-        {
-            pAfCb->data.sample[i] = pPcmBuf;
-            memset(pAfCb->data.sample[i], 0, pCb->maxAFSampCount);
-            pPcmBuf += pCb->maxAFSampCount;
-            
-            pAfCb->data.samsiz[i] = 0;
-        }
-        
-        // Initialize metadata buffers
-        for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
-        {
-            pAfCb->pafPrivateMetadata[i].offset = 0; 
-            pAfCb->pafPrivateMetadata[i].size   = 0; 
-            pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
-            pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
-        }
-    }
-    
-    // reset read/write flags
-    if (resetRwFlags)
-    {
-        pCb->writerActiveFlag = 0;
-        pCb->readerActiveFlag = 0;
-        pCb->drainFlag = 0;
-    }
-    
-    // reset stats
-    pCb->readAfWriterInactiveCnt = 0;
-    pCb->readAfNdCnt = 0;
-    pCb->wrtAfReaderInactiveCnt = 0;
-    pCb->wrtAfZeroSampsCnt = 0;
-    pCb->errUndCnt = 0;
-    pCb->errOvrCnt = 0;
-    
-    // Write back circular buffer configuration
-    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
-    // Write back AF circular buffer
-    Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
-    // Write back PCM data
-    for (n=0; n<pCb->maxNumAfCb; n++)
-    {
-        pAfCb = &pCb->afCb[n];
-        Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
-        Cache_wb(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
-        for (i=0; i<pCb->maxAFChanNum; i++)
-        {
-            Cache_wb(pAfCb->data.sample[i], pCb->maxAFSampCount*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
-        }
-    }
-    Cache_wait();
-
-    // Leave the gate
-    GateMP_leave(gateHandle, key);
-    
-    return ASP_DECOP_CB_SOK;
-}
-#endif
-
 // Initialize circular buffer for Stream reads
 Int cbInitStreamRead(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
@@ -687,7 +263,6 @@ Int cbReadAf(
     //
     // Check (writerActiveFlag,drainFlag)=(0,0)
     //
-    //if (((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0)) || (pCb->afLagIdx < pCb->afInitialLag))
     if ((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0))
     {
         //
@@ -774,8 +349,9 @@ Int cbReadAf(
             cbReadMuteWithLastAfInfo(pCb, pAfRd);
             //SW_BREAKPOINT; // debug
             
-#if 0 // also for CB_RW_OP_CAP_PP (***) FL: shows timing of CB underflow
-            // debug
+#if 0 // debug // also for CB_RW_OP_CAP_PP 
+            // Shows timing of CB underflow
+            // ADC B9
             {
                 static Uint8 toggleState = 0;
                 if (toggleState == 0)
@@ -893,19 +469,11 @@ Int cbReadAf(
                                }
                        }
                }
-        // FL: brute force clear of Read AF PCM data
-        // Reset Read AF PCM data
-        //for (i = 0; i < pCb->maxAFChanNum; i++)
-        //{
-        //    if ((streamMask >> i) & 0x1)
-        //    {
-        //        memset(pAfRd->data.sample[i], 0, pCb->strFrameLen);
-        //    }
-        //}
         
-        // FL: This brute force approach shouldn't be necessary if
-        //     decoders properly set, and downstream components
-        //     properly use, number of private metadata in frame
+        // FL: This brute force approach to clearing metadata isn't 
+        //     necessary if decoders properly set, and downstream 
+        //     components properly use, number of private metadata
+        //     in audio frame
         // Reset Read AF metadata
         for (i = 0; i < PAF_MAX_NUM_PRIVATE_MD; i++)
         {
@@ -1089,8 +657,9 @@ Int cbReadAf(
                 // Mute output on underflow
                 cbReadMuteWithLastAfInfo(pCb, pAfRd);
                 
-#if 0 // also for CB_RW_OP_CAP_PP (***) FL: shows timing of CB underflow
-                // debug
+#if 0 // debug // also for CB_RW_OP_CAP_PP 
+                // Shows timing of CB underflow
+                // ADC B9
                 {
                     static Uint8 toggleState = 0;
                     if (toggleState == 0)
@@ -1132,7 +701,9 @@ Int cbReadAf(
         // Read AF complete, update Last CB AF Info
         cbUpdateLastAfInfo(pCb, pAfRd);
 
-#if 0 // also for CB_RW_OP_CAP_PP (***) FL: shows timing of successful CB read
+#if 0 // debug // also for CB_RW_OP_CAP_PP 
+        // Shows timing of successful CB read
+        // ADC B8
         {
             static Uint8 toggleState = 0;
             if (toggleState == 0)
@@ -1161,20 +732,6 @@ Int cbReadAf(
 #endif
     }
     
-#if 0
-    if (pCb->drainFlag == 1)
-    {
-        //
-        // Writer inactive, but remaining frames in circular buffer.
-        // Update drain flag.
-        //
-        if (pCb->numAfCb <= 0)
-        {
-            pCb->drainFlag = 0;
-        }
-    }
-#endif
-    
     // Write back circular buffer configuration.
     // NOTE: Probably only a subset of this information needs to be updated.
     Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
@@ -1186,81 +743,12 @@ Int cbReadAf(
     return ASP_DECOP_CB_SOK;
 }
 
-#if 0
-// Generate mute AF on circular buffer read
-static Void cbReadAfMute(
-    PAF_AudioFrame *pAfRd,      // audio frame into which to read
-    Int16 strFrameLen           // stream frame length (output transaction size)
-)
-{
-    PAF_ChannelMask_HD streamMask;
-    Int8 i;
-    
-    pAfRd->sampleDecode = PAF_SOURCE_PCM;
-    PAF_PROCESS_ZERO(pAfRd->sampleProcess);
-    pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
-    pAfRd->sampleCount = strFrameLen;
-    pAfRd->channelConfigurationRequest.full = 0;
-    pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-    pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-    pAfRd->channelConfigurationStream.full = 0;
-    pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-    pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-    
-    // compute stream mask
-    streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
-    // Clear PCM data
-    for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
-    {
-        if ((streamMask >> i) & 0x1)
-               {
-            memset(pAfRd->data.sample[i], 0, strFrameLen*sizeof(PAF_AudioData));
-        }
-        pAfRd->data.samsiz[i] = 0;
-    }
-    // write metadata information updated by decoder
-    pAfRd->bsMetadata_type     = PAF_bsMetadata_channelData;    /* non zero if metadata is attached. */
-    pAfRd->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-    pAfRd->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-    pAfRd->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-}
-#endif
-
-#if 0 // FL: unused
-// Init last audio frame configuration info 
-static Void cbInitLastAfInfo(
-    PAF_AudioFrame *pAfRd      // last audio frame stored in CB instance
-)
-{
-    pAfRd->sampleDecode = PAF_SOURCE_PCM;
-    PAF_PROCESS_ZERO(pAfRd->sampleProcess);
-    pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
-    pAfRd->sampleCount = DEF_DEC_OP_FRAME_LEN;
-    pAfRd->channelConfigurationRequest.full = 0;
-    pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
-    pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
-    pAfRd->channelConfigurationStream.full = 0;
-    pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
-    pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
-
-    pAfRd->bsMetadata_type     = PAF_bsMetadata_none;           /* non zero if metadata is attached. */
-    pAfRd->pafBsMetadataUpdate = 0;                             /* indicates whether bit-stream metadata update */
-    pAfRd->numPrivateMetadata  = 0;                             /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
-    pAfRd->bsMetadata_offset   = 0;                             /* offset into audio frame for change in bsMetadata_type field */
-}
-#endif
-
 // Update last audio frame configuration info 
 static Void cbUpdateLastAfInfo(
     PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer control
     PAF_AudioFrame *pAfUpd      // audio frame used for update
 )
 {
-    // FL: full copy shouldn't be necessary
-    //  Note currently (data.nChannels, data.nSamples)=(32,256) is fixed in ASOT stream AF.
-    //  There parameters aren't copied from CB on CB read.
-    //memcpy (&pCb->lastAf, pAfUpd, sizeof(PAF_AudioFrame));
-
     // These are parameters used in cbReadMuteWithLastAfInfo()
     pCb->lastAf.sampleDecode = pAfUpd->sampleDecode;
     pCb->lastAf.sampleRate = pAfUpd->sampleRate;
@@ -1282,11 +770,7 @@ static Void cbReadMuteWithLastAfInfo(
     pAfRd->sampleRate  = pCb->lastAf.sampleRate;
     pAfRd->sampleCount = pCb->strFrameLen;
     pAfRd->channelConfigurationRequest.full     = pCb->lastAf.channelConfigurationRequest.full;
-    //pAfRd->channelConfigurationRequest.part.sat = pCb->lastAf.channelConfigurationRequest.part.sat; // FL: not necessary since full in union already copied
-    //pAfRd->channelConfigurationRequest.part.sub = pCb->lastAf.channelConfigurationRequest.part.sub;
     pAfRd->channelConfigurationStream.full      = pCb->lastAf.channelConfigurationStream.full;
-    //pAfRd->channelConfigurationStream.part.sat  = pCb->lastAf.channelConfigurationStream.part.sat;
-    //pAfRd->channelConfigurationStream.part.sub  = pCb->lastAf.channelConfigurationStream.part.sub;
     
     // compute stream mask
     streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
index 9dcad2802efaa57e7fcb0a262978240013cddc28..cc48d809c1e8f7b61042b22f8e5ee4d5da1a98e7 100644 (file)
@@ -417,7 +417,7 @@ static Int decodeInit(
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
 
-            // FL: send dec activate message to slave
+            // send dec activate message to slave
             argIdx = 0; // set decIdx (zone index)
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
@@ -428,7 +428,7 @@ static Int decodeInit(
                 return ASIP_ERR_DECODE_MSG; // temporary
             }
 
-            // FL: send dec reset message to slave
+            // send dec reset message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
@@ -444,7 +444,6 @@ static Int decodeInit(
                 errno = *(Int32 *)&decMsgBuf[argIdx];
             }
 
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
@@ -659,7 +658,7 @@ Int decInfoSnd(
                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
                 }
                 else {
-                    TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
+                    //TRACE_TERSE1("decDecodeInfo: AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
                         pAstCfg->xDec[zD].decodeControl.sampleRate);
@@ -700,20 +699,19 @@ Int decInfoSnd(
                 return DEC_ERR_INFO_SNDMSG;
             }
 
-            // debug, capture input buffer
-            //capIb(pAstCfg->xInp[zI].pInpBuf);
-            //gCapIb_cnt++;
+#if 0 // debug
+            // capture input buffer
+            capIb(pAstCfg->xInp[zI].pInpBuf);
+            gCapIb_cnt++;
+#endif
 
-#if 1
-            // (***) FL: revisit
             // write back Inp configuration
             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
             // write back Dec configuration
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
-#endif
 
-            // FL: send info message to slave
+            // send info message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSnd(ASP_SLAVE_DEC_INFO, decMsgBuf) != ASP_MSG_NO_ERR)
@@ -797,12 +795,9 @@ Int decInfoAck(
                 errno = *(Int32 *)&decMsgBuf[argIdx];
             }
 
-#if 1
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
-#endif
 
             if (errno) {
                 TRACE_TERSE1("decInfoAck return error errno 0x%x.", errno);
@@ -885,15 +880,16 @@ static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
 
-            // FL: debug, capture input buffer
-            //capIbPcm(pAstCfg->xInp[z].pInpBuf);
-
-            // (***) FL: revisit
+#if 0 // debug
+            // capture input buffer
+            capIbPcm(pAstCfg->xInp[z].pInpBuf);
+#endif
+            
             // write back Dec configuration
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
 
-            // FL: send decode message to slave
+            // send decode message to slave
             errno  = 0;
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
@@ -986,7 +982,6 @@ static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
                 }
             }
 
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
index 4678ba0c6e61286bfb3abf6c1a3d277ecdb047f9..141e1e23dd2195211b20730de08747229e945239 100644 (file)
@@ -56,6 +56,8 @@ All rights reserved.
 #include <sio.h>
 #include <pafsio_ialg.h>
 
+#include "ioConfig.h"
+
 #include "common.h"
 #include "paf_heapMgr.h"
 #include "aspMsg_common.h"
@@ -69,15 +71,11 @@ All rights reserved.
 
 #include "pfp/pfp.h"
 #include "pfp_app.h"        /* contains all PFP ID's */
-#include "ioConfig.h"
-
 Int32 gNumPfpAsit1=0; // debug
 Int32 gNumPfpAsit2=0;
 
-
-
-// FL: debug
-#include "dbgCapAf.h"
+// debug
+//#include "dbgCapAf.h"
 
 
 // -----------------------------------------------------------------------------
@@ -304,7 +302,6 @@ extern UInt32 gAspProfileEnable;
 //
 
 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
-//#define ENC_Handle PCE_Handle /* works for all: PCE */
 
 #define __TASK_NAME__  "TaskAsip"
 
@@ -314,13 +311,9 @@ extern UInt32 gAspProfileEnable;
 //
 
 #define ASIP_FRAMELEN_SS_DEFAULT    ( 256 )
-// FL: pP->frameLength
-//#define ASIP_FRAMELEN_SS_PCM        ( FRAMELENGTH )
-// FL: (***) hard-coded
-#define ASIP_FRAMELEN_SS_DDP_AC3    ( 1536 )
-// FL: (***) hard-coded
-#define ASIP_FRAMELEN_SS_THD        ( 1536 )        
-
+#define ASIP_FRAMELEN_SS_PCM        ( FRAMELENGTH ) // pP->frameLength
+#define ASIP_FRAMELEN_SS_DDP_AC3    ( 1536 )        // hard-coded
+#define ASIP_FRAMELEN_SS_THD        ( 1536 )        // hard-coded
 #define ASIP_FRAMELEN_SS_DTS        ( 512 )         
 
 // Compute decoder frame length based on selected source
@@ -370,8 +363,8 @@ extern struct {
     IALG_Status *pStatus[512];
 } IACP_STD_BETA_TABLE;
 
-// FL: debug
-#include "evmc66x_gpio_dbg.h"
+// debug
+//#include "evmc66x_gpio_dbg.h"
 
 /*
  *  ======== taskAsipFxnInit ========
@@ -493,22 +486,19 @@ Void taskAsipFxnInit(
             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
     }
 
-    // (***) FL: revisit
     // write back AST shared configuration
     Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
     Cache_wait();
 
-    // (***) FL: revisit
     // write back Dec configuration
     Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
     Cache_wait();
 
-    // (***) FL: revisit
     // write back entire beta table
     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_wait();
 
-    // FL: send start initialization message to slave
+    // send start initialization message to slave
     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
     pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
@@ -522,9 +512,9 @@ Void taskAsipFxnInit(
         SW_BREAKPOINT;
     }
     // wait for initialization complete message from slave
+    // no other thread is allowed to run until Slave finishes startup
     do {
-        //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
-        status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
+        status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0);
     } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
         (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
@@ -541,7 +531,6 @@ Void taskAsipFxnInit(
         SW_BREAKPOINT;
     }
 
-    // (***) FL: revisit
     // invalidate Status structure addresses for Beta Units initialized on Slave
     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
@@ -565,9 +554,7 @@ Void taskAsipFxnInit(
     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_AAC]) Log_info0("WARNING: beta unit for Dec==NULL");
     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_AAC2]) Log_info0("WARNING: beta unit for Dec==NULL");
 
-    // (***) FL: revisit
     // invalidate Status structures for Beta Units initialized on Slave
-    //
     if (IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE] != NULL)
     {
         Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
@@ -662,7 +649,7 @@ Void taskAsipFxnInit(
         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DTS);
     }
 #endif
-    // (***) FL: revisit
+
     // invalidate Dec configuration
     Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
     Cache_wait();
@@ -860,12 +847,10 @@ Void taskAsipFxn_Not_Used(
         // At this point we have an enabled input and want to decode something.
         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
         // when no decoder is selected there are no calls to IB
-        //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
                                      GATEMP_INDEX_DEC);
         pfpBegin(PFP_ID_ASIT_1, pAsitCfg->taskHandle);  // PFP begin
         gNumPfpAsit1++;
-        // (***) FL: re-visit, hard-coded to use FRAMELENGTH (pP->frameLength) inside function
         errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, tempVar8, NULL);
         pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);         // PFP end
         gNumPfpAsit1--;
@@ -966,7 +951,8 @@ Void taskAsipFxn_Not_Used(
             continue;
         }
 
-#if 0 // debug, reset IB capture buffer
+#if 0 // debug
+        // reset IB capture buffer
         capIbReset();
         gCapIbReset_cnt++;
         Log_info0("capIbReset()");
@@ -1008,7 +994,7 @@ Void taskAsipFxn_Not_Used(
         // Increase priority level since decoding complete
         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
 
-        // FL: send dec exit message to slave
+        // send dec exit message to slave
         if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
             != ASP_MSG_NO_ERR)
         {
@@ -1258,7 +1244,6 @@ PAF_ASIT_initPhaseConfig(
         Int zI = pP->inputsFromDecodes[z];
         pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
         pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
-        //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
     }
 
     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
@@ -1490,7 +1475,6 @@ PAF_ASIT_initPhaseCommon(
     return 0;
 } //PAF_ASIT_initPhaseCommon
 
-// (***) FL: candidate for removal
 // -----------------------------------------------------------------------------
 // ASIT Initialization Function - Algorithm Keys
 //
@@ -1522,25 +1506,6 @@ PAF_ASIT_initPhaseAlgKey(
 
     TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
 
-#if 0 // FL: slave    
-    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]))) 
-            {
-                pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
-                /* Cast in interface, for now --Kurt */
-            }
-            else
-            {
-                pC->xDec[z].decAlg[s] = NULL;
-            }
-        }
-    }
-#endif
-
     return 0;
 } //PAF_ASIT_initPhaseAlgKey
 
@@ -1620,7 +1585,6 @@ PAF_ASIT_initPhaseDevice(
     return 0;
 } //PAF_ASIT_initPhaseDevice
 
-// (***) FL: move to ASOT
 // -----------------------------------------------------------------------------
 // ASIT Initialization Function - Decoder Output Circular Buffer
 //
@@ -1654,7 +1618,6 @@ PAF_ASIT_initPhaseDecOpCircBuf(
     Int betaPrimeOffset;
     Int zS;
 
-    // FL: (***)revisit
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
     as = pAstCfg->as;
     zMS = pAstCfg->masterStr;
@@ -1762,7 +1725,7 @@ PAF_ASIT_initPhaseDecOpCircBuf(
         errno = cbInit(pCb);
         if (errno)
         {
-            SW_BREAKPOINT; // FL: debug
+            //SW_BREAKPOINT; // debug
             return errno;
         }
     }
@@ -2158,10 +2121,8 @@ PAF_ASIT_autoProcessing(
         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
         return errno;
     }
-    //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
-    //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
-    frameLength = FRAMELENGTH; // (***) FL: fix PCM frameLength
     
+    frameLength = FRAMELENGTH; // fix PCM frameLength
     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
     {
@@ -2187,8 +2148,9 @@ PAF_ASIT_autoProcessing(
     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
     if (nbytes == -DIBERR_SYNC)
     {
-#if 0 // (***) FL: shows timing of autosync restart
-        // (***) debug // B5
+#if 0 // debug
+        // Shows timing of autosync restart
+        // ADC B5
         {
             static Uint8 toggleState = 0;
             if (toggleState == 0)
@@ -2305,7 +2267,7 @@ PAF_ASIT_decodeProcessing(
     Int zMD;
     //Int zMS;
     Int frame; // decoder input frame count
-    Int block; // (***) FL: formerly  -- decoder output block count / input frame
+    Int block; // decoder output block count / input frame
     Int8 tempVar8, temp2Var8;
     
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
@@ -2707,7 +2669,7 @@ PAF_ASIT_decodeInit(
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
 
-            // FL: send dec activate message to slave
+            // send dec activate message to slave
             argIdx = 0; // set decIdx (zone index)
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE, 
@@ -2718,11 +2680,7 @@ PAF_ASIT_decodeInit(
                 return -1; // temporary
             }           
 
-#if 0 // FL: decoder activate call, slave
-            if (decAlg[z]->fxns->algActivate)
-                decAlg[z]->fxns->algActivate (decAlg[z]);
-#endif
-            // FL: send dec reset message to slave
+            // send dec reset message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE, 
@@ -2738,17 +2696,10 @@ PAF_ASIT_decodeInit(
                 errno = *(Int32 *)&decMsgBuf[argIdx];                
             }   
 
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
             
-#if 0 // FL: decoder reset call, slave
-            if (dec->fxns->reset
-                && (errno = dec->fxns->reset (dec, NULL,
-                                              &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
-                return errno;
-#endif
             if (errno != 0)
             {
                 return errno;
@@ -2760,36 +2711,13 @@ PAF_ASIT_decodeInit(
             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
                                   tempVar8, GATEMP_INDEX_DEC);
             
-#if 0 // FL: change handle to decIdx (zone index)
-            frameLength = pP->fxns->computeFrameLength(decAlg[z], 
-                FRAMELENGTH,
-                pC->xDec[z].decodeStatus.bufferRatio);
-#endif
-#if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
-            frameLength = pP->fxns->computeFrameLength(z, 
-                FRAMELENGTH, 
-                pC->xDec[z].decodeStatus.bufferRatio);
-#else
             // Compute decoder frame length based on source selection
             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
-#endif    
             
             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
           
-#if 0 // FL: Moved to ARM:ASDT:INFO
-            // Initialize decoder output circular buffer for selected source
-            errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
-            if (errno)
-            {
-                SW_BREAKPOINT; // debug
-                return errno;
-            }
-            // debug
-            cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
-#endif
-            
             if (z != zMD) 
             {
                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
@@ -2867,12 +2795,8 @@ PAF_ASIT_decodeInfo(
     Int8 tempVar8;
     Int tempVar;
     char decMsgBuf[ASP_MSG_BUF_LEN];
-    // FL: revisit
-    //Int size;
-    //PAF_InpBufConfig *pIpBufConfig;
-    // debug
-    //UInt32 curTime;
 
+    
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
     as = pAstCfg->as;
     zMD = pAstCfg->masterDec;
@@ -2916,7 +2840,7 @@ PAF_ASIT_decodeInfo(
                 }
                 else
                 {
-                    TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
+                    //TRACE_TERSE1("PAF_ASIT_decodeInfo: AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus, 
                         pAstCfg->xDec[zD].decodeControl.sampleRate);
@@ -2950,13 +2874,15 @@ PAF_ASIT_decodeInfo(
             return ASPERR_RECLAIM;
         }
         
-#if 0 // debug, capture input buffer
+#if 0 // debug
+        // capture input buffer
         capIb(pAstCfg->xInp[zMI].pInpBuf);
         gCapIb_cnt++;
 #endif
         
-#if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
-        // (***) debug // B5
+#if 0 // debug
+        // Shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
+        // ADC B5
         {
             static Uint8 toggleState = 0;
             if (toggleState == 0)
@@ -2967,15 +2893,6 @@ PAF_ASIT_decodeInfo(
         }
 #endif
 
-        //
-        // Simulate Rx SIO_reclaim() pend
-        //
-        //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER); 
-        //curTime = Clock_getTicks();
-        //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);        
-        //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
-        //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
-        
         gAsipRxSioReclaimCnt++;
     } //pAstCfg->xInp[zMI].hRxSio
 
@@ -2999,16 +2916,13 @@ PAF_ASIT_decodeInfo(
                 return errno;
             }
 
-#if 1
-            // (***) FL: revisit
             // write back Inp configuration
             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
             // write back Dec configuration
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
-#endif
             
-            // FL: send info message to slave
+            // send info message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE, 
@@ -3024,18 +2938,10 @@ PAF_ASIT_decodeInfo(
                 errno = *(Int32 *)&decMsgBuf[argIdx];                
             }             
 
-#if 1
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();                            
-#endif            
             
-#if 0 // FL: decoder info call, slave
-            if (dec->fxns->info
-                && (errno = dec->fxns->info (dec, NULL,
-                                             &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus))) 
-#endif
             if (errno)
             {
                 TRACE_TERSE1("return error errno 0x%x.", errno);
@@ -3091,37 +2997,6 @@ PAF_ASIT_decodeInfo(
         }
     }
 
-#if 0 // FL: ASDT (slave)
-    // TODO: move this to start of this function so that it doesn't affect IO timing
-    // Initialize audio frame(s)
-    //    Re-initialize audio frame if there is an associated decode and
-    //    that decode doesn't have a valid input or is turned off
-    for (z=STREAM1; z < STREAMN; z++) 
-    {
-        Int reset = 0;
-        for (zX = DECODE1; zX < DECODEN; zX++) 
-        {
-            if (pP->streamsFromDecodes[zX] == z) 
-            {
-                zI = pP->inputsFromDecodes[zX];
-                if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
-                {
-                    reset = 1;
-                }
-            }
-        }
-        if (reset) 
-        {
-            TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
-            pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
-        }
-        else
-        {
-            TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
-        }
-    }
-#endif    
-
     return 0;
 } //PAF_ASIT_decodeInfo
 
@@ -3272,17 +3147,6 @@ PAF_ASIT_decodeDecode(
     as = pAstCfg->as;
     (void)as; // clear compiler warning in case not used with tracing disabled
 
-#if 0 // FL: slave
-    // Clear samsiz for all channels - MID 208.
-    for (z=STREAM1; z < STREAMN; z++) 
-    {
-        for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
-        {
-            pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
-        }
-    }
-#endif    
-
     // Decode data
     for (z=DECODE1; z < DECODEN; z++) 
     {
@@ -3298,16 +3162,16 @@ PAF_ASIT_decodeDecode(
                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
 
-#if 0 // debug, capture input buffer
+#if 0 // debug
+            // capture input buffer
             capIbPcm(pAstCfg->xInp[z].pInpBuf);
 #endif
             
-            // (***) FL: revisit
             // write back Dec configuration
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();                        
 
-            // FL: send decode message to slave
+            // send decode message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE, 
@@ -3331,12 +3195,11 @@ PAF_ASIT_decodeDecode(
                 }
             }           
 
-            // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
 
-#if 0 // FL: decoder decode call, slave
+#if 0 // decoder decode call, slave
             if (dec->fxns->decode
                 && (errno = dec->fxns->decode (dec, NULL,
                                                &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct))) 
@@ -3351,20 +3214,8 @@ PAF_ASIT_decodeDecode(
             as_traceChannels(pC, z);
 #endif
 
-#if 0 // FL: change handle to decIdx (zone index)  
-            frameLength = pP->fxns->computeFrameLength(decAlg[z],
-                FRAMELENGTH, 
-                pC->xDec[z].decodeStatus.bufferRatio);
-#endif
-#if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
-            frameLength = pP->fxns->computeFrameLength(z, 
-                FRAMELENGTH, 
-                pC->xDec[z].decodeStatus.bufferRatio);
-#else
             // Compute decoder frame length based on source selection
             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
-#endif
-
 
 //#ifdef PROFILER
 //            // modify for different decoders
@@ -3405,33 +3256,6 @@ PAF_ASIT_decodeDecode(
         }
     } // z=DECODE1 to DECODEN
 
-#if 0 // FL: ASDT (slave)
-    // Set up audio frames not decoded into
-    //    Re-initialize audio frame if there is an assocatiated decode and
-    //    that decode doesn't have a valid input or is turned off
-    for (z=STREAM1; z < STREAMN; z++) 
-    {
-        Int zX;
-        Int reset = 0;
-        for (zX = DECODE1; zX < DECODEN; zX++) 
-        {
-            if (pP->streamsFromDecodes[zX] == z) 
-            {
-                Int zI = pP->inputsFromDecodes[zX];
-                if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
-                    reset = 1;
-            }
-        }
-        if (reset) 
-        {
-            TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
-            pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
-        }
-        else
-            TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
-    }
-#endif
-    
     return 0;
 } //PAF_ASIT_decodeDecode
 
@@ -3568,7 +3392,7 @@ PAF_ASIT_decodeComplete(
                                  &pAstCfg->xDec[z].decodeStatus);
 #endif /* PAF_ASP_FINAL */
 
-            // FL: send dec deactivate message to slave
+            // send dec deactivate message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
@@ -3578,11 +3402,6 @@ PAF_ASIT_decodeComplete(
                 SW_BREAKPOINT;
                 return -1;
             }
-
-#if 0 // FL: decoder deactivate call, slave
-            if (decAlg[z]->fxns->algDeactivate)
-                decAlg[z]->fxns->algDeactivate (decAlg[z]);
-#endif    
         }
         else 
         {
@@ -3714,58 +3533,6 @@ PAF_ASIT_sourceDecode(
 
 // -----------------------------------------------------------------------------
 
-#if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
-Int
-PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
-{
-    Int errno = 0;
-    Int zMD = pC->masterDec;
-    Int zI = pP->inputsFromDecodes[z];
-
-    // only handle real errors, on primary input, for writeDECModeContinuous
-    if ( !( error &&
-            z == zMD ))
-        return error;
-
-    TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
-    TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
-
-    if (pC->xInp[zI].hRxSio) {
-        DEC_Handle dec;
-
-        if (errno = SIO_idle (pC->xInp[zI].hRxSio))
-            return errno;
-
-        // indicates (primary) input not running
-        pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
-
-        pC->xInp[zI].inpBufConfig.deliverZeros = 1;
-
-        // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
-        pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
-
-        if (decAlg[z]->fxns->algDeactivate)
-            decAlg[z]->fxns->algDeactivate (decAlg[z]);
-
-        decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
-        dec = (DEC_Handle )decAlg[z];
-
-        TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
-                    pC->as+z));
-
-        if (decAlg[z]->fxns->algActivate)
-            decAlg[z]->fxns->algActivate (decAlg[z]);
-
-        if (dec->fxns->reset
-            && (errno = dec->fxns->reset (dec, NULL,
-                                          &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
-            return errno;
-    }
-
-    return errno;
-} //PAF_AST_decodeHandleErrorInput
-#endif
-
 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
 
 //------------------------------------------------------------------------------
index 1bb59434824269b99a2d3a70a68d39c3a7bb6d25..a9b791c0a7d075aa293241a4f81588cd9c092123 100644 (file)
@@ -69,23 +69,16 @@ typedef struct PAF_ASIT_Fxns {
     Int (*autoProcessing) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, ALG_Handle);
     Int (*decodeProcessing) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int);    
     Int (*decodeCommand) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *);
-    //Int (*encodeCommand) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *);
     Int (*decodeInit) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int);
     Int (*decodeInfo) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, Int);
     Int (*decodeInfo1) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, Int);
     Int (*decodeInfo2) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, Int);
     //Int (*decodeCont) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, ALG_Handle *, Int, Int);
     Int (*decodeDecode) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, Int, Int);
-    //Int (*decodeStream) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int);
-    //Int (*decodeEncode) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int);
     Int (*decodeFinalTest) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int, Int);    
     Int (*decodeComplete) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, ALG_Handle *, Int, Int);
     Int (*selectDevices) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *);
     Int (*sourceDecode) (const struct PAF_ASIT_Params *, const struct PAF_ASIT_Patchs *, struct PAF_ASIT_Config *, Int);    
-    //Int (*startOutput) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *);
-    //Int (*stopOutput) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *);
-    //Int (*setCheckRateX) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int);
-    //Int (*streamChainFunction) (const struct PAF_AST_Params *, const struct PAF_AST_Patchs *, struct PAF_AST_Config *, Int, Int, Int);
     Int (*deviceAllocate) (SIO_Handle *, int, int, int, Ptr);
     Int (*deviceSelect) (SIO_Handle *, int, int, Ptr);
     Int (*computeFrameLength) (Int, Int, Int);
@@ -542,14 +535,6 @@ PAF_ASIT_sourceDecode(
     Int x
 );
 
-//   Purpose:   Decoding Function for terminating output.
-Int
-PAF_AST_stopOutput(
-    const PAF_ASIT_Params *pP, 
-    const PAF_ASIT_Patchs *pQ, 
-    PAF_ASIT_Config *pAsitCfg
-);
-
 //   Purpose:   Common Function for processing algorithm chains.
 Int
 PAF_AST_streamChainFunction(
index 9275da7d2bd0a2690ddceb1e3f8a60602a658614..3db43196fd95135dd0c57e1df4c8330596d30a81 100644 (file)
@@ -182,6 +182,9 @@ enum {
 int asipLoopCount1, asipLoopCount2;
 Int asipErrno;
 Int inputReadyForProcessing;
+
+// FL: debug
+#include "evmc66x_gpio_dbg.h"
 #endif
 
 Event_Handle asitEvent;
index ff4c54eabda3bbe3d6fdf07b2fbe08b876dd85de..cbab851de909de9f6ab7f1015d584a56538eef6d 100644 (file)
@@ -32,354 +32,444 @@ All rights reserved.
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
-#if 0
 /*
- *  ======== audioStreamOutProc.c ========
+ *  ======== audioStreamOutDec.c ========
  */
 
 #include <string.h> // for memset
 #include <xdc/runtime/Log.h>
-#include <xdc/runtime/Error.h>
-#include <xdc/runtime/Memory.h>
-#include <ti/sysbios/knl/Clock.h>
-#include <ti/sysbios/knl/Task.h>
+#include <xdc/std.h>
 
 #include "paferr.h"
-#include <acp_mds.h>
-#include <pcm.h>
-#include <pce.h>
-#include <pafsio_ialg.h>
-#include <stdasp.h>
-#include <doberr.h>
+#include "pafsio_ialg.h"
+#include "pce.h"
+#include "stdasp.h"
 #include "asperr.h"
 
-#include "common.h"
-#include "aspMsg_common.h"
-#include "aspMsg_master.h"
 #include "aspDecOpCircBuf_master.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamOutProc.h"
+#include "audioStreamOutIo.h"
+#include "audioStreamOutDec.h"
 
-// FL: debug
-#include "evmc66x_gpio_dbg.h"
 #define ENC_Handle PCE_Handle /* works for all: PCE */
 
-extern UInt32 gCbReadAfErr      ; // read circular buffer error count, not including underflows
-extern UInt32 gDecOpCbRdAfUnd   ; // decoder output circular buffer underflow count
-extern UInt32 gMaxDecOpCbRdAfUnd; // max (consecutive) decoder output circular buffer underflow count
-
-extern PAF_AST_OutIO *outIOtemp;    /* Output I/O */
-
-Int
-asopDecodeInit(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pC,
-       asopDecProc_t *dec
+// debug
+#include "evmc66x_gpio_dbg.h"
+#include "dbgCapAf.h"
+PAF_AST_DecOpCircBufStats gCbStats; // circular buffer stats
+
+// debug
+// Underflow threshold before circular buffer reset and return error to Top-Level FSM
+#define DEC_OP_CB_RDAF_UND_THR  ( 80 ) // arbitrary setting
+UInt32 gCbReadAfErr         =0; // read circular buffer error count, not including underflows
+UInt32 gDecOpCbRdAfUnd      =0; // decoder output circular buffer underflow count
+UInt32 gMaxDecOpCbRdAfUnd   =0; // max (consecutive) decoder output circular buffer underflow count
+UInt32 gMasterCbResetCnt    =0; // master circular buffer reset count
+
+
+//   Purpose:   Common Function for processing algorithm chains
+static Int streamChainFunction(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int iChainFrameFxns, 
+    Int abortOnError, 
+    Int logArg
+);
+
+//   Purpose:   ASOT Function for Output reset
+Int asopDecOutProcReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame
 )
 {
-    PAF_AST_Config *pAstCfg;
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
-    Int as;                             /* Audio Stream Number (1, 2, etc.) */
-    Int z;                              /* decode counter */
-    Int errno;                          /* error number */
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoOut *pOut;        // ASOT IO configuration
+    Int as;                     // Audio Stream Number (1, 2, etc.) */
     Int zO, zS;
-
-    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
-
-    // Reset audio frame pointers to original values
-    // (may be needed if error occurred).
-    for (z=STREAM1; z < STREAMN; z++)
-    {
-        Int ch;
-        for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
-        {
-            if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
-            {
-                pAstCfg->xStr[z].audioFrameChannelPointers[ch] =
-                    pAstCfg->xStr[z].origAudioFrameChannelPointers[ch];
-            }
-        }
-    }
-
-    // Reset audio frame meta data elements
-    {
-        Int i;
-
-        for (z=STREAM1; z < STREAMN; z++)
-        {
-            pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
-            pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
-            pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
-            pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
-
-            for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
-            {
-                pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
-                pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
-            }
-        }
-    }
-
+    Int z;                      // encode counter
+    Int errno;                  // error number
+    Int status;                 // status code
+    
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
     as = pAstCfg->as;
-    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
 
-    for (z=DECODE1; z < DECODEN; z++)
-    {
-        // Start decoder output circular buffer reads
-        errno = cbReadStart(pCbCtl, z);
-        if (errno) {
-            TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
-            SW_BREAKPOINT; // FL: debug
-            return errno;
-        }
-
-        gCbReadAfErr = 0;         // reset read circular buffer error count
-        gDecOpCbRdAfUnd = 0;      // reset decoder output circular buffer underflow count
-        gMaxDecOpCbRdAfUnd = 0;   // reset max decoder output circular buffer underflow count
-
-        // FL: debug
-        //cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
-    }
-
-    // TODO: move this to start of this function so that it doesn't affect IO timing
-    for (z=ENCODE1; z < ENCODEN; z++)
+    for (z=ENCODE1; z < ENCODEN; z++) 
     {
         zO = pP->outputsFromEncodes[z];
         zS = pP->streamsFromEncodes[z];
-        //if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
-        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)
+        if (pOut[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode) 
         {
             Int select = pAstCfg->xEnc[z].encodeStatus.select;
             ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
             ENC_Handle enc = (ENC_Handle )encAlg;
-            TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
+
+            TRACE_VERBOSE1("AS%d: PAF_ASOT_outputReset: initializing encode", as+zS);
+
             if (encAlg->fxns->algActivate)
             {
-                encAlg->fxns->algActivate (encAlg);
+                encAlg->fxns->algActivate(encAlg);
             }
-            if (enc->fxns->reset
-                && (errno = enc->fxns->reset(enc, NULL,
-                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
+            
+            if (enc->fxns->reset)
             {
-                return errno;
+                errno = enc->fxns->reset(enc, NULL, 
+                    &pAstCfg->xEnc[z].encodeControl, 
+                    &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    status = ASOP_DOP_ERR_RESET_ENCRESET;
+                    return status;
+                }
             }
         }
-    }
-
-    //JXTODO: move decodeInfo1 to output task state machine
-    /*if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
-    {
-        TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x.  break after decodeInfo1", errno);
-        break;
-    }*/
-
-    dec->frame = 0;
-    dec->block = 0;
-
-       return ASOP_DECODE_NO_ERR;
-} /* asopDecodeInit */
-
-
-// -----------------------------------------------------------------------------
-// ASOT Decoding Function - Info Processing, Initial
-//
-//   Name:      PAF_ASOT_decodeInfo1
-//   Purpose:   Decoding Function for processing information in a manner that
-//              is unique to initial frames of input data.
-//   From:      AST Parameter Function -> decodeProcessing
-//   Uses:      See code.
-//   States:    x
-//   Return:    Error number in standard or SIO form (0 on success).
-//   Trace:     Message Log "trace" in Debug Project Configuration reports:
-//              * State information as per parent.
-//
-// (***) FL: setup output (ASP chain reset, ENC reset, setCheckRateX, start output)
-//           Contained in INFO1 in combined FSM.
-// Establish secondary timing
-Int
-asopDecodeInfo1(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pC,
-    Int frame
+    }    
+    
+    return status;
+}
+
+//   Purpose:   Reset ASP chain, execute ENC info, and initiate Output
+Int asopDecOutProcInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
 )
 {
-    PAF_AST_Config *pAstCfg;
-    Int z;                              /* decode/encode counter */
-    Int errno;                          /* error number */
-
-    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoOut *pOut;        // ASOT IO configuration
+    Int zO, zS; 
+    Int z;                      // decode/encode counter
+    Int errno;                  // error number
+    Int status;                 // status code
+    
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
 
-    // run the chain of ASP's on the stream.
-    TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
-    if (errno = pP->fxns->streamChainFunction(pP, pQ, pC,
-        PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame))
+    //
+    // Reset ASP chain
+    //
+    TRACE_VERBOSE0("asopDecOutProcInfo1: calling streamChainFunction.");
+    errno = streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
+    if (errno)
     {
-        TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
-        return errno;
+        TRACE_TERSE1("asopDecOutProcInfo1: streamChainFunction returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_INFO1_ASPCHAINRESET;
+        return status;
     }
 
-    TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
-    for (z=ENCODE1; z < ENCODEN; z++)
+    //
+    // Encode Info
+    //
+    TRACE_VERBOSE0("asopDecOutProcInfo1: calling enc->info.");
+    for (z=ENCODE1; z < ENCODEN; z++) 
     {
         Int zO = pP->outputsFromEncodes[z];
-        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)
+        if (pOut[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode) 
         {
             Int select = pAstCfg->xEnc[z].encodeStatus.select;
             ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
             ENC_Handle enc = (ENC_Handle )encAlg;
-            if (enc->fxns->info
-                && (errno = enc->fxns->info(enc, NULL,
-                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
+            
+            if (enc->fxns->info)
             {
-                TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
-                return errno;
+                errno = enc->fxns->info(enc, NULL,
+                    &pAstCfg->xEnc[z].encodeControl, 
+                    &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    TRACE_TERSE1("asopDecOutProcInfo1: info returns errno 0x%x ", errno);
+                    status = ASOP_DOP_ERR_INFO1_ENCINFO;
+                    return status;
+                }
             }
         }
     }
 
-    if (errno = pP->fxns->setCheckRateX(pP, pQ, pC, 0))
+    //
+    // Initialize Output components
+    //
+
+    // FL, New IO: Something needed in new IO
+    // FL, New IO: API for multiple Outputs
+    // FL, New IO: SIO calls need to be checked
+    errno = asopSetCheckRateX(pP, pQ, pAsotCfg, 0);
+    if (errno)
+    {
+        TRACE_TERSE1("asopDecOutProcInfo1: info returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_INFO1_SETRATEX;
+        return status;
+    }
+    
+    // FL, New IO: API for multiple Outputs
+    // FL, New IO: SIO calls need to be checked
+    errno = asopStartOutput(pP, pQ, pAsotCfg);
+    if (errno)
+    {
+        TRACE_TERSE1("asopDecOutProcInfo1: asopStartOutput returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_INFO1_STARTOUTPUT;
+        return status;
+    }    
+    
+    // Find first Output associated with Master Stream
+    zO = OUTPUT1;
+    for (z=ENCODE1; z < ENCODEN; z++)
     {
-        // ignore if rateX has changed since we haven't, but are about to,
-        // start the output. If we didn't ignore this case then the state machine
-        // would restart unnecessarily, e.g. in the case of SRC, resulting in
-        // added latency.
-        if (errno != ASPERR_INFO_RATECHANGE)
+        zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
+        if (zS == pAstCfg->masterStr)
         {
-            TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
-            return errno;
+            // This Encoder is associated with Master Stream.
+            // Note other Encoder can also be associated with Master Stream.
+            zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
         }
-        else
+    }
+    
+    // Initialize Output buffer configuration
+    errno = asopInitOutBufConfig(&pAstCfg->xOut[zO], &pOut[zO]);
+    if (errno)
+    {
+        TRACE_TERSE1("asopDecOutProcInfo1: asopInitOutBufConfig returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_INFO1_STARTOUTPUT;
+        return status;
+    }
+    
+    return status;
+} //asopDecOutProcInfo1
+
+//   Purpose:   Re-initiate Output
+Int asopDecOutProcInfo2(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ,  
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+)
+{
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoOut  *pOut;       // ASIO IO configuration
+    Int zO, zS;
+    Int z;                      // decode/encode counter
+    Int errno;                  // error number
+    Int status;                 // status code
+    
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
+
+    // FL, New IO: Something needed in new IO
+    // FL, New IO: API for multiple Outputs
+    // FL, New IO: SIO calls need to be checked
+    errno = asopSetCheckRateX(pP, pQ, pAsotCfg, 0);
+    if (errno)
+    {
+        TRACE_TERSE1("asopDecOutProcInfo2: info returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_INFO2_SETRATEX;
+        return status;
+    }
+    
+    // Find first Output associated with Master Stream
+    zO = OUTPUT1;
+    for (z=ENCODE1; z < ENCODEN; z++)
+    {
+        zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
+        if (zS == pAstCfg->masterStr)
         {
-            TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
+            // This Encoder is associated with Master Stream.
+            // Note other Encoder can also be associated with Master Stream.
+            zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
         }
     }
-/*
-    if (errno = pP->fxns->startOutput(pP, pQ, pC)) // PAF_ASOT_startOutput, SIO_issue() call inside
+    
+    // Start output transfer
+    // FL, New IO: API for single Output
+    asopPhyTransferStart(&pOut[zO]);
+    
+    return status;
+}
+
+// Initialize Decoder output processing
+Int asopDecOutProcInit(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+)
+{
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output circular buffer control
+    Int z;                              // decode counter
+    Int errno;                          // error number
+    Int status;                         // status code
+
+    status = ASOP_DOP_SOK;
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
+    for (z=DECODE1; z < DECODEN; z++)
     {
-        if (errno == 0x105)
+        // Initialize decoder output circular buffer for stream reads
+        errno = cbInitStreamRead(pCbCtl, z);
+        if (errno)
         {
-            TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
+            TRACE_TERSE1("asopDecOutProcInit:cbInitStreamRead() error=%d", errno);
+            status = ASOP_DOP_ERR_INIT_CBINITREAD;
+            return status;
         }
-        else
+        
+        // Start decoder output circular buffer reads
+        errno = cbReadStart(pCbCtl, z);
+        if (errno)
         {
-            TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
+            TRACE_TERSE1("asopDecOutProcInit:cbReadStart() error=%d", errno);
+            status = ASOP_DOP_ERR_INIT_CBREADSTART;
+            return status;
         }
-        return errno;
+        
+        gCbReadAfErr=0;         // reset read circular buffer error count
+        gDecOpCbRdAfUnd=0;      // reset decoder output circular buffer underflow count
+        gMaxDecOpCbRdAfUnd=0;   // reset max decoder output circular buffer underflow count
+        gMasterCbResetCnt=0;    // reset master circular buffer reset count
+
+        // debug, log circular buffer control variables
+        cbLog(pCbCtl, z, 1, "asopDecOutProcInit:cbReadStart");
     }
-*/
-    return ASOP_DECODE_NO_ERR;
-} /* asopDecodeInfo1 */
-
-// -----------------------------------------------------------------------------
-// ASOT Decoding Function Helper - SIO Driver Start
-//
-//   Name:      PAF_ASOT_startOutput
-//   Purpose:   Decoding Function for initiating output.
-//   From:      AST Parameter Function -> decodeInfo1
-//   Uses:      See code.
-//   States:    x
-//   Return:    Error number in standard or SIO form (0 on success).
-//   Trace:     Message Log "trace" in Debug Project Configuration reports:
-//              * State information as per parent.
-//              * SIO control errors.
-//
-#define DEC_OUTNUMBUF_MAP(X) \
-      pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
-
-Int
-asopStartOutput(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pC
+        
+    return status;
+} /* asopDecOutProcInit */
+
+// Process Decoder output audio data using ASP chain
+Int asopDecOutProcStream(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
 )
 {
     PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int z;                      /* output counter */
-    Int nbufs;
-    Int zE, zS, zX;
-    Int zMD;
-    PAF_SIO_IALG_Obj    *pObj;
-    PAF_SIO_IALG_Config *pAlgConfig;
-
-
-    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
-    as = pAstCfg->as;
-    zMD = pAstCfg->masterDec;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output circular buffer control
+    Int z;                              // decode/stream counter
+    PAF_AudioFrame *pAfRd;
+    //PAF_AST_DecOpCircBufStats cbStats;  // circular buffer statistics
+    Int errno;                          // error number
+    Int status;                         // status code
 
-    for (z=OUTPUT1; z < OUTPUTN; z++)
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration    
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    
+    for (z=DECODE1; z < DECODEN; z++) 
     {
-        if (outIOtemp[z].hIoPhy)
+        Int zS = pP->streamsFromDecodes[z];
+        
+        //
+        // Read decoder output circular buffer
+        //
+        pAfRd = pAstCfg->xStr[zS].pAudioFrame;
+        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);       // debug
+        errno = cbReadAf(pCbCtl, z, pAfRd);
+        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
+        if ((errno < 0) && 
+            (errno != ASP_DECOP_CB_AF_READ_UNDERFLOW) && 
+            (errno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
         {
-            // determine associated encoder and stream
-            zE = z;
-            zS = z;
-            for (zX = ENCODE1; zX < ENCODEN; zX++)
-            {
-                if (pP->outputsFromEncodes[zX] == z)
-                {
-                    zE = zX;
-                    zS = pP->streamsFromEncodes[zE];
-                    break;
-                }
-            }
-
-            // Set sample count so that DOB knows how much data to send
-            pAstCfg->xOut[z].outBufConfig.lengthofFrame =
-                pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
+            gCbReadAfErr++;
+            TRACE_TERSE1("asopDecOutProcStream:cbReadAf() error=%d", errno);
+            //SW_BREAKPOINT; // debug
+            status = ASOP_DOP_ERR_STREAM_CBREAD;
+            return status;
+        }
 
-            if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
+        // Handle underflows
+        if ((errno == ASP_DECOP_CB_AF_READ_UNDERFLOW) ||
+            (errno == ASP_DECOP_CB_PCM_READ_UNDERFLOW))
+        {
+            // FL: Need to check behavior of cbReset() on exit/re-entry into Output processing.
+            gDecOpCbRdAfUnd++; // increment circular buffer underflow count
+            if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR) 
             {
-                pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
-                pAlgConfig = &pObj->config;
-                memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
-                    pAlgConfig->pMemRec[0].size);
-            }
+                // Underflow count above threshold.
+                // (1) set max underflow count to threshold
+                // (2) reset underflow count
+                // (3) reset circular buffer
+                
+                gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
+                gDecOpCbRdAfUnd = 0; // reset underflow count
 
-            // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
-            // decoder. How should we handle the sourceProgram for multiple decoders?
-            // Override as needed
-            nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
-            if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
-            {
-                nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
+                // Reset circular buffer
+                cbReset(pCbCtl, z);
+                gMasterCbResetCnt++; // increment master circular buffer reset count
+                Log_info0("asopDecOutProcStream:cbReset()");
+            
+                status = ASOP_DOP_ERR_STREAM_CBREADUNDTHR;
+                return status;
             }
-            //JXTODO: add similar thing to be figured out
-            //SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
-
-            //JXTODO: data transfer start to be moved to output task state machine
-            /*if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
-                &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
-            {
-                SIO_idle(pAstCfg->xOut[z].hTxSio);
-                TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
-                return errno;
-            } */
-
-            //JXTODO: add similar thing to be figured out
-#if 0
-            if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
-                (errno =  SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
+        }
+        else if ((errno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
+        {
+            // No underflow detected.
+            // update max underflow count,
+            // reset underflow count
+            
+            // update max underflow count
+            if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
             {
-                errno = (errno & 0xff) | ASPERR_MUTE;
-                /* convert to sensical errno */
-                TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
-                return (errno);
+                gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
             }
-            else
+            gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
+        }
+        //Log_info0("asopDecOutProcStream:cbReadAf() complete.");
+        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
+        Log_info0("asopDecOutProcStream:cbReadAf() complete.");
+        
+#if 0 // debug
+            // Shows timing of CB read
+            // ADC B8
             {
-                pAstCfg->xOut[z].outBufStatus.audio
-                    = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
+                static Uint8 toggleState = 0;
+                if (toggleState == 0)
+                    GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+                else
+                    GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+                toggleState = ~(toggleState);
             }
 #endif
-            TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
+
+        // debug, get circular buffer statistics
+        //cbGetStats(pCbCtl, z, &cbStats);
+        cbGetStats(pCbCtl, z, &gCbStats);
+
+        // debug
+        cbLog(pCbCtl, z, 1, "asopDecOutProcStream:cbReadAf()");
+        
+#if 0 // debug, capture audio frame
+        if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
+        {
+            Log_info0("asopDecOutProcStream:capAfWrite() error");
         }
+#endif
+    }
+            
+    TRACE_VERBOSE0("asopDecOutProcStream: calling streamChainFunction()");
+    errno = streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, frame);
+    if (errno)
+    {
+        TRACE_TERSE1("asopDecOutProcStream: streamChainFunction() returns errno 0x%x ", errno);
+        status = ASOP_DOP_ERR_STREAM_ASPCHAINAPPLY;
+        return status;
     }
 
-    return ASOP_DECODE_NO_ERR;
-} /* asopStartOutput */
+#if 0 // debug, capture audio frame
+    if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
+    {
+        Log_info0("asopDecOutProcStream:capAfWrite() error");
+    }
+#endif
+    
+    return status;
+} //asopDecodeStream
 
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function - Encode Processing
@@ -394,33 +484,35 @@ asopStartOutput(
 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
 //              * State information as per parent.
 //
-Int
-asopDecodeEncode(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pC,
-    Int frame,
-    Int block
+Int asopDecOutProcEncode(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
 )
 {
-    PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int z;                      /* encode/output counter */
-    Int errno;                  /* error number */
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoOut  *pOut;       // ASIO IO configuration
+    Int as;                     // Audio Stream Number (1, 2, etc.)
     Int zX, zE, zS;
-    ioPhyCtl_t ioPhyCtl;
+    Int z;                      // encode/output counter
+    Int errno;                  // error number
+    Int status;                 // status code
+    //ioPhyCtl_t ioPhyCtl;
 
-    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
     as = pAstCfg->as;
 
     // Await output buffers (but not first time)
-    for (z=OUTPUT1; z < OUTPUTN; z++)
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
     {
         // determine encoder associated with this output
         zE = z;
-        for (zX = ENCODE1; zX < ENCODEN; zX++)
+        for (zX = ENCODE1; zX < ENCODEN; zX++) 
         {
-            if (pP->outputsFromEncodes[zX] == z)
+            if (pP->outputsFromEncodes[zX] == z) 
             {
                 zE = zX;
                 break;
@@ -428,19 +520,24 @@ asopDecodeEncode(
         }
         zS = pP->streamsFromEncodes[zE];
 
-        if (outIOtemp[z].hIoPhy)   // TODO: put hIoPhy into structure or replace with API call to check if I/O is ready
+        if (pOut[z].hIoPhy)
         {
             // update length (e.g. ARC may have changed)
             pAstCfg->xOut[z].outBufConfig.lengthofFrame =
                 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
-            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
+                
+            TRACE_GEN2("asopDecodeEncode: AS%d: processing frame %d -- idle", as+zS, frame);
 
+#if 0 // FL, New IO: add similar thing to be figured out
+            // Update framework Phy transfer size
+            pOut[z].phyXferSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame * OUTPUT_STRIDE * WORD_SIZE_PCM;
+            // Update IO Phy transfer size            
             ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-            ioPhyCtl.params.xferFrameSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame
-                                               * ASOP_OUTBUF_STRIDE * ASOP_NUM_BYTES_PCM_SAMPLE;
-            ioPhyControl(outIOtemp[z].hIoPhy, &ioPhyCtl);
+            ioPhyCtl.params.xferFrameSize = pOut[z].phyXferSize;
+            ioPhyControl(pOut[z].hIoPhy, &ioPhyCtl);
+            // Update IO Buff delay to match Phy transfer size
+            ioBuffAdjustDelay(pOut[z].hIoBuff, pOut[z].phyXferSize * (NUM_PRIME_XFERS+1));
 
-#if 0
             errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
             if (errno < 0)
             {
@@ -449,10 +546,10 @@ asopDecodeEncode(
                 return -errno; // SIO negates error codes
             }
 #endif
-            // TODO: use pC->xOut[z].pOutBuf in following ->encode call
 
-#if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
-            // (***) debug // B8
+#if 0 // debug 
+            // Shows timing of Output Tx SIO reclaim
+            // ADC B8
             {
                 static Uint8 toggleState = 0;
                 if (toggleState == 0)
@@ -461,105 +558,80 @@ asopDecodeEncode(
                     GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
                 toggleState = ~(toggleState);
             }
-#endif
-
-            //
-            // Simulate Tx SIO_reclaim() pend
-            //
-            //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
-            gTaskAsopCnt++;
-            //curTime = Clock_getTicks();
-            //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
-            //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
+#endif            
         }
-        else
+        else 
         {
-            TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
+            TRACE_VERBOSE2("AS%d: asopDecodeEncode: processing frame %d -- idle <ignored>", as+zS, frame);
         }
     }
 
     // Encode data
-    for (z=ENCODE1; z < ENCODEN; z++)
+    for (z=ENCODE1; z < ENCODEN; z++) 
     {
-        Int zO = pP->outputsFromEncodes[z];
+#if 0 // debug, capture audio frame
+        PAF_AudioFrame *pAfRd;
+        pAfRd = pAstCfg->xEnc[z].encodeInStruct.pAudioFrame;
+        if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
+        {
+            Log_info0("asopDecOutProcEncode:capAfWrite() error");
+        }
+#endif
+        
         Int zS = pP->streamsFromEncodes[z];
         (void)zS; // clear compiler warning in case not used with tracing disabled
-        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)    // TODO: put hIoPhy into structure or replace with API call to check if I/O is ready
+        if (pAstCfg->xEnc[z].encodeStatus.mode) 
         {
             Int select = pAstCfg->xEnc[z].encodeStatus.select;
             ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
-            ENC_Handle enc = (ENC_Handle )encAlg;
+            ENC_Handle enc = (ENC_Handle)encAlg;
             if (select != pAstCfg->xEnc[z].encodeControl.encActive)
             {
                 pAstCfg->xEnc[z].encodeControl.encActive = select;
-                TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
-                return (-1);
+                TRACE_TERSE0("asopDecodeEncode: AS%d: changing selected encoder, return error");
+                return ASOP_DOP_ERR_ENCODE_ENCSELECT;
             }
-            TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
+            TRACE_GEN2("asopDecodeEncode: AS%d: processing frame %d -- encode", as+zS, frame);
 
             // (MID 1933) temp. workaround for PCE2
-            //pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
-            pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = 2;   //JXTODO: make this correct
-
-          /*
-          #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
-            {
-                PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
-                int *wp;
-                wp = (int*)pAudioFrame->data.sample[0];
-                TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
-                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
-                wp = (int*)pAudioFrame->data.sample[1];
-                TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
-                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
-                wp = (int*)pAudioFrame->data.sample[2];
-                TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
-                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
-            }
-          #endif
-          */
+            pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
+            //pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = 2;   //JXTODO: make this correct
 
             if (enc->fxns->encode)
             {
                 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
                         pP->z_pEncodeStatus[z]->encBypass;
-                if (errno = enc->fxns->encode(enc, NULL,
-                    &pAstCfg->xEnc[z].encodeInStruct, &pAstCfg->xEnc[z].encodeOutStruct))
+                errno = enc->fxns->encode(enc, NULL, 
+                    &pAstCfg->xEnc[z].encodeInStruct, 
+                    &pAstCfg->xEnc[z].encodeOutStruct);
+                if (errno)
                 {
                     if (errno != PCEERR_OUTPUT_POINTERNULL)    // errno = PCEERR_OUTPUT_RESULTRANGE
                     {
-                        TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
-                        return errno;
+                        TRACE_TERSE1("asopDecodeEncode: encode returns error %d", errno);
+                        status = ASOP_DOP_ERR_ENCODE_ENC;
+                        return status;
                     }
                 }
-            /*  #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
-                else
-                {
-                    int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
-                    TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
-                    TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
-                }
-              #endif
-              */
             }
         }
-        else
+        else 
         {
-            TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
-                as+pP->streamsFromEncodes[z], block);
+            TRACE_VERBOSE2("asopDecodeEncode: AS%d: processing frame %d -- encode <ignored>",
+                as+pP->streamsFromEncodes[z], frame);
         }
     }
 
     // add debug code to dump output samples to memory
 
     // Transmit data
-    for (z=OUTPUT1; z < OUTPUTN; z++)
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
     {
-        // determine encoder associated with this output
+        // determine stream associated with this output
         zE = z;
-        for (zX = ENCODE1; zX < ENCODEN; zX++)
+        for (zX = ENCODE1; zX < ENCODEN; zX++) 
         {
-            if (pP->outputsFromEncodes[zX] == z)
+            if (pP->outputsFromEncodes[zX] == z) 
             {
                 zE = zX;
                 break;
@@ -567,18 +639,20 @@ asopDecodeEncode(
         }
         zS = pP->streamsFromEncodes[zE];
 
-#if 0
-        if (pAstCfg->xOut[z].hTxSio)
+#if 0  // FL, New IO: Something needed in new IO
+        if (pAstCfg->xOut[z].hTxSio) 
         {
-            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
-            errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
+            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing frame %d -- output", as+zS, frame);
+            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);       // debug
+            errno = SIO_issue(pAstCfg->xOut[z].hTxSio, 
                 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
+            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
             if (errno)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
                 if (errno == 0x105)     // 0x105 == RINGIO_EBUFFULL
                 {
-//                    statStruct_LogFullRing(STATSTRUCT_AS1_F2);
+                    //statStruct_LogFullRing(STATSTRUCT_AS1_F2);
                     TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
                 }
                 if (errno > 0)
@@ -601,16 +675,49 @@ asopDecodeEncode(
                 return -errno; // SIO negates error codes
             }
         }
-        else
+        else 
         {
-            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
+            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing frame %d -- output <ignored>", as+zS, frame);
         }
 #endif
     }
 
-    return ASOP_DECODE_NO_ERR;
+    return status;
 } /* asopDecodeEncode */
 
+//   Purpose: Check if output processing of current stream is complete
+Int asopDecOutProcFinalTest(
+    const struct PAF_ASOT_Params *pP, 
+    const struct PAF_ASOT_Patchs *pQ, 
+    struct PAF_ASOT_Config *pAsotCfg, 
+    Int frame
+)
+{
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // decoder output circular buffer control
+    Int8 drainedFlag;                   // CB drained indicator flag
+    Int zMD;                            // master Dec index
+    Int errno;                          // error number
+    Int status;                         // status code
+    
+    status = ASOP_DOP_SOK;
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
+
+    // Check circular buffer drain state
+    errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
+    if (errno)
+    {
+        status = ASOP_DOP_ERR_FINALTEST_CBCHKDRAIN;
+        return status;
+    }
+    else if (drainedFlag == 1) // errno == 0
+    {
+        status = ASOP_DOP_ERR_FINALTEST_CBDRAINED;
+        return status;
+    }
+    
+    return status;
+}    
 
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function - Stream-Final Processing
@@ -624,192 +731,280 @@ asopDecodeEncode(
 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
 //              * State information as per parent.
 //
-Int
-asopDecodeComplete(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pC,
-    ALG_Handle decAlg[],
-    Int frame,
-    Int block
+Int asopDecOutProcComplete(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame
 )
 {
-    PAF_AST_Config *pAstCfg;
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
-    Int as;                             /* Audio Stream Number (1, 2, etc.) */
-    Int z;                              /* decode/encode counter */
-    Int errno;                          /* error number */
-
-
-    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoOut  *pOut;               // ASIO IO configuration
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    // Decoder output circular buffer control
+    Int as;                             // Audio Stream Number (1, 2, etc.)
+    Int z;                              // decode/encode counter
+    Int errno;                          // error number
+    Int status;                         // status code
+    
+    status = ASOP_DOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
 
-    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
-
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    
     for (z=DECODE1; z < DECODEN; z++)
     {
         // Stop decoder output circular buffer reads
         errno = cbReadStop(pCbCtl, z);
         if (errno)
         {
-            TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
-            SW_BREAKPOINT; // FL: debug
-            return errno;
+            TRACE_TERSE1("asopDecOutProcComplete:cbReadStop() error=%d", errno);
+            //SW_BREAKPOINT; // debug
+            status = ASOP_DOP_ERR_COMPLETE_CBREADSTOP;
+            return status;
         }
-        // FL: debug
-        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
+        // debug
+        cbLog(pCbCtl, z, 1, "asopDecOutProcComplete:cbReadStop");
     }
+    
+    streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
 
-    pP->fxns->streamChainFunction(pP, pQ, pC, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
-
-    for (z=ENCODE1; z < ENCODEN; z++)
+    for (z=ENCODE1; z < ENCODEN; z++) 
     {
         Int zO = pP->outputsFromEncodes[z];
-        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)
+        if (pOut[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode) 
         {
             Int select = pAstCfg->xEnc[z].encodeStatus.select;
             ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
 #ifdef PAF_ASP_FINAL
             ENC_Handle enc = (ENC_Handle)encAlg;
 #endif /* PAF_ASP_FINAL */
-            TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
+            TRACE_VERBOSE1("asopDecOutProcComplete: AS%d: finalizing encode", as+z);
 #ifdef PAF_ASP_FINAL
             if (enc->fxns->final)
+            {
                 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
-                                 &pAstCfg->xEnc[z].encodeStatus);
+                    &pAstCfg->xEnc[z].encodeStatus);
+            }
 #endif /* PAF_ASP_FINAL */
             if (encAlg->fxns->algDeactivate)
             {
                 encAlg->fxns->algDeactivate(encAlg);
             }
         }
-        else
+        else 
         {
-            TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
+            TRACE_VERBOSE1("asopDecOutProcComplete: AS%d: finalizing encode <ignored>", as+z);
         }
     }
 
     // wait for remaining data to be output
-    //pP->fxns->stopOutput(pP, pQ, pC);    //JXTODO: implement similar function using new I/O components
+    errno = asopStopOutput(pP, pQ, pAsotCfg);
+    if (errno)
+    {
+        status = ASOP_DOP_ERR_COMPLETE_STOPOUTPUT;
+        return status;
+    }
 
-    return 0;
-} //asopDecodeComplete
+    return status;
+} //asopDecOutProcComplete
 
-Int
-asotDecodeStream(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ,
-    PAF_ASOT_Config *pAsotCfg,
-    Int frame,
-    Int block
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function - Encode Command Processing
+//
+//   Name:      PAF_ASOT_encodeCommand
+//   Purpose:   Decoding Function for processing Encode Commands.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    0.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * Command execution.
+//              * SIO control errors.
+//              * Error number macros.
+//
+Int asopDecOutProcEncodeCommand(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
 )
 {
     PAF_AST_Config *pAstCfg;
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
-    Int z;                              /* decode/stream counter */
-    PAF_AudioFrame *pAfRd;
-    Int cbErrno;
-    Int errno;
-
+    Int as;                     // Audio Stream Number (1, 2, etc.)
+    Int zO, zS;
+    Int z;                      // encode counter
+    Int errno = 0;              // error number
+    Int status;                 // status code
 
+    status = ASOP_DOP_SOK;
     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
 
-    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
-
-    for (z=DECODE1; z < DECODEN; z++)
+    for (z=ENCODE1; z < ENCODEN; z++) 
     {
-        Int zS = pP->streamsFromDecodes[z];
-
-        //
-        // Read decoder output circular buffer
-        //
-        pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
-        cbErrno = cbReadAf(pCbCtl, z, pAfRd);
-        if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
+        zO = pP->outputsFromEncodes[z];
+        zS = pP->streamsFromEncodes[z];
+        if (!(pAstCfg->xEnc[z].encodeStatus.command2 & 0x80)) 
         {
-            gCbReadAfErr++;
-            TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
-            //SW_BREAKPOINT; // FL: debug
-            return cbErrno;
+            switch (pAstCfg->xEnc[z].encodeStatus.command2) 
+            {
+                case 0: // command none - process
+                    pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
+                    break;
+                case 1: // mute command
+                    TRACE_VERBOSE2("asopDecOutProcEncodeCommand: AS%d: encode command mute (0x%02x)", as+zS, 1);
+#if 0 // FL, New IO: Something needed in new IO
+                    if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
+                        && pAstCfg->xOut[zO].hTxSio
+                        && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0))) 
+                    {
+                        errno = (errno & 0xff) | ASPERR_MUTE;
+                        /* convert to sensical errno */
+                        TRACE_TERSE1("asopDecOutProcEncodeCommand: AS%d: SIO control failed (mute)", as+zS);
+                        TRACE_TERSE2("asopDecOutProcEncodeCommand: AS%d: errno = 0x%04x <ignored>", as+zS, errno);
+                    }
+                    else 
+                    {
+                        pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
+                    }
+#endif
+                    pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
+                    break;
+                case 2: // unmute command
+                    TRACE_VERBOSE2("asopDecOutProcEncodeCommand: AS%d: encode command unmute (0x%02x)", as+zS, 2);
+#if 0 // FL, New IO: Something needed in new IO
+                    if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
+                        && pAstCfg->xOut[zO].hTxSio
+                        && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))) 
+                    {
+                        errno = (errno & 0xff) | ASPERR_MUTE;
+                        /* convert to sensical errno */
+                        TRACE_TERSE1("asopDecOutProcEncodeCommand: AS%d: SIO control failed (unmute)", as+zS);
+                        TRACE_TERSE2("asopDecOutProcEncodeCommand: AS%d: errno = 0x%04x <ignored>", as+zS, errno);
+                    }
+                    else 
+                    {
+                        pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
+                    }
+#endif
+                    pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
+                    break;
+                default: // command unknown - ignore
+                    break;
+            }
         }
+    }
 
-        // Handle underflows
-        if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
-        {
-            // FL: some number of underflows alway occur on start of stream when ASOT only depends on configured Output.
-            //     DDP: ~2 underflows
-            //     MAT-THD: ~16 underflows
-            // Need to check behavior of cbReset().
-            // Need to check behavior on exit/re-entry into Output processing.
+    //ERRNO_RPRT (TaskAsop, errno);
 
-            gDecOpCbRdAfUnd++; // increment circular buffer underflow count
-            if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR)
-            {
-                // Underflow count above threshold.
-                // (1) set max underflow count to threshold
-                // (2) reset underflow count
-                // (3) reset circular buffer
+    return status;
+} //asopDecOutProcEncodeCommand
 
-                gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
-                gDecOpCbRdAfUnd = 0; // reset underflow count
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function Helper - Chain Processing
+//
+//   Name:      PAF_ASOT_streamChainFunction
+//   Purpose:   Common Function for processing algorithm chains.
+//   From:      AST Parameter Function -> decodeInfo1
+//              AST Parameter Function -> decodeStream
+//              AST Parameter Function -> decodeComplete
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+static Int streamChainFunction(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int iChainFrameFxns, 
+    Int abortOnError, 
+    Int logArg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     // Audio Stream Number (1, 2, etc.)
+    Int z;                      // stream counter
+    Int dFlag, eFlag, gear;
+    Int zX;
+    Int zS;
+    Int errno;                  // error number
 
-                // Reset circular buffer
-                cbReset(pCbCtl, z);
-                Log_info0("PAF_ASOT_decodeStream:cbReset");
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    (void)as; // clear compiler warning in case not used with tracing disabled
 
-                return cbErrno;
+    for (zS = STREAM1; zS < STREAMN; zS++)
+    {
+        z = pP->streamOrder[zS];  // Select stream order from streamOrder parameter - MID 788
+
+        // apply stream
+        //      unless the stream is associated with a decoder and it is not running
+        // or
+        //      unless the stream is associated with an encoder and it is not running
+        // Also gear control only works for streams with an associated decoder
+        // if no such association exists then gear 0 (All) is used
+        dFlag = 1;
+        gear = 0;
+        for (zX = DECODE1; zX < DECODEN; zX++) 
+        {
+            if (pP->streamsFromDecodes[zX] == z) 
+            {
+                dFlag = pAstCfg->xDec[zX].decodeStatus.mode;
+                gear = pAstCfg->xDec[zX].decodeStatus.aspGearStatus;
+                break;
             }
         }
-        else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
+        eFlag = 1;
+        for (zX = ENCODE1; zX < ENCODEN; zX++) 
         {
-            // No underflow detected.
-            // update max underflow count,
-            // reset underflow count
-
-            // update max underflow count
-            if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
+            if (pP->streamsFromEncodes[zX] == z) 
             {
-                gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
+                eFlag = pAstCfg->xEnc[zX].encodeStatus.mode;
+                break;
             }
-            gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
         }
-        //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
-        GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
-        Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
 
-#if 0 // (***) FL: shows timing of CB read
-            // (***) debug // B8
+        if (dFlag && eFlag) 
+        {
+            PAF_ASP_Chain *chain = pAstCfg->xStr[z].aspChain[gear];
+            PAF_AudioFrame *frame = pAstCfg->xStr[z].pAudioFrame;
+            Int (*func) (PAF_ASP_Chain *, PAF_AudioFrame *) =
+                chain->fxns->chainFrameFunction[iChainFrameFxns];
+
+            TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (reset)"
+                       : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (apply)"
+                       : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (final)"
+                       : "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (?????)",
+                       as+z, logArg);
+            errno = (*func) (chain, frame);
+            TRACE_VERBOSE2("asopStreamChainFunction: AS%d: errno 0x%x.", as+z, errno);
+
+            if (errno && abortOnError)
             {
-                static Uint8 toggleState = 0;
-                if (toggleState == 0)
-                    GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
-                else
-                    GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
-                toggleState = ~(toggleState);
+                return errno;
             }
-#endif
-
-        // FL: debug
-        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
-        //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
-        //{
-        //    Log_info0("capAfWrite() error");
-        //}
-    }
-/*
-    TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
-    errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
-        PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
-    if (errno)
-    {
-        TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
-        return errno;
+        }
+        else 
+        {
+            TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (reset) <ignored>"
+                       : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (apply) <ignored>"
+                       : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
+                       ? "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (final) <ignored>"
+                       : "asopStreamChainFunction: AS%d: processing frame %d -- audio stream (?????) <ignored>",
+                       as+z, logArg);
+        }
     }
-*/
+
     return 0;
+} //asopStreamChainFunction
+
 
-} //asotDecodeStream
 /* nothing past this point */
-#endif
diff --git a/pasdk/test_dsp/framework/audioStreamOutDec.h b/pasdk/test_dsp/framework/audioStreamOutDec.h
new file mode 100644 (file)
index 0000000..cf4a2bc
--- /dev/null
@@ -0,0 +1,141 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamOutDec.h ========
+ */
+
+#ifndef _ASOP_DEC_H_
+#define _ASOP_DEC_H_
+
+#include <xdc/std.h>
+
+#include "audioStreamOutProc.h"
+
+// status codes
+#define ASOP_DOP_SOK                        (   0 ) // ok
+#define ASOP_DOP_ERR_RESET_ENCRESET         (  -1 ) // error - reset, enc reset
+#define ASOP_DOP_ERR_INFO1_ASPCHAINRESET    (  -2 ) // error - info1, ASP chain reset
+#define ASOP_DOP_ERR_INFO1_ENCINFO          (  -3 ) // error - info1, enc info
+#define ASOP_DOP_ERR_INFO1_SETRATEX         (  -4 ) // error - info1, set rate X
+#define ASOP_DOP_ERR_INFO1_STARTOUTPUT      (  -5 ) // error - info1, start output
+#define ASOP_DOP_ERR_INFO1_INITOUTBUFCFG    (  -6 ) // error - info1, init out buf config
+#define ASOP_DOP_ERR_INFO2_SETRATEX         (  -7 ) // error - info2, set rate X
+#define ASOP_DOP_ERR_INIT_CBINITREAD        (  -8 ) // error - init, CB init read
+#define ASOP_DOP_ERR_INIT_CBREADSTART       (  -9 ) // error - init, CB read start
+#define ASOP_DOP_ERR_STREAM_CBREAD          ( -10 ) // error - stream, CB read
+#define ASOP_DOP_ERR_STREAM_CBREADUNDTHR    ( -11 ) // error - stream, CB read underflow threshold reached
+#define ASOP_DOP_ERR_STREAM_ASPCHAINAPPLY   ( -12 ) // error - stream, ASP chain apply
+#define ASOP_DOP_ERR_ENCODE_ENCSELECT       ( -13 ) // error - encode, encoder (re-)select
+#define ASOP_DOP_ERR_ENCODE_ENC             ( -14 ) // error - encode, encoder 
+#define ASOP_DOP_ERR_ENCODE_WRTOPBUFS       ( -15 ) // error - encode, write output buffers 
+#define ASOP_DOP_ERR_FINALTEST_CBCHKDRAIN   ( -16 ) // error - final test, CB check drained
+#define ASOP_DOP_ERR_FINALTEST_CBDRAINED    ( -17 ) // error - final test, CB drained
+#define ASOP_DOP_ERR_COMPLETE_CBREADSTOP    ( -18 ) // error - complete, CB read stop
+#define ASOP_DOP_ERR_COMPLETE_STOPOUTPUT    ( -19 ) // error - complete, stop output
+
+
+//   Purpose:   ASOT Function for Output reset
+Int asopDecOutProcReset(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    Int frame
+);
+
+//   Purpose:   Reset ASP chain, execute ENC info, and initiate Output
+Int asopDecOutProcInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+);
+
+//   Purpose:   Re-initiate Output
+Int asopDecOutProcInfo2(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+);
+
+// Initialize Decoder output processing
+Int asopDecOutProcInit(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+);
+
+// Process Decoder output audio data using ASP chain
+Int asopDecOutProcStream(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+);
+
+// Process ASP chain output audio data using Encoder
+Int asopDecOutProcEncode(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame 
+);
+
+// Check if processing of current stream is complete
+Int asopDecOutProcFinalTest(
+    const struct PAF_ASOT_Params *pP, 
+    const struct PAF_ASOT_Patchs *pQ, 
+    struct PAF_ASOT_Config *pAsotCfg, 
+    Int frame
+);
+
+// Terminate Decoder output processing
+Int asopDecOutProcComplete(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame
+);
+
+//   Purpose:   Decoding output processing function for processing Encode Commands.
+Int asopDecOutProcEncodeCommand(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+#endif /* _ASOP_DEC_H_ */
diff --git a/pasdk/test_dsp/framework/audioStreamOutInit.c b/pasdk/test_dsp/framework/audioStreamOutInit.c
new file mode 100644 (file)
index 0000000..5fc2bd5
--- /dev/null
@@ -0,0 +1,1231 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamOutInit.c ========
+ */
+
+#include <xdc/std.h>
+#include <xdc/runtime/Log.h>
+#include <xdc/runtime/Error.h>
+#include <xdc/runtime/Memory.h>
+
+#include <acp_mds.h>
+#include "pafsio_ialg.h"
+#include "stdasp.h"
+
+#include "common.h"
+#include "audioStreamProc_common.h"
+#include "audioStreamOutProc.h"
+
+// -----------------------------------------------------------------------------
+// Debugging Trace Control, local to this file.
+// 
+#include "logp.h"
+
+// Allow a developer to selectively enable tracing.
+#define CURRENT_TRACE_MASK      0x07
+
+#define TRACE_MASK_TERSE        0x01   // only flag errors and show init
+#define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
+#define TRACE_MASK_VERBOSE      0x04   // trace full operation
+
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
+    #undef  TRACE_TERSE0
+    #undef  TRACE_TERSE1
+    #undef  TRACE_TERSE2
+    #undef  TRACE_TERSE3
+    #undef  TRACE_TERSE4
+    #define TRACE_TERSE0(a)
+    #define TRACE_TERSE1(a,b)
+    #define TRACE_TERSE2(a,b,c)
+    #define TRACE_TERSE3(a,b,c,d)
+    #define TRACE_TERSE4(a,b,c,d,e)
+#endif
+    
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
+    #undef  TRACE_GEN0
+    #undef  TRACE_GEN1
+    #undef  TRACE_GEN2
+    #undef  TRACE_GEN3
+    #undef  TRACE_GEN4
+    #define TRACE_GEN0(a)
+    #define TRACE_GEN1(a,b)
+    #define TRACE_GEN2(a,b,c)
+    #define TRACE_GEN3(a,b,c,d)
+    #define TRACE_GEN4(a,b,c,d,e)
+#endif
+
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
+    #undef  TRACE_VERBOSE0
+    #undef  TRACE_VERBOSE1
+    #undef  TRACE_VERBOSE2
+    #undef  TRACE_VERBOSE3
+    #undef  TRACE_VERBOSE4
+    #define TRACE_VERBOSE0(a)
+    #define TRACE_VERBOSE1(a,b)
+    #define TRACE_VERBOSE2(a,b,c)
+    #define TRACE_VERBOSE3(a,b,c,d)
+    #define TRACE_VERBOSE4(a,b,c,d,e)
+#endif
+
+// -----------------------------------------------------------------------------
+//
+// Audio Stream Output Task definitions
+//
+
+//
+// Audio Stream Processing Definitions
+//
+#define aspLinkInit pQ->i_aspLinkInit
+
+//
+// Encoder Definitions
+//
+#define encLinkInit pQ->i_encLinkInit
+
+//
+// Output Definitions
+//
+#define outLinkInit pP->i_outLinkInit
+
+// -----------------------------------------------------------------------------
+
+LINNO_DECL(TaskAsop); // Line number macros
+ERRNO_DECL(TaskAsop); // Error number macros
+
+// Create ASOT event
+static Int asotCreateEvent(void);
+
+// Create IO Buff & Phy framework components
+static Int PAF_ASOT_ioCompCreate(
+    PAF_AST_IoOut *pIoOut, 
+    Int numOut, 
+    IHeap_Handle iHeapHandle
+);
+
+// Audio Stream Output Processing initialization function
+Void taskAsopFxnInit(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ
+)
+{
+    PAF_ASOT_Config *pAsotCfg;      /* ASOT 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 */
+    Int zMS;
+    Int status;
+
+    Log_info0("Enter taskAsopFxnInit()");
+
+    //
+    // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
+    //
+    if (!pP)
+    {
+        TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
+        LINNO_RPRT(TaskAsop, -1);
+        return;
+    }
+
+    if (!pQ)
+    {
+        TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
+        LINNO_RPRT(TaskAsop, -1);
+        return;
+    }
+
+    //
+    // Audio Stream Output Task Configuration (*pAsotCfg):
+    //
+    pAsotCfg = &gPAF_ASOT_config;       // initialize pointer to task configuration
+    pAsotCfg->taskHandle = Task_self(); // set task handle
+    pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
+
+    // Create ASIT event
+    status = asotCreateEvent();
+    if (status < 0)
+    {
+        TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
+        return;
+    }
+    
+    /* Obtain Audio Stream Number (1, 2, etc.) */
+    as = pAstCfg->as;
+    TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
+
+    //
+    // Initialize message log trace and line number reporting
+    //
+    for (z=STREAM1; z < STREAMN; z++)
+    {
+        TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
+    }
+    LINNO_RPRT(TaskAsop, -1);
+
+    //
+    // Determine stream index
+    //
+    zMS = pAstCfg->masterStr;
+
+    // Initialize as per parametrized phases:
+    //
+    //   In standard form these are:
+    //      - Malloc: Memory Allocation
+    //      - Config: Configuration Initialization
+    //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
+    //      - Common: Common Memory Initialization
+    //      - AlgKey: Dec/Enc chain to Array Initialization
+    //      - Device: I/O Device Initialization
+    //      - Unused: (available)
+    //      - Unused: (available)
+    //
+    LINNO_RPRT(TaskAsop, -2);
+    for (i=0; i < lengthof(pP->fxns->initPhase); i++)
+    {
+        Int linno;
+        if (pP->fxns->initPhase[i])
+        {
+            linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
+            if (linno)
+            {
+                LINNO_RPRT(TaskAsop, linno);
+                return;
+            }
+        }
+        else
+        {
+            TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
+        }
+        TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
+        LINNO_RPRT(TaskAsop, -i-3);
+    }
+
+    //
+    // End of Initialization -- display memory usage report.
+    //
+    if (pP->fxns->memStatusPrint)
+    {
+        pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
+            HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
+            HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
+    }
+} /* taskAsopFxnInit */
+
+// Create ASOT event object
+static Int asotCreateEvent(void)
+{
+    Error_Block eb;
+    
+    Error_init(&eb);
+    
+    // Default instance configuration params
+    asotEvt = Event_create(NULL, &eb);
+    if (asotEvt == NULL)
+    {
+        return -1; // error code
+    }
+    
+    return 0;
+} /* asotCreateEvent */
+
+// Create IO Buff & Phy framework components
+static Int PAF_ASOT_ioCompCreate(
+    PAF_AST_IoOut *pIoOut, 
+    Int numOut, 
+    IHeap_Handle iHeapHandle)
+{
+    int i, j, num_alloc;
+    lib_mem_rec_t   *mem_rec;
+    ioBuffHandle_t  ioBufHandle;
+    ioPhyHandle_t   ioPhyHandle;
+    Error_Block     eb;
+
+    for(i=0; i<numOut; i++)
+    {
+        // Create an I/O BUFF instance
+        // Obtain number of memory blocks required by I/O BUFF
+        num_alloc = ioBuffNumAlloc();
+
+        // Obtain requirements of each memory block
+        mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
+        if(ioBuffAlloc(mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        /* Allocate memory and create I/O BUFF instance */
+        for(j=0; j<num_alloc; j++) {
+            mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
+                                            (1<<mem_rec[j].alignment), &eb);
+        }
+
+        if(ioBuffCreate(&ioBufHandle, mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        pIoOut[i].hIoBuff = ioBufHandle;
+
+        free(mem_rec);
+
+        // Create an I/O PHY instance
+        // Obtain number of memory blocks required by I/O PHY
+        num_alloc = ioPhyNumAlloc();
+
+        // Obtain requirements of each memory block
+        mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
+        if(ioPhyAlloc(mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        /* Allocate memory and create I/O PHY instance */
+        for(j=0; j<num_alloc; j++) {
+            mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
+                                            (1<<mem_rec[j].alignment), &eb);
+        }
+
+        if(ioPhyCreate(&ioPhyHandle, mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        pIoOut[i].hIoPhy = ioPhyHandle;
+
+        free(mem_rec);
+
+    } // end of for loop
+
+    return 0;
+} // PAF_ASOT_ioCompCreate
+
+// -----------------------------------------------------------------------------
+// AST Initialization Function - Memory Allocation
+//
+//   Name:      PAF_ASOT_initPhaseMalloc
+//   Purpose:   Audio Stream Output Task Function for initialization of data pointers
+//              by allocation of memory.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Source code line number on MEM_calloc failure.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * Memory allocation errors.
+//
+
+Int PAF_ASOT_initPhaseMalloc(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int zMS, errLineNum;
+    Error_Block    eb;
+    //Int i;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
+
+    // Initialize error block
+    Error_init(&eb); 
+
+    /* Stream memory */
+    if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+    TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
+            STREAMN * sizeof (*pAstCfg->xStr),
+            HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
+
+    {
+        Int z;                          /* stream counter */
+
+        PAF_AudioFrame *fBuf;
+
+        if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
+        {
+            TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+            SW_BREAKPOINT;
+            return __LINE__;
+        }
+        TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
+                STREAMS * sizeof (*fBuf),
+                HEAP_ID_INTERNAL, (IArg)fBuf);
+
+        for (z=STREAM1; z < STREAMN; z++)
+        {
+            pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
+            TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
+        }
+    }
+
+    /* Encode memory */
+    if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+    TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
+            ENCODEN * sizeof (*pAstCfg->xEnc),
+            HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
+
+    /* Output memory */
+    if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+    TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
+            OUTPUTN * sizeof (*pAstCfg->xOut),
+            HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
+
+    /* Output I/O data structure memory */
+    if (!(pAsotCfg->pIoOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAsotCfg->pIoOut), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+    TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAsotCfg->pIoOut) %d bytes from space %d at 0x%x.",
+                 OUTPUTN * sizeof (*pAsotCfg->pIoOut),
+                 HEAP_ID_INTERNAL, (IArg)pAsotCfg->pIoOut);
+
+    /* I/O components memory for output */
+    errLineNum = PAF_ASOT_ioCompCreate(pAsotCfg->pIoOut, OUTPUTN, (IHeap_Handle)HEAP_INTERNAL);
+    if(errLineNum)
+    {
+        SW_BREAKPOINT;
+        return errLineNum;
+    }
+    TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
+    return 0;
+} //PAF_ASOT_initPhaseMalloc
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function - Memory Initialization from Configuration
+//
+//   Name:      PAF_ASOT_initPhaseConfig
+//   Purpose:   Audio Stream Output Task Function for initialization of data values
+//              from parameters.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Other as per initFrame0 and initFrame1.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+Int PAF_ASOT_initPhaseConfig(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* input/encode/stream/decode/output counter */
+    Int zMS;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
+
+    //
+    // Unspecified elements have been initialized to zero during alloc
+    //
+
+    for (z=STREAM1; z < STREAMN; z++) 
+    {
+        Int linno;
+        if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
+        {
+            return linno;           
+        }
+        if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
+        {
+            return linno;
+        }
+    }
+
+    for (z=ENCODE1; z < ENCODEN; z++) 
+    {
+        Int zO = pP->outputsFromEncodes[z];
+        Int zS = pP->streamsFromEncodes[z];
+        pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
+        pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
+        pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
+        pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
+        pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
+        pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
+        pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
+        pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
+    }
+
+    for (z=OUTPUT1; z < OUTPUTN; z++)
+    {
+        pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
+    }
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
+    return 0;
+} //PAF_ASOT_initPhaseConfig
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function - ACP Algorithm Instantiation
+//
+//   Name:      PAF_ASOT_initPhaseAcpAlg
+//   Purpose:   Audio Stream Input Task Function for initialization of ACP by
+//              instantiation of the algorithm.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Source code line number on ACP Algorithm creation failure.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * Memory allocation errors.
+//
+Int PAF_ASOT_initPhaseAcpAlg(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    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;
+    Int zS, zX;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    zMS = pAstCfg->masterStr;
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
+
+    ACP_MDS_init();
+
+    if (!(acp = (ACP_Handle )ACP_MDS_create(NULL))) 
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation  failed", as+zMS);
+        return __LINE__;
+    }
+    pAsotCfg->acp = acp;
+
+    ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
+        ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
+
+    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 *)&pAstCfg->xEnc[z].encodeStatus);
+        acp->fxns->attach(acp, ACP_SERIES_STD,
+            STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
+            (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
+        /* Ignore errors, not reported. */
+    }
+
+    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 *)&pAstCfg->xOut[z].outBufStatus);
+        /* Ignore errors, not reported. */
+    }
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
+
+    return 0;
+} //PAF_ASOT_initPhaseAcpAlg
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function - Common Memory
+//
+//   Name:      PAF_ASOT_initPhaseCommon
+//   Purpose:   Audio Stream Output Task Function for allocation of common memory.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Source code line number on PAF_ALG_alloc failure.
+//              Source code line number on PAF_ALG_mallocMemory failure.
+//              Source code line number on Decode Chain initialization failure.
+//              Source code line number on ASP Chain initialization failure.
+//              Source code line number on Encode Chain initialization failure.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * Memory allocation errors.
+//
+Int PAF_ASOT_initPhaseCommon(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    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];
+   
+    acp = pAsotCfg->acp;
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+
+    TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
+
+    //
+    // Determine memory needs and instantiate algorithms across audio streams
+    //
+    TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
+    PAF_ALG_setup(&pafAlgConfig, 
+        HEAP_ID_INTERNAL,                 HEAP_INTERNAL, 
+        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_ID_EXTERNAL_NONCACHED_SHM,   HEAP_EXTERNAL_NONCACHED_SHM,
+        HEAP_CLEAR);
+
+    if (pP->fxns->headerPrint)
+    {
+        pP->fxns->headerPrint();        
+    }
+
+    for (z = STREAM1; z < STREAMN; z++) 
+    {
+        //Int zD, zE, zX;
+        Int zE, zX;
+
+        TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
+
+        //
+        // Determine common memory needs for:
+        //  (1) ASP Algorithms
+        //  (2) Encode Algorithms
+        //  (3) Logical Output drivers
+        //
+        PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
+
+        zE = -1;
+        for (zX = ENCODE1; zX < ENCODEN; zX++) 
+        {
+            if (pP->streamsFromEncodes[zX] == z) 
+            {
+                zE = zX;
+                break;
+            }
+        }
+
+        TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
+        if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z])) 
+        {
+            TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
+            TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, 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 *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
+        }
+
+        if (zE >= 0) 
+        {
+            TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
+            if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z])) 
+            {
+                TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
+                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);
+            }
+        }
+
+        //
+        // Determine common memory needs of Logical IO drivers
+        //
+
+        if (OUTPUT1 <= z && z < OUTPUTN)
+        {
+            TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
+            if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
+            {
+                TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
+                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);
+            }
+        }
+    }
+    {
+        // Changes made to share scratch between zones
+        // Assume maximum 3 zones and scratch common memory is at offset 0;
+        int max=0;
+        for (z=STREAM1; z<STREAMN; z++)
+        {
+            if (max < common[z][0].size)
+            {
+                max = common[z][0].size;
+            }
+        }
+        common[STREAM1][0].size=max;
+        for (z=STREAM1+1; z<STREAMN; z++)
+        {
+            common[z][0].size = 0;            
+        }
+    }
+        
+    //
+    // Allocate common memory for:
+    //  (1) ASP Algorithms
+    //  (2) Encode Algorithms
+    //  (3) Logical Output drivers
+    //
+    for (z = STREAM1; z < STREAMN; z++) 
+    {
+        //Int zD, zE, zX;
+        Int zE, zX;
+
+        TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
+        if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
+        {
+            TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
+            TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
+            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);
+        // share zone0 scratch with all zones 
+        common[z][0].base = common[0][0].base;
+        if (pP->fxns->commonPrint)
+        {
+            pP->fxns->commonPrint(common[z], &pafAlgConfig);
+        }
+
+        zE = -1;
+        for (zX = ENCODE1; zX < ENCODEN; zX++) 
+        {
+            if (pP->streamsFromEncodes[zX] == z) 
+            {
+                zE = zX;
+                break;
+            }
+        }
+
+        pAstCfg->xStr[z].aspChain[0] = NULL;
+        for (g=0; g < GEARS; g++) 
+        {
+            PAF_ASP_Chain *chain;
+            TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
+            chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
+                HEAP_INTERNAL, as+z, acp, &trace,
+                aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
+            if (!chain) 
+            {
+                TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
+                return __LINE__;
+            }
+            else
+            {
+                pAstCfg->xStr[z].aspChain[g] = chain;
+            }
+        }
+
+        if (zE >= 0) 
+        {
+            PAF_ASP_Chain *chain;
+            TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
+            chain = PAF_ASP_chainInit(&pAstCfg->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__;
+            }
+        }
+
+        //
+        // Allocate non-common memories for Logical IO drivers
+        //    Since these structures are used at run-time we allocate from external memory
+        if (OUTPUT1 <= z && z < OUTPUTN) 
+        {
+            PAF_ASP_Chain *chain;
+            TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
+                           as+z, z);
+            chain = PAF_ASP_chainInit (&pAstCfg->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__;
+            }
+        }
+    }
+    TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
+
+    return 0;
+} //PAF_ASOT_initPhaseCommon
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function - Algorithm Keys
+//
+//   Name:      PAF_ASOT_initPhaseAlgKey
+//   Purpose:   Audio Stream Output Task Function for initialization of data values
+//              from parameters for Algorithm Keys.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+// .............................................................................
+Int PAF_ASOT_initPhaseAlgKey(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    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;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    (void)as; // clear compiler warning in case not used with tracing disabled
+
+    TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
+
+    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(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
+            {
+                pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
+            }
+            /* Cast in interface, for now --Kurt */
+            else
+            {
+                pAstCfg->xEnc[z].encAlg[s] = NULL;                
+            }
+        }
+    }
+
+    return 0;
+} //PAF_ASOT_initPhaseAlgKey
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function - I/O Devices
+//
+//   Name:      PAF_ASOT_initPhaseDevice
+//   Purpose:   Audio Stream Output Task Function for initialization of I/O Devices.
+//   From:      audioStream1Task or equivalent
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Source code line number on device allocation failure.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * Memory allocation errors.
+//
+Int PAF_ASOT_initPhaseDevice(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* input/output counter */
+    PAF_SIO_IALG_Obj    *pObj;
+    PAF_SIO_IALG_Config *pAlgConfig;
+    PAF_IALG_Config pafAlgConfig;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    (void)as; // clear compiler warning in case not used with tracing disabled
+
+    TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
+
+    if(pP->fxns->bufMemPrint)
+    {
+        PAF_ALG_setup (&pafAlgConfig, 
+            HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
+            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_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
+            HEAP_CLEAR);
+        TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
+    }
+    
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    {
+        PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
+
+        pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
+        pAlgConfig = &pObj->config;
+
+        pAstCfg->xOut[z].hTxSio = NULL;
+        pConfig->base.pVoid     = pAlgConfig->pMemRec[0].base;
+        pConfig->pntr.pVoid     = pAlgConfig->pMemRec[0].base;
+        pConfig->head.pVoid     = pAlgConfig->pMemRec[0].base;
+        pConfig->allocation     = pAlgConfig->pMemRec[0].size;
+        pConfig->sizeofElement  = 3;
+        pConfig->precision      = 24;
+        if(pP->fxns->bufMemPrint)
+        {
+            pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
+        }
+    }
+    TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
+
+    return 0;
+} //PAF_ASOT_initPhaseDevice
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function Helper - Initialization of Audio Frame
+//
+//   Name:      PAF_ASOT_initFrame0
+//   Purpose:   Audio Stream Output Task Function for initialization of the Audio
+//              Frame(s) by memory allocation and loading of data pointers
+//              and values.
+//   From:      AST Parameter Function -> decodeInfo
+//   Uses:      See code.
+//   States:    x
+//   Return:    0 on success.
+//              Source code line number on MEM_calloc failure.
+//              Source code line number on unsupported option.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * Memory allocation errors.
+//              * Unsupported option errors.
+//
+
+// MID 314
+extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
+extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
+
+Int PAF_ASOT_initFrame0(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int z
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int ch;
+    //Int aLen;
+    Int aLen_int=0,aLen_ext=0;
+    Int aSize = sizeof(PAF_AudioData);
+    Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
+    Int maxFrameLength = pP->maxFramelength;
+    Int zX;
+    PAF_AudioData *aBuf_int=NULL;
+    PAF_AudioData *aBuf_ext=NULL;
+    XDAS_UInt8 *metadataBuf;
+    char i;
+    Error_Block    eb;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+
+    // Initialize error block
+    Error_init(&eb); 
+
+    // Compute maximum framelength (needed for ARC support)
+    maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
+    //aLen = numchan[z] * maxFrameLength;
+    for (i=0; i < numchan[z]; i++)
+    {
+        if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
+        {
+            aLen_int += maxFrameLength;
+        }
+        else
+        {
+            aLen_ext += maxFrameLength;
+        }
+    }
+
+    //
+    // Initialize audio frame elements directly
+    //
+    pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
+    pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
+///    pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
+    pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
+    pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
+    pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
+    pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
+
+    //
+    // Allocate memory for and initialize pointers to audio data buffers
+    //
+    //   The NUMCHANMASK is used to identify the channels for which data
+    //   buffers can be allocated. Using this mask and switch statement
+    //   rather than some other construct allows efficient code generation,
+    //   providing just the code necessary (with significant savings).
+    //
+    if (pP->fxns->bufMemPrint)
+    {
+        pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
+        pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
+    }
+
+    TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
+    
+    if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
+    {
+        if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
+        {
+            TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
+            TRACE_TERSE2("  maxFrameLength: %d.  aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
+            SW_BREAKPOINT;
+            return __LINE__;
+        }
+    }
+        
+    if (aLen_ext*aSize!=0)
+    {
+        if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
+        {
+            TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
+            TRACE_TERSE2("  maxFrameLength: %d.  aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
+            SW_BREAKPOINT;
+            return __LINE__;
+        }
+    }
+    
+    TRACE_TERSE3("  maxFrameLength: %d.  aLen_int*aSize: %d.  aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
+    TRACE_TERSE3("  maxFrameLength: %d.  aLen_ext*aSize: %d.  aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
+
+    TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
+    if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
+        TRACE_TERSE1("  bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+
+    {
+        Int i;
+
+#pragma UNROLL(1)
+        for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
+        {
+            pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
+        }
+    }
+
+    // MID 314
+    if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1)) 
+    {
+        TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
+        return __LINE__;
+    }
+    else 
+    {
+        Int j = 0;
+        Int k = 0;
+        TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
+        for(i=0;i<numchan[z];i++)
+        {
+            char chan = AFChanPtrMap[numchan[z]][i];
+            if(chan != -1)
+            {
+                if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
+                {
+                    pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
+                    j++;
+                }
+                else
+                {        
+                    pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
+                    k++;
+                }    
+                TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
+                TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
+            }
+        }
+    }
+
+    for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
+    {
+        if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
+        {
+            pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
+        }
+    }
+
+    //
+    // Initialize meta data elements
+    //
+    pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
+    pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
+    pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
+    pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
+    pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
+    for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
+    {
+        pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
+        pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
+        pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
+    }
+
+    //
+    // Initialize decoder elements directly
+    //
+
+    for (zX = DECODE1; zX < DECODEN; zX++) 
+    {
+        if (pP->streamsFromDecodes[zX] == z) 
+        {
+#ifdef NOAUDIOSHARE
+            pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
+            pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
+#else /* NOAUDIOSHARE */
+            pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
+            pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
+#endif /* NOAUDIOSHARE */
+        }
+    }
+
+    return 0;
+} //PAF_ASOT_initFrame0
+
+// -----------------------------------------------------------------------------
+// ASOT Initialization Function Helper - Reinitialization of Audio Frame
+// AST Decoding Function              - Reinitialization of Audio Frame
+//
+//   Name:      PAF_ASOT_initFrame1
+//   Purpose:   Audio Stream Task Function for initialization or reinitiali-
+//              zation of the Audio Frame(s) by loading of data values of a
+//              time-varying nature.
+//   From:      audioStream1Task or equivalent
+//              AST Parameter Function -> decodeInfo
+//              AST Parameter Function -> decodeDecode
+//   Uses:      See code.
+//   States:    x
+//   Return:    0.
+//   Trace:     None.
+//
+Int PAF_ASOT_initFrame1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int z, 
+    Int apply
+)
+{
+    PAF_AST_Config *pAstCfg;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    //
+    // Reinitialize audio frame elements:
+    //
+    //   Channel Configurations during sys init                 = Unknown
+    //      "          "        during info or decode           = None
+    //
+    //   Sample Rate / Count    during sys init, info or decode = Unknown / 0
+    //
+
+    if (apply < 0) 
+    {
+        pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
+        pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
+    }
+    else 
+    {
+        pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
+        pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
+    }
+
+    if (apply < 1) 
+    {
+        pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
+        pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
+    }
+
+    return 0;
+} //PAF_ASOT_initFrame1
diff --git a/pasdk/test_dsp/framework/audioStreamOutInit.h b/pasdk/test_dsp/framework/audioStreamOutInit.h
new file mode 100644 (file)
index 0000000..0baf13c
--- /dev/null
@@ -0,0 +1,123 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamOutInit.h ========
+ */
+
+#ifndef _ASOP_INIT_H_
+#define _ASOP_INIT_H_
+#include <xdc/std.h>
+
+#include "audioStreamProc_params.h"
+#include "audioStreamProc_patchs.h"
+#include "audioStreamProc_config.h"
+
+
+//   Purpose:   Audio Stream Output Task Function for initialization of data pointers
+//              by allocation of memory.
+Int PAF_ASOT_initPhaseMalloc(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+    
+//   Purpose:   Audio Stream Output Task Function for initialization of data values
+//              from parameters.
+Int PAF_ASOT_initPhaseConfig(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Audio Stream Output Task Function for initialization of ACP by
+//              instantiation of the algorithm.
+Int PAF_ASOT_initPhaseAcpAlg(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Audio Stream Output Task Function for allocation of common memory.
+Int PAF_ASOT_initPhaseCommon(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Audio Stream Output Task Function for initialization of data values
+//              from parameters for Algorithm Keys.
+Int PAF_ASOT_initPhaseAlgKey(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Audio Stream Output Task Function for initialization of Input Devices.
+Int PAF_ASOT_initPhaseDevice(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+//   Purpose:   Audio Stream Output Task Function for initialization of the Audio
+//              Frame(s) by memory allocation and loading of data pointers
+//              and values.
+Int PAF_ASOT_initFrame0(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int z
+);
+
+//   Purpose:   Audio Stream Task Function for initialization or reinitiali-
+//              zation of the Audio Frame(s) by loading of data values of a
+//              time-varying nature.
+Int PAF_ASOT_initFrame1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int z, 
+    Int apply
+);
+
+// Audio Stream Output Processing initialization function
+Void taskAsopFxnInit(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ
+);
+
+#endif /* _ASOP_INIT_H_ */
diff --git a/pasdk/test_dsp/framework/audioStreamOutIo.c b/pasdk/test_dsp/framework/audioStreamOutIo.c
new file mode 100644 (file)
index 0000000..a936b0e
--- /dev/null
@@ -0,0 +1,716 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+/*
+ *  ======== audioStreamOutIo.c ========
+ */
+
+#include <string.h> // for memset
+#include <xdc/runtime/Log.h>
+#include <xdc/runtime/System.h>
+#include <xdc/std.h>
+
+#include "mcasp_cfg.h"
+#include "ioConfig.h"    //TODO: remove this header
+#include "ioBuff.h"
+#include "ioPhy.h"
+#include "ioData.h"
+
+#include "pafsio_ialg.h"
+#include "stdasp.h"
+#include "asperr.h"
+
+#include "audioStreamProc_common.h"
+#include "audioStreamOutProc.h"
+#include "audioStreamOutIo.h"
+
+#define DEC_OUTNUMBUF_MAP(X) \
+      pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
+
+#define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
+
+extern Ptr hMcaspTxChan;
+extern Int d10Initialized;
+
+
+// FL, New IO: this function is currently a stub
+// FL, New IO: need to McASP/EDMA configuration using SAP configuration from Output shortcut
+// Select Output devices
+Int asopSelectDevices(PAF_AST_IoOut *pOut)
+{
+    if((pOut->hIoBuff == NULL) || (pOut->hIoPhy == NULL) || (!d10Initialized)) {
+        return -1;
+    }
+
+    pOut->hMcaspChan = hMcaspTxChan;
+
+    return 0;
+}
+
+// Check if Output device SIO selection changed
+Int checkOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Int z, 
+    Bool *pOutDevSelUpdate
+)
+{
+    PAF_AST_Config *pAstCfg;
+    
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    if ((z < OUTPUT1) || (z >= OUTPUTN))
+    {
+        *pOutDevSelUpdate = FALSE;
+        return -1;
+    }
+    
+    *pOutDevSelUpdate = (Bool)(pAstCfg->xOut[z].outBufStatus.sioSelect >= 0);
+
+    return 0;
+}
+
+// Check if any Output device SIO selection changed
+Int checkAnyOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Bool *pOutDevSelUpdate
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int outDevSelUpdate;
+    Int z;
+    
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    outDevSelUpdate = FALSE;
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    {
+        if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
+        {
+            outDevSelUpdate = TRUE;
+            break;
+        }
+    }
+    
+    *pOutDevSelUpdate = outDevSelUpdate;
+
+    return 0;
+}
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function Helper - SIO Driver Change
+//
+//   Name:      PAF_ASOT_setCheckRateX
+//   Purpose:   Decoding Function for reinitiating output.
+//   From:      AST Parameter Function -> decodeInfo1
+//              AST Parameter Function -> decodeInfo2
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard form (0 on success).
+//   Trace:     None.
+//
+
+/* 0: set, 1: check, unused for now. --Kurt */
+Int asopSetCheckRateX(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int check
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_IoOut  *pOut;
+    float rateX;
+    PAF_SampleRateHz rateO /* std */, rateI /* inv */;
+    Int z;                              /* output counter */
+    Int zx;                             /* output re-counter */
+    Int getVal;
+    int inputRate, inputCount, outputRate, outputCount;
+    Int zMD;
+    Int zMI;
+    Int zMS;
+    Int zE, zX;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
+    
+    zMD = pAstCfg->masterDec;
+    zMS = pAstCfg->masterStr;
+    zMI = pP->zone.master;
+
+    inputRate = pAstCfg->xInp[zMI].inpBufStatus.sampleRateStatus;
+    inputCount = pAstCfg->xDec[zMD].decodeStatus.frameLength;
+    rateI = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz(pAstCfg->xStr[zMS].pAudioFrame, 
+        inputRate, PAF_SAMPLERATEHZ_INV);
+
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    {
+        if (pOut[z].hIoPhy && (pAstCfg->xOut[z].outBufStatus.clock & 0x01)) 
+        {
+            // determine associated encoder
+            zE = z;
+            for (zX = ENCODE1; zX < ENCODEN; zX++) 
+            {
+                if (pP->outputsFromEncodes[zX] == z) 
+                {
+                    zE = zX;
+                    break;
+                }
+            }
+
+            outputRate = pAstCfg->xEnc[zE].encodeStatus.sampleRate;
+            outputCount = pAstCfg->xEnc[zE].encodeStatus.frameLength;
+            rateO = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz(pAstCfg->xStr[zMS].pAudioFrame, 
+                outputRate, PAF_SAMPLERATEHZ_STD);
+            if ((rateI > 0) && (rateO > 0))
+            {
+                rateX = rateO /* std */ * rateI /* inv */;
+            }
+            else if (inputCount != 0)
+            {
+                rateX = (float)outputCount / inputCount;
+            }
+            else
+            {
+                return ASPERR_INFO_RATERATIO;
+            }
+
+#if 0 // FL, New IO: add similar thing to be figured out     
+            getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg)&rateX);
+            if (getVal == DOBERR_RATECHANGE) 
+            {
+                for (zx=OUTPUT1; zx < OUTPUTN; zx++)
+                {
+                    if (pAstCfg->xOut[zx].hTxSio)
+                    {
+                        SIO_idle(pAstCfg->xOut[zx].hTxSio);
+                    }
+                }
+
+                // this forces an exit from the calling state machine which will
+                // eventually call startOutput which calls setCheckRateX for all outputs
+                // and so it is ok, in the presence of a rate change on any output, to
+                // exit this loop /function early.
+                return ASPERR_INFO_RATECHANGE;
+            }
+            else if (getVal != SYS_OK)
+            {
+                return ((getVal & 0xff) | ASPERR_RATE_CHECK);
+            }
+#endif // FL, New IO
+        }
+    }
+
+    return 0;
+} //asopSetCheckRateX
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function Helper - SIO Driver Start
+//
+//   Name:      PAF_ASOT_startOutput
+//   Purpose:   Decoding Function for initiating output.
+//   From:      AST Parameter Function -> decodeInfo1
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * SIO control errors.
+//
+Int asopStartOutput(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_IoOut  *pOut;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* output counter */
+    Int nbufs;
+    Int zE, zS, zX;
+    Int zMD;
+    PAF_SIO_IALG_Obj    *pObj;
+    PAF_SIO_IALG_Config *pAlgConfig;
+    ioPhyCtl_t ioPhyCtl;
+
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
+    as = pAstCfg->as;
+    zMD = pAstCfg->masterDec;
+
+    for (z=OUTPUT1; z < OUTPUTN; z++)
+    {
+        if (pOut[z].hIoPhy)
+        {
+            // determine associated encoder and stream
+            zE = z;
+            zS = z;
+            for (zX = ENCODE1; zX < ENCODEN; zX++)
+            {
+                if (pP->outputsFromEncodes[zX] == z)
+                {
+                    zE = zX;
+                    zS = pP->streamsFromEncodes[zE];
+                    break;
+                }
+            }
+
+            // FL, New IO: add similar thing to be figured out
+// Need to Revisit: Starting Clocks here seems logical & also manages the McASP without spurious underruns .
+#if 0
+            // if device selected and valid then enable stat tracking if
+                       // required and start clocking
+                       if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
+                       {
+                               TRACE_VERBOSE0("PAF_ASOT_startOutput: start SIO clocks");
+                               errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
+                               if (errno)
+                               {
+                                       TRACE_VERBOSE2("PAF_ASOT_startOutput: errme 0x%x, errno 0x%x", errme, errno);
+                                       SIO_idle(pAstCfg->xOut[z].hTxSio);
+                                       if (!errno)
+                                       {
+                                               errno = ASPERR_DEVOUT + errme;
+                                       }
+                               }
+                       }
+#endif            
+
+            // Set sample count so that DOB knows how much data to send
+            pAstCfg->xOut[z].outBufConfig.lengthofFrame =
+                pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
+
+#if 1 // FL, New IO: add similar thing to be figured out
+            // Update framework Phy transfer size
+            pOut[z].phyXferSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame * OUTPUT_STRIDE * WORD_SIZE_PCM;
+            // Update IO Phy transfer size            
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = pOut[z].phyXferSize;
+            ioPhyControl(pOut[z].hIoPhy, &ioPhyCtl);
+            // Update IO Buff delay to match Phy transfer size
+            ioBuffAdjustDelay(pOut[z].hIoBuff, pOut[z].phyXferSize * (NUM_PRIME_XFERS+1));
+#endif            
+
+            if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
+            {
+                pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
+                pAlgConfig = &pObj->config;
+                memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
+                    pAlgConfig->pMemRec[0].size);
+            }
+
+            // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
+            // decoder. How should we handle the sourceProgram for multiple decoders?
+            // Override as needed
+            nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
+            if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
+            {
+                nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
+            }
+            //JXTODO: add similar thing to be figured out
+            //SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
+
+            //JXTODO: data transfer start to be moved to output task state machine
+            /*if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
+                &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
+            {
+                SIO_idle(pAstCfg->xOut[z].hTxSio);
+                TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
+                return errno;
+            } */
+
+            //JXTODO: add similar thing to be figured out
+#if 0
+            if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
+                (errno =  SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
+            {
+                errno = (errno & 0xff) | ASPERR_MUTE;
+                /* convert to sensical errno */
+                TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
+                return errno;
+            }
+            else
+            {
+                pAstCfg->xOut[z].outBufStatus.audio
+                    = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
+            }
+#endif
+            TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
+        }
+    }
+
+    return 0;
+} /* asopStartOutput */
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function Helper - SIO Driver Stop
+//
+//   Name:      PAF_ASOT_stopOutput
+//   Purpose:   Decoding Function for terminating output.
+//   From:      AST Parameter Function -> decodeProcessing
+//              AST Parameter Function -> decodeComplete
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * SIO control errors.
+//
+Int asopStopOutput(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_IoOut  *pOut;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* output counter */
+    Int errno = 0, getVal;
+    Int zS, zX;
+    PAF_SIO_IALG_Obj    *pObj;
+    PAF_SIO_IALG_Config *pAlgConfig;
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pOut = pAsotCfg->pIoOut; // get pointer to ASOT IO configuration
+    as = pAstCfg->as;
+    (void)as;  // clear compiler warning in case not used with tracing disabled
+
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    {
+        if (pOut[z].hIoPhy) 
+        {
+            // determine associated encoder and stream
+            zS = z;
+            (void)zS;
+            for (zX = ENCODE1; zX < ENCODEN; zX++) 
+            {
+                if (pP->outputsFromEncodes[zX] == z) 
+                {
+                    zS = pP->streamsFromEncodes[zX];
+                    break;
+                }
+            }
+
+#if 0 // FL, New IO: add similar thing to be figured out            
+            // Mute output before audio data termination in the usual case,
+            // where such termination is due to decode error or user command.
+            // Identification of this as the usual case is provided by the
+            // "decode processing" state machine.
+            if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
+                ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND) &&
+                (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0))) 
+            {
+                if (!errno) 
+                {
+                    errno = (getVal & 0xff) | ASPERR_MUTE;
+                    /* convert to sensical errno */
+                }
+                TRACE_VERBOSE1("asopStopOutput:  AS%d: SIO control failed (mute)", as+zS);
+            }
+
+            TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- begin PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
+            
+            // Terminate audio data output, truncating (ignore) or flushing
+            // (play out) final samples as per (1) control register set by
+            // the user and (2) the type of audio data termination:
+
+#if 0
+            // This form is not used because driver support for truncating
+            // data is not supported for internal clocks, although it is
+            // for external clocks.
+            getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
+                pC->xOut[z].outBufStatus.flush
+                & (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
+                ? 1 : 0);
+            /* UNTESTED */
+#else
+            // This form should be used when driver support for truncating
+            // data is supported for both internal and external clocks.
+            getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
+                pAstCfg->xOut[z].outBufStatus.flush ? 1 :
+                (pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
+                ? 1 : 0);
+            /* TESTED */
+#endif
+
+            TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- after PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
+
+            if (!errno)
+            {
+                errno = getVal;
+            }
+
+            // Mute output after audio data termination in a special case,
+            // where such termination is due to processing of a final frame
+            // or user command. Identification of this as a special case is
+            // provided by the "decode processing" state machine.
+            if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
+                ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH) &&
+                (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
+            {
+                if (!errno) 
+                {
+                    errno = (getVal & 0xff) | ASPERR_MUTE;
+                    /* convert to sensical errno */
+                }
+                TRACE_VERBOSE1("as1-f2: asopStopOutput:  AS%d: SIO control failed (mute)", as+zS);
+            }
+
+            pAstCfg->xOut[z].outBufStatus.audio &= ~0x0f;
+#endif // FL, New IO
+
+            // zero output buffers
+            pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
+            pAlgConfig = &pObj->config;
+            memset (pAstCfg->xOut[z].outBufConfig.base.pVoid, 0, pAlgConfig->pMemRec[0].size);
+        } //pAstCfg->xOut[z].hTxSio
+    }//OUTPUT
+
+    return errno;
+} //asopStopOutput
+
+/*===========================================================================
+ * Initialize I/O components for output processing
+============================================================================*/
+Int asopIoCompsInit(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+)
+{
+    // Initialize I/O BUFF and I/O PHY components for output task
+    ioBuffParams_t ioBuffParams;
+    ioPhyParams_t  ioPhyParams;
+
+    ioBuffParams.base         = pOutBuf->outBufConfig.base.pVoid;
+    ioBuffParams.size         = pOutBuf->outBufConfig.allocation/STRIDE_WORST_CASE*STRIDE_WORST_CASE;
+    ioBuffParams.sync         = IOBUff_READ_SYNC;
+    ioBuffParams.nominalDelay = OUTPUT_FRAME_SIZE * (NUM_PRIME_XFERS+1);
+    if(ioBuffInit(pOutIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) 
+    {
+        return -1;   // to remove magic number
+    }
+
+    ioPhyParams.ioBuffHandle    = pOutIo->hIoBuff;
+    ioPhyParams.xferFrameSize   = OUTPUT_FRAME_SIZE;
+    ioPhyParams.mcaspChanHandle = hMcaspTxChan;
+    ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_READ;
+    if(ioPhyInit(pOutIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) 
+    {
+        return -1;   // to remove magic number
+    }
+
+    pOutIo->phyXferSize = ioPhyParams.xferFrameSize;
+    
+    pOutIo->ioBuffBuf2AllocCnt = 0; // initialize buffer2 alloc count (indicates Output buffer wrap)
+    pOutIo->errIoBuffOvrCnt = 0; // initialize IO buff overflow count
+    pOutIo->errIoBuffUndCnt = 0; // initialize IO buff underflow count
+
+    return 0;
+} /* asopIoCompsInit */
+
+/*======================================================================================
+ *  This function checks whether the I/O physical layer has been initialized
+ *====================================================================================*/
+Bool asopIoPhyCheckInit(Void)
+{
+    if (!d10Initialized)
+        return FALSE;
+    else 
+        return TRUE;
+}
+
+/*======================================================================================
+ *  I/O physical layer prime operation required by McASP LLD
+ *====================================================================================*/
+Void asopIoPhyPrime(
+    PAF_AST_IoOut *pOut
+)
+{
+    Int32        count;
+
+    pOut->numPrimeXfers = NUM_PRIME_XFERS;
+
+    for (count = 0; count < pOut->numPrimeXfers; count++)
+    {
+        ioPhyXferSubmit(pOut->hIoPhy);
+    }
+} /* asipIoPhyPrime */
+
+// Initialize Output buffer configuration
+Int asopInitOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+)
+{
+    PAF_OutBufConfig *pOutBufCfg;
+    ioBuffHandle_t hIoBuff;
+    ioBuffInfo_t outBuffInfo;
+    
+    pOutBufCfg = &pOutBuf->outBufConfig;
+    hIoBuff = pOutIo->hIoBuff;
+    
+    pOutBufCfg->stride = OUTPUT_STRIDE;
+    pOutBufCfg->sizeofElement = WORD_SIZE_PCM;
+    pOutBufCfg->precision = 24;
+    
+    ioBuffGetInfo(hIoBuff, &outBuffInfo);
+       pOutBufCfg->base.pLgInt = outBuffInfo.base;
+       pOutBufCfg->sizeofBuffer = outBuffInfo.size;
+    
+       pOutBuf->pOutBuf = &(pOutBuf->outBufConfig);
+    
+    return 0;
+}
+
+// Update Output buffer configuration.
+// This is needed for proper operation of PCM encoder.
+Int asopUpdateOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+)
+{
+    PAF_OutBufConfig *pOutBufCfg;
+    ioBuffHandle_t hIoBuff;
+    ioBuffInfo_t outBuffInfo;
+    void *buff1, *buff2;
+    size_t size1, size2, total_write_size;
+    Int status;
+
+    pOutBufCfg = &pOutBuf->outBufConfig;
+    hIoBuff = pOutIo->hIoBuff;
+
+    // FL, New IO: original code can change these values in every DOB issue
+    //  Need to determine if this is required or not.
+    pOutBufCfg->stride = OUTPUT_STRIDE;
+    pOutBufCfg->sizeofElement = WORD_SIZE_PCM;
+    pOutBufCfg->precision = 24;
+    
+    //JXTODO: to replace hard coded write size
+    // Get write pointers of output memory pool
+       total_write_size = pOutBufCfg->lengthofFrame * pOutBufCfg->stride * pOutBufCfg->sizeofElement;
+    status = ioBuffGetWritePtrs(hIoBuff, total_write_size,
+        &buff1, &size1, &buff2, &size2);
+    if (status == IOBUFF_ERR_OVERFLOW) 
+    {
+        pOutIo->errIoBuffOvrCnt++;
+        //System_printf ("asopUpdateOutBufConfig: output buff overflow\n"); // debug
+
+        // skip processing since output buffer overflows        
+        return -1;
+    }
+    else if (status == IOBUFF_ERR_UNDERFLOW) 
+    {
+        pOutIo->errIoBuffUndCnt++;
+        //System_printf ("asopUpdateOutBufConfig: output buff underflow\n"); // debug
+        
+        // already underflows and remain in underflow
+    }
+
+    // Update Output buffer pointer for Encoder
+       pOutBufCfg->pntr.pLgInt = buff1;
+    if ((buff2 != NULL) || (size2 != 0))
+    {
+        // buff2 should always be NULL for Output & size2 should always be 0 for Output.
+        // Track this here.
+        pOutIo->ioBuffBuf2AllocCnt++; // debug
+    }
+    
+    // save buffer pointers & sizes for later write complete
+    pOutIo->buff1 = buff1;
+    pOutIo->size1 = size1;
+    pOutIo->buff2 = buff2;
+    pOutIo->size2 = size2;
+    
+    return 0;
+}
+
+// Mark Output buffers write complete
+Int asopMarkOutBuffsWriteComplete(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+)
+{
+    ioBuffHandle_t hIoBuff;
+    void *buff1, *buff2;
+    size_t size1, size2;
+    
+    // get buffer pointers & sizes from previous IO Buff write allocation
+    buff1 = pOutIo->buff1;
+    size1 = pOutIo->size1;
+    buff2 = pOutIo->buff2; // this should always be NULL for Output
+    size2 = pOutIo->size2; // this should always be 0 for Output
+    
+    hIoBuff = pOutIo->hIoBuff;
+    
+    ioBuffWriteComplete(hIoBuff, buff1, size1);
+
+    if (buff2 != NULL) 
+    {
+        ioBuffWriteComplete(hIoBuff, buff2, size2);
+    }
+    
+    return 0;
+}
+
+/*======================================================================================
+ *  This function starts an I/O PHY transfer for output
+ *====================================================================================*/
+Void asopPhyTransferStart(
+    PAF_AST_IoOut *pOut
+)
+{
+    if(mcaspCheckOverUnderRun(pOut->hMcaspChan)) 
+    {
+        mcaspTxReset();
+        mcaspTxCreate();
+        pOut->hMcaspChan = hMcaspTxChan;
+    }
+    else 
+    {
+        if(ioPhyXferSubmit(pOut->hIoPhy) == IOPHY_ERR_BUFF_UNDERFLOW) 
+        {
+            // Output buffer underflows!
+            System_abort("\nOutput buffer underflows!\n");
+        }
+        else {
+            // Output buffer operates normally
+            ;
+        }
+    }
+}
+
+/* nothing past this point */
diff --git a/pasdk/test_dsp/framework/audioStreamOutIo.h b/pasdk/test_dsp/framework/audioStreamOutIo.h
new file mode 100644 (file)
index 0000000..7e33e96
--- /dev/null
@@ -0,0 +1,127 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamOutIo.h ========
+ */
+
+#ifndef _ASOP_IO_H_
+#define _ASOP_IO_H_
+
+#include <xdc/std.h>
+
+#include "audioStreamOutProc.h"
+
+
+// Select Output devices
+Int asopSelectDevices(
+    PAF_AST_IoOut *pOut
+);
+
+// Check if Output device SIO selection changed
+Int checkOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Int z, 
+    Bool *pOutDevSelUpdate
+);
+
+// Check if any Output device SIO selection changed
+Int checkAnyOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Bool *pOutDevSelUpdate
+);
+
+// Re-initiate Output
+Int asopSetCheckRateX(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg, 
+    Int check);
+
+// Initiate Output
+Int asopStartOutput(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg
+);
+
+// Terminate Output
+Int asopStopOutput(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
+// Initialize I/O components for output processing
+Int asopIoCompsInit(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+);
+
+// Check I/O physical layer initialized
+Bool asopIoPhyCheckInit(Void);
+
+// I/O physical layer prime operation required by McASP LLD
+Void asopIoPhyPrime(
+    PAF_AST_IoOut *pOut
+);
+
+// Initialize Output buffer configuration
+Int asopInitOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+);
+
+// Update Output buffer configuration
+Int asopUpdateOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+);
+
+// Mark Output buffers write complete
+Int asopMarkOutBuffsWriteComplete(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
+);
+
+// This function starts an I/O PHY transfer for output 
+Void asopPhyTransferStart(
+    PAF_AST_IoOut *pOut
+);
+
+
+#endif /* _ASOP_IO_H_ */
index 44040493f1fbc1d217e3cdf0a0448af0be6539c4..34e9d73e006461ea60aa396798d1b54a7f93d347 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
-Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
 All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without 
@@ -37,47 +37,30 @@ All rights reserved.
  *  ======== audioStreamOutProc.c ========
  */
 
-#include <string.h> // for memset
 #include <xdc/runtime/Log.h>
-#include <xdc/runtime/Error.h>
-#include <xdc/runtime/Memory.h>
-#include <ti/sysbios/knl/Clock.h>
-#include <ti/sysbios/knl/Task.h>
-
-#include "paferr.h"
-#include <acp_mds.h>
-#include <pcm.h>
-#include <pce.h>
-#include <pafsio_ialg.h>
-#include <stdasp.h>
-#include <doberr.h>
-#include "asperr.h"
-
-#include "common.h"
-#include "aspMsg_common.h"
-#include "aspMsg_master.h"
-#include "aspDecOpCircBuf_master.h"
+#include <ti/sysbios/BIOS.h>
+
 #include "aspOutInitSync_master.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamOutProc.h"
+#include "audioStreamOutInit.h"
+#include "audioStreamOutDec.h"
+#include "audioStreamOutIo.h"
 
-#include "pfp/pfp.h"
-#include "pfp_app.h"        /* contains all PFP ID's */
-Int32 gNumPfpAsot1=0; // debug
+//#include "pfp/pfp.h"
+//#include "pfp_app.h"        /* contains all PFP ID's */
+//Int32 gNumPfpAsot1=0; // debug
 
-// FL: debug
+// debug
 #include "evmc66x_gpio_dbg.h"
-#include "dbgCapAf.h"
 
-#include "ioConfig.h"
+//#include "ioConfig.h"
 
 // -----------------------------------------------------------------------------
 // Debugging Trace Control, local to this file.
 // 
 #include "logp.h"
 
-#define TRACE_TIME(a)
-
 // Allow a developer to selectively enable tracing.
 #define CURRENT_TRACE_MASK      0x07
 
@@ -124,3366 +107,897 @@ Int32 gNumPfpAsot1=0; // debug
     #define TRACE_VERBOSE4(a,b,c,d,e)
 #endif
 
-// .............................................................................
-
-//
-// Audio Stream Definitions
-//
-
-//
-// Audio Stream Processing Definitions
-//
-#define aspLinkInit pQ->i_aspLinkInit
-
-//
-// Encoder Definitions
-//
-#define encLinkInit pQ->i_encLinkInit
-
+// -----------------------------------------------------------------------------
 //
-// Output Definitions
+// Audio Stream Output Task definitions
 //
-#define outLinkInit pP->i_outLinkInit
 
-/* ---------------------------------------------------------------- */
-/*              Parameter macro definitions end here.               */
-/* ---------------------------------------------------------------- */
-
-//
-// Standardized Definitions
-//
+#define __TASK_NAME__  "TaskAsop"
 
-#define ENC_Handle PCE_Handle /* works for all: PCE */
+// status codes
+// ASOT FSM
+#define ASOP_SOK_INITSYNC_NOTREADY              (   1 ) // ok, init-sync not ready
+#define ASOP_SOK                                (   0 ) // ok
+#define ASOP_ERR_FORWARD_ERR                    (  -1 ) // error, forward (ASIT) error
+#define ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL       (  -2 ) // error, reset dec out proc, no output device selected
+#define ASOP_ERR_PROCDECOUT_OUTDEVSELUPD        (  -3 ) // error, proc dec out, output device select updated
+#define ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE   (  -4 ) // error, proc dec out, io phy transfer complete
+#define ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD     (  -5 ) // error, proc dec out, check output device select update
 
-#define __TASK_NAME__  "TaskAsop"
+// -----------------------------------------------------------------------------
 
+// ASOT FSM states 
+enum 
+{ 
+    ASOT_STATE_SEL_OUT_DEV, 
+    ASOT_STATE_RESET_OUT_PROC, 
+    ASOT_STATE_INITSYNC_DEC_INFO1, 
+    ASOT_STATE_INITSYNC_DEC_DECODE1, 
+    ASOT_STATE_PROC_DEC_OUT,
+    ASOT_STATE_RESEL_OUT_DEV,
+    ASOT_STATE_INITSYNC_RESYNC
+};
 
-//
-// Audio Stream Output Task definitions
-//
+// Check if Output device selected
+static Int checkOutDevSel(
+    PAF_AST_IoOut *pOut,
+    Bool *pOutDevSel);
+    
+// Check if any Output device selected
+static Int checkAnyOutDevSel(
+    const PAF_ASOT_Params *pP,
+    PAF_AST_IoOut *pOut,
+    Bool *pOutDevSel);
 
-// status codes
-// Output FSM
-#define ASOP_INITSYNC_NOTREADY      (  1 )  // ok, init-sync not ready
-#define ASOP_SOK                    (  0 )  // ok
-#define ASOP_FORWARD_ERR            ( -1 )  // forward (ASIT) error
-#define ASOP_ENCRESET_ERR           ( -2 )  // enc reset error
-#define ASOP_DECINFO1_ERR           ( -3 )  // dec info1 error
-// Decode Processing
-#define ASOP_DP_OUT_SIO_UPDATE      (  3 )  // new output selected
-#define ASOP_DP_CB_DRAINED          (  2 )  // circular buffer drained
-#define ASOP_DP_SOK                 (  0 )  // ok
-#define ASOP_DP_FORWARD_ERR         ( -1 )  // forward (ASIT) error
-#define ASOP_DP_DECINIT_ERR         ( -2 )  // decode init error
-#define ASOP_DP_DECSTREAM_ERR       ( -3 )  // decode stream error
-#define ASOP_DP_DECENC_ERR          ( -4 )  // decode encode error
-#define ASOP_DP_DECINFO2_ERR        ( -5 )  // decode encode error
-#define ASOP_DP_DECFINALTEST_ERR    ( -6 )  // decode final error
-
-
-
-/* Check if at least one output selected */
-static Int checkOutSel(
+// ASOT SM function
+//   Purpose:   Audio Stream Output Task Function for selecting the devices used
+//              for output.
+static Int PAF_ASOT_selectDevices(
     const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
-    Int *pOutSel
+    Bool *pOutDevSel
+);
+
+// Reset audio frame pointers to original values
+static Void resetAfPointers(
+    const PAF_ASOT_Params *pP, 
+    PAF_AST_Stream *xStr
 );
 
-/* Check if at least one output sio changed */
-static Int checkOutSio(
+// Reset audio frame meta data elements
+static Void resetAfMetadata(
     const PAF_ASOT_Params *pP, 
-    PAF_ASOT_Config *pAsotCfg,
-    Int *pOutSioUpdate
+    PAF_AST_Stream *xStr
 );
 
-// Initialize Output Processing state function
-//static Int PAF_ASOT_initOutProc(
-// used by new OutProc.c, will be changed back to static once refactoring is done
-Int PAF_ASOT_initOutProc(
+// Reset audio frames
+static Void resetAfs(
     const PAF_ASOT_Params *pP, 
     PAF_AST_Stream *xStr
 );
 
-// Initialize Output Processing state function
 // used by new OutProc.c, will be changed back to static once refactoring is done
-Int PAF_ASOT_initSyncDecReset(
+//   Purpose:   Init-Sync Dec Reset state function.
+//              Performs Dec Reset Init-Sync.
+static Int PAF_ASOT_initSyncDecReset(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
-    PAF_AudioFrame *pDecResetAf
+    PAF_AudioFrame *pDecResetAf,
+    Int frame
 );
 
-//   Purpose:   ASOT Function for Output reset
-static Int PAF_ASOT_outputReset(
+// ASOT SM function
+// Reset Decoder Output processing
+static Int PAF_ASOT_resetDecOutProc(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
-    PAF_ASOT_Config *pAsotCfg
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf,
+    Bool outDevSel,
+    Int frame
 );
 
+// ASOT SM function
 //   Purpose:   Init-Sync Dec Info1 state function.
-//              Performes Dec Info1 Init-Sync.
-Int PAF_ASOT_initSyncDecInfo1(
+//              Performs Dec Info1 Init-Sync.
+static Int PAF_ASOT_initSyncDecInfo1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
-    PAF_AudioFrame *pDecInfo1Af
+    PAF_AudioFrame *pDecInfo1Af, 
+    Int frame
 );
 
-//   Purpose:   ASOT function for ASP chain reset and ENC info
-static Int PAF_ASOT_outputInfo1(
+// ASOT SM function
+//   Purpose:   Init-Sync Dec Decode1 state function.
+//              Performs Dec Decode1 Init-Sync.
+static Int PAF_ASOT_initSyncDecDecode1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
-    PAF_ASOT_Config *pAsotCfg
+    PAF_ASOT_Config *pAsotCfg, 
+    Int frame
 );
 
-//   Purpose:   Init-Sync Dec Decode1 state function.
-//              Performes Dec Decode1 Init-Sync.
-Int PAF_ASOT_initSyncDecDecode1(
+// ASOT SM function
+// Process Decoder output audio data
+static Int PAF_ASOT_procDecOut(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
-    PAF_ASOT_Config *pAsotCfg
+    PAF_ASOT_Config *pAsotCfg, 
+    Bool *pFirstTime, 
+    Int frame
 );
 
+// ASOT SM function
 //   Purpose:   Init-Sync Re-Sync state function.
-//              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
-Int PAF_ASOT_initSyncResync(
+//              Performs Init-Sync using stored Dec Reset/Info1 AFs.
+static Int PAF_ASOT_initSyncResync(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
     PAF_AudioFrame *pDecResetAf,
-    PAF_AudioFrame *pDecInfo1Af  
-);
-
-#if 0
-// Init-Sync update audio frame
-static Int initSyncUpdateAf(
-    PAF_AudioFrame *dstAf, 
-    PAF_AudioFrame *srcAf
-);
-#endif
-
-// Reset audio frames
-static Void resetAfs(
-    const PAF_ASOT_Params *pP, 
-    PAF_AST_Stream *xStr
-);
-
-// Reset audio frame pointers to original values
-static Void resetAfPointers(
-    const PAF_ASOT_Params *pP, 
-    PAF_AST_Stream *xStr
+    PAF_AudioFrame *pDecInfo1Af, 
+    Int frame
 );
 
-// Reset audio frame meta data elements
-static Void resetAfMetadata(
+// ASOT SM function
+//   Purpose:   Re-select devices used for Output.
+//              Performs Init-Sync using stored Dec Reset/Info1 AFs.
+static Int PAF_ASOT_reselectDevices(
     const PAF_ASOT_Params *pP, 
-    PAF_AST_Stream *xStr
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg,
+    PAF_AudioFrame *pDecResetAf,
+    PAF_AudioFrame *pDecInfo1Af,
+    Int frame, 
+    Bool *pOutDevSel
 );
+   
 
-
-LINNO_DEFN(TaskAsop); /* Line number macros */
-ERRNO_DEFN(TaskAsop); /* Error number macros */
+// FL: debug, allow modification of Output frame length via JTAG.
+Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
 
 // ASOT configuration
 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
 PAF_ASOT_Config gPAF_ASOT_config = {
     NULL,               // taskHandle
+    0,                  // asotState
     NULL,               // acp
-    0,0,0,              // CB drained flags (size DECODE_MAXN)
+    0,0,0,              // cbDrainedFlag (size DECODE_MAXN)
     &gPAF_ASPM_config,  // pAspmCfg
     &gPAF_AST_config    // pAstCfg
 };
 
-// Underflow threshold before circular buffer reset and return error to Top-Level FSM
-#define DEC_OP_CB_RDAF_UND_THR  ( 80 ) // FL: arbitrary setting
-UInt32 gCbReadAfErr         =0; // read circular buffer error count, not including underflows
-UInt32 gDecOpCbRdAfUnd      =0; // decoder output circular buffer underflow count
-UInt32 gMaxDecOpCbRdAfUnd   =0; // max (consecutive) decoder output circular buffer underflow count
-UInt32 gMasterCbResetCnt    =0; // master circular buffer reset count
+/* ASOT event handle - to put in structure */
+Event_Handle asotEvt;
+
+extern Int d10Initialized;
 
 // For writeDECCommandRestart
 extern volatile UInt32 gCommandOutputTask_SYNC;
 extern volatile UInt32 gCommandOutputTask_ACK;
 
-// Global debug counters */
-UInt32 gAsopTxSioReclaimCnt         =0;
-UInt32 gAsopInitOutProcCnt          =0;
-UInt32 gAsopInitSyncDecResetCnt     =0;
-UInt32 gAsopInitSyncDecInfo1Cnt     =0;
-UInt32 gAsopInitSyncDecDecode1Cnt   =0;
-UInt32 gAsopInitSyncResyncCnt       =0;
-UInt32 gAsopOutProcCnt              =0;
-UInt32 gAsopInitCnt                 =0;
-UInt32 gAsopStreamCnt               =0;
-UInt32 gAsopEncodeCnt               =0;
-UInt32 gAsopFinalCnt                =0;
-UInt32 gAsopOutSioUpdateCnt         =0;
-UInt32 gAsopQuitCnt                 =0;
-
-/*
- *  ======== taskAsopFxnInit ========
- *  Audio Stream Output Processing initialization function
- */
-Void taskAsopFxnInit(
-    const PAF_ASOT_Params *pP,
-    const PAF_ASOT_Patchs *pQ
-)
-{
-    PAF_ASOT_Config *pAsotCfg;      /* ASOT 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 */
-    Int zMS;
-
-    Log_info0("Enter taskAsopFxnInit()");
-
-    //
-    // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
-    //
-    if (!pP)
-    {
-        TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
-        LINNO_RPRT(TaskAsop, -1);
-        return;
-    }
-
-    if (!pQ)
-    {
-        TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
-        LINNO_RPRT(TaskAsop, -1);
-        return;
-    }
-
-    //
-    // Audio Stream Output Task Configuration (*pAsotCfg):
-    //
-    pAsotCfg = &gPAF_ASOT_config;       // initialize pointer to task configuration
-    pAsotCfg->taskHandle = Task_self(); // set task handle
-    pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
-
-    /* Obtain Audio Stream Number (1, 2, etc.) */
-    as = pAstCfg->as;
-    TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
-
-    //
-    // Initialize message log trace and line number reporting
-    //
-    for (z=STREAM1; z < STREAMN; z++)
-    {
-        TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
-    }
-    LINNO_RPRT(TaskAsop, -1);
-
-    //
-    // Determine stream index
-    //
-    zMS = pAstCfg->masterStr;
+LINNO_DEFN(TaskAsop); // Line number macros
+ERRNO_DEFN(TaskAsop); // Error number macros
 
-    // Initialize as per parametrized phases:
-    //
-    //   In standard form these are:
-    //      - Malloc: Memory Allocation
-    //      - Config: Configuration Initialization
-    //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
-    //      - Common: Common Memory Initialization
-    //      - AlgKey: Dec/Enc chain to Array Initialization
-    //      - Device: I/O Device Initialization
-    //      - Unused: (available)
-    //      - Unused: (available)
-    //
-    LINNO_RPRT(TaskAsop, -2);
-    for (i=0; i < lengthof(pP->fxns->initPhase); i++)
-    {
-        Int linno;
-        if (pP->fxns->initPhase[i])
-        {
-            linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
-            if (linno)
-            {
-                LINNO_RPRT(TaskAsop, linno);
-                return;
-            }
-        }
-        else
-        {
-            TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
-        }
-        TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
-        LINNO_RPRT(TaskAsop, -i-3);
-    }
+#define ASOP_DEBUG
+#ifdef ASOP_DEBUG
+Int asopLoopCount;
+#endif
 
-    //
-    // End of Initialization -- display memory usage report.
-   &nb