]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamInpProc.c
PASDK-218:Add rudimentary Dec Op CB status and alpha command interface
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProc.c
index 967318046953b7f2c2a1c9676fa48eba510b60ba..7505838e959e75bbdd43f186fa1118b8c3b43451 100644 (file)
@@ -61,6 +61,7 @@ All rights reserved.
 #include "aspMsg_common.h"
 #include "aspMsg_master.h"
 #include "aspDecOpCircBuf_master.h"
+#include "aspOutInitSync_master.h"
 #include "audioStreamProc_common.h"
 #include "audioStreamProc_master.h"
 #include "audioStreamInpProc.h"
@@ -305,6 +306,25 @@ extern UInt32 gAspProfileEnable;
 
 #define __TASK_NAME__  "TaskAsip"
 
+
+//
+// Audio Stream Output Task definitions
+//
+
+#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 )        //QIN FIX ME
+
+// Compute decoder frame length based on selected source
+static Int getFrameLengthSourceSel(
+    const PAF_ASIT_Params *pP, 
+    Int8 sourceSelect
+);
+
 LINNO_DEFN(TaskAsip); /* Line number macros */
 ERRNO_DEFN(TaskAsip); /* Error number macros */
 
@@ -779,11 +799,12 @@ Void taskAsipFxn(
         
         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--;
 
-        if (errno) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
+        if (errno)
         {
             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
             continue;
@@ -793,8 +814,10 @@ Void taskAsipFxn(
         // 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]))
-        if (errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
+        // (***) FL: re-visit this, hard-coded to use FRAMELENGTH (pP->frameLength) inside function
+        if (errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL))
         {
             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
             continue;
@@ -1022,7 +1045,7 @@ Void taskAsipFxn(
         }
     } // End of main processing loop for (;;)
     
-    Log_info0("Exit taskAsipFxn()");
+    //Log_info0("Exit taskAsipFxn()");
 }
 
 // -----------------------------------------------------------------------------
@@ -1509,6 +1532,7 @@ PAF_ASIT_initPhaseDevice(
     return 0;
 } //PAF_ASIT_initPhaseDevice
 
+// (***) FL: move to ASOT
 // -----------------------------------------------------------------------------
 // ASIT Initialization Function - Decoder Output Circular Buffer
 //
@@ -1538,13 +1562,16 @@ PAF_ASIT_initPhaseDecOpCircBuf(
     Int errno;                          /* error number */
     Error_Block    eb;
     Int i;
+    ACP_Handle acp;
+    Int betaPrimeOffset;
+    Int zS;
 
     // FL: (***)revisit
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
     as = pAstCfg->as;
     zMS = pAstCfg->masterStr;
 
-    /* Decode output circular buffer memory */
+    // Decode output circular buffer memory
     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
         DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
     {
@@ -1556,7 +1583,7 @@ PAF_ASIT_initPhaseDecOpCircBuf(
     TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pAsitCfg->xDecOpCb) %d bytes from space %d at 0x%x.",
         DECODEN * sizeof (*pAstCfg->xDecOpCb),
         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
-        
+
     for (z=DECODE1; z < DECODEN; z++)
     {
         pCb = &pAstCfg->xDecOpCb[z];
@@ -1588,7 +1615,7 @@ PAF_ASIT_initPhaseDecOpCircBuf(
             SW_BREAKPOINT;
         }
         pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
-        // allocate Metadata buffers //QIN
+        // allocate Metadata buffers
         if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
         {
             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
@@ -1596,8 +1623,7 @@ PAF_ASIT_initPhaseDecOpCircBuf(
         }
         pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
 
-
-        #ifdef CB_RW_OP_CAP_PP
+        #ifdef CB_RW_OP_CAP_PP // debug
         // allocate debug buffer
         if (!(pCb->cb_samples_op = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt32), 4, &eb)))
         {
@@ -1633,9 +1659,18 @@ PAF_ASIT_initPhaseDecOpCircBuf(
             SW_BREAKPOINT;
         }
         #endif
+    }
 
-        // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length        
-        // Initialize decoder output circular buffer for PCM
+    for (z = DECODE1; z < DECODEN; z++)
+    {
+        //
+        // Initialize decoder output circular
+        //
+        
+        // Initialize status
+        pAstCfg->xDecOpCb[z].cbStatus = *pP->z_pDecOpCircBufStatus[z];
+        
+        // Default initialization
         errno = cbInit(pCb);
         if (errno)
         {
@@ -1643,11 +1678,81 @@ PAF_ASIT_initPhaseDecOpCircBuf(
             return errno;
         }
     }
-
+    
+    // Get ASIT ACP handle
+    acp = pAsitCfg->acp;
+    if (!acp)
+    {
+        TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: ACP algorithm instance creation  failed", as+zMS);
+        return __LINE__;
+    }
+    
+    // Get Beta Prime offset
+    ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
+        ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
+            
+    for (z = DECODE1; z < DECODEN; z++)
+    {
+        // ACP attach CB
+        zS = pP->streamsFromDecodes[z];
+        acp->fxns->attach(acp, ACP_SERIES_STD,
+            STD_BETA_DECOPCB + betaPrimeOffset * (as-1+zS),
+            (IALG_Status *)&pAstCfg->xDecOpCb[z].cbStatus);        
+    }
+            
     return 0;
 } //PAF_ASIT_initPhaseDecOpCircBuf
 
 
+// -----------------------------------------------------------------------------
+// ASIT Initialization Function - Output Init-Sync
+//
+//   Name:      PAF_ASIT_initPhaseOutIS
+//   Purpose:   Audio Stream Input Task Function for initialization of Output Init-Sync.
+//
+Int
+PAF_ASIT_initPhaseOutIS(
+    const PAF_ASIT_Params *pP, 
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_ASIT_Config *pAsitCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode counter */
+    PAF_AST_OutInitSyncInfo *pOutISI;
+    Error_Block    eb;
+    Int i;
+
+
+    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    as = pAstCfg->as;
+    
+    /* Output Init-Sync memory */
+    if (!(pAstCfg->xOutIsi = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, 
+        DECODEN * sizeof (*pAstCfg->xOutIsi), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASIT_initPhaseOutIS: AS%d: Memory_calloc failed", as);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+
+    // Reset all decoder stage flags
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        // Get address of Output Init-Sync Info
+        pOutISI = &pAstCfg->xOutIsi[z];
+        for (i = 0; i < ASP_OUTIS_NUM_DEC_STAGES; i++)
+        {
+            // Reset flag value
+            pOutISI->decStageOutInitSyncInfo[i].decFlag = 0;
+        }
+    }    
+    
+    return 0;
+} // PAF_ASIT_initPhaseOutIS
+
+
 #if 0
 // -----------------------------------------------------------------------------
 // AST Processing Function - Pass-Through Processing
@@ -1967,8 +2072,8 @@ PAF_ASIT_autoProcessing(
     }
     //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
     //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
-    frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
-
+    frameLength = FRAMELENGTH; // (***) FL: fix PCM frameLength
+    
     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
     {
@@ -1994,7 +2099,7 @@ PAF_ASIT_autoProcessing(
     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
     if (nbytes == -DIBERR_SYNC)
     {
-#if 1 // (***) FL: shows timing of autosync restart
+#if 0 // (***) FL: shows timing of autosync restart
         // (***) debug // B5
         {
             static Uint8 toggleState = 0;
@@ -2341,8 +2446,8 @@ PAF_ASIT_decodeProcessing(
                 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
                 if (errno)
                 {
-                       gAsipDecodeErrCnt++;
-                       TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
+                    gAsipDecodeErrCnt++;
+                    TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
                     break;
                 }
                 
@@ -2529,7 +2634,7 @@ PAF_ASIT_decodeInit(
 )
 {
     PAF_AST_Config *pAstCfg;
-    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    //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 */
@@ -2541,6 +2646,7 @@ PAF_ASIT_decodeInit(
     Int status;
 #ifdef NON_CACHE_STATUS
     Int8 tempVar8;
+    Int tempVar;
 #endif
     
     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
@@ -2549,7 +2655,7 @@ PAF_ASIT_decodeInit(
     zMI = pP->zone.master;
     (void)as;  // clear compiler warning in case not used with tracing disabled
     
-    pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
 
 #ifdef NON_CACHE_STATUS
     // reset frameCount
@@ -2561,10 +2667,10 @@ PAF_ASIT_decodeInit(
                       GATEMP_INDEX_DEC);
         if (tempVar8)
         {
-            tempVar8 = 0;
+            tempVar = 0;
             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
-                          &tempVar8,
-                          sizeof(tempVar8),
+                          &tempVar,
+                          sizeof(tempVar),
                           GATEMP_INDEX_DEC);
         }
     }
@@ -2752,42 +2858,30 @@ PAF_ASIT_decodeInit(
                 FRAMELENGTH,
                 pC->xDec[z].decodeStatus.bufferRatio);
 #endif
-#if 0 // (***) FL: revisit. Bypass computeFrameLength().
+#if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
             frameLength = pP->fxns->computeFrameLength(z, 
                 FRAMELENGTH, 
                 pC->xDec[z].decodeStatus.bufferRatio);
 #else
-            if (sourceSelect == PAF_SOURCE_PCM)
-            {
-               frameLength = PAF_SYS_FRAMELENGTH;
-            }
-            else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
-            {
-                frameLength = 1536;
-            }
-            else if (sourceSelect == PAF_SOURCE_THD)
-            {
-                frameLength = 1536; //QIN FIX ME
-            }
-            else
-            {
-                frameLength = 256;
-            }
+            // 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; // FL: debug
+                SW_BREAKPOINT; // debug
                 return errno;
             }
-            // FL: debug
+            // debug
             cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
+#endif
             
             if (z != zMD) 
             {
@@ -2968,11 +3062,11 @@ PAF_ASIT_decodeInfo(
             return ASPERR_RECLAIM;
         }
         
-        // FL: debug, capture input buffer
-        capIb(pAstCfg->xInp[zMI].pInpBuf);
-        gCapIb_cnt++;
+        //// FL: debug, capture input buffer
+        //capIb(pAstCfg->xInp[zMI].pInpBuf);
+        //gCapIb_cnt++;
         
-#if 1 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
+#if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
         // (***) debug // B5
         {
             static Uint8 toggleState = 0;
@@ -3025,10 +3119,6 @@ PAF_ASIT_decodeInfo(
             // (***) FL: revisit
             // write back Inp configuration
             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
-            // write back input data //  (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
-            //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
-            //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
-            //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
             // write back Dec configuration
             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
@@ -3522,27 +3612,13 @@ PAF_ASIT_decodeDecode(
                 FRAMELENGTH, 
                 pC->xDec[z].decodeStatus.bufferRatio);
 #endif
-#if 0 // (***) FL: revisit. Bypass computeFrameLength().
+#if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
             frameLength = pP->fxns->computeFrameLength(z, 
                 FRAMELENGTH, 
                 pC->xDec[z].decodeStatus.bufferRatio);
 #else
-            if (sourceSelect == PAF_SOURCE_PCM)
-            {
-                frameLength = PAF_SYS_FRAMELENGTH;
-            }
-            else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
-            {
-                frameLength = 1536;
-            }
-            else if (sourceSelect == PAF_SOURCE_THD)
-            {
-                frameLength = 1536; //QIN FIX ME
-            }
-            else
-            {
-                frameLength = 256;
-            }
+            // Compute decoder frame length based on source selection
+            frameLength = getFrameLengthSourceSel(pP, sourceSelect);
 #endif
 
 
@@ -3550,7 +3626,7 @@ PAF_ASIT_decodeDecode(
 //            // modify for different decoders
 //            if (sourceSelect == PAF_SOURCE_THD)
 //            {
-//             start_profiling = 1;
+//                start_profiling = 1;
 //            }
 //            else
 //            {
@@ -4063,3 +4139,31 @@ void as_traceChannels(PAF_AST_Config *pC, int z)
     }
 }
 #endif
+
+// Compute decoder frame length based on selected source
+static Int getFrameLengthSourceSel(
+    const PAF_ASIT_Params *pP, 
+    Int8 sourceSelect
+)
+{
+    Int frameLength;
+    
+    switch(sourceSelect)
+    {
+        case PAF_SOURCE_PCM:
+            frameLength = FRAMELENGTH;
+            break;
+        case PAF_SOURCE_AC3: 
+        case PAF_SOURCE_DDP: 
+            frameLength = ASIP_FRAMELEN_SS_DDP_AC3;
+            break;
+        case PAF_SOURCE_THD:
+            frameLength = ASIP_FRAMELEN_SS_THD;
+            break;
+        default:
+            frameLength = ASIP_FRAMELEN_SS_DEFAULT;
+            break;
+    }
+    
+    return frameLength;
+}