PASDK-218:Move ownership of CB stream frame size to DSP:ASOT
authorFrank Livingston <frank-livingston@ti.com>
Mon, 17 Jul 2017 16:57:16 +0000 (11:57 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Mon, 17 Jul 2017 16:57:16 +0000 (11:57 -0500)
pasdk/common/aspDecOpCircBuf_common.h
pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
pasdk/test_arm/framework/aspDecOpCircBuf_slave.h
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
pasdk/test_dsp/framework/aspDecOpCircBuf_master.h
pasdk/test_dsp/framework/audioStreamOutProc.c

index 4e18afa79bd58c8590c4cb00ed8ecc79b70550eb..f67bd67f6fb833d513c4e8145dce1640d2d61371 100644 (file)
@@ -51,6 +51,10 @@ All rights reserved.
 #define CB_OP_COUNT_MAX   10000
 #endif
 
+// CB control
+#define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
+#define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
+
 // error return codes
 #define ASP_DECOP_CB_SOK                        ( 0 )                               // ok
 #define ASP_DECOP_CB_CTL_INIT_INV_GATE          ( ASP_DECOP_CB_SOK-1 )              // error: invalid gate handle
@@ -96,16 +100,14 @@ All rights reserved.
 #define ASP_DECOP_CB_INIT_WRTIDX_THD            ( 0 )
 #define ASP_DECOP_CB_INIT_RDIDX_THD             ( 0 )
 //#define ASP_DECOP_CB_INIT_LAG_THD               ( 5 ) // 5*20ms = 100 ms, For the worst case of 100 ms
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3504 ) //( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_96kTHD     ( ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=96 kHz
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3600 ) //( 3504 ) //( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_96kTHD     ( 7200 ) // THD target Nominal Delay in number of samples, fs=96 kHz
 #define ASP_DECOP_CB_TARGET_ND_SAMPS_192kTHD    ( ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=192 kHz
 
-#define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
-#define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
+//#define DEF_SOURCE_SEL                          ( PAF_SOURCE_PCM )          // default source select
+//#define DEF_DEC_OP_FRAME_LEN                    ( PAF_SYS_FRAMELENGTH )     // default decoder output frame length
+//#define DEF_STR_FRAME_LEN                       ( PAF_SYS_FRAMELENGTH )     // default stream frame length
 
-#define DEF_SOURCE_SEL                          ( PAF_SOURCE_PCM )          // default source select
-#define DEF_DEC_OP_FRAME_LEN                    ( PAF_SYS_FRAMELENGTH )     // default decoder output frame length
-#define DEF_STR_FRAME_LEN                       ( PAF_SYS_FRAMELENGTH )     // default stream frame length
 
 // Decoder output circular buffer
 typedef struct PAF_AST_DecOpCircBuf 
index d864671b1ddce913d41d917f9a0a8a8d8b38d9fb..7965102f01f3edd9bfc49ea0e97afd9c7818a058 100644 (file)
@@ -85,16 +85,15 @@ Int cbCtlInit(
 #endif
 
 // debug
-//Int8 gCbInitSourceSelCnt=0;
-//Int8 gCbInitSourceSelThdCnt=0;
+//Int8 gCbInitDecWriteCnt=0;
+//Int8 gCbInitDecWriteThdCnt=0;
 
-// Initialize circular buffer based on selected source
-Int cbInitSourceSel(
+/// Initialize circular buffer for Decoder writes
+Int cbInitDecWrite(
     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
     PAF_AudioFrame *pDecInitAf          // pointer to Dec output audio frame used for CB initialization
 )
@@ -108,7 +107,7 @@ Int cbInitSourceSel(
     Int8 n;
     Int8 i;
 
-    //gCbInitSourceSelCnt++; // debug
+    //gCbInitDecWriteCnt++; // debug
     
     // Get gate handle
     gateHandle = pCbCtl->gateHandle;
@@ -122,7 +121,7 @@ Int cbInitSourceSel(
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
 
-    //Log_info1("cbInitSourceSel:afCb=0x%04x", (IArg)pCb->afCb); // debug
+    //Log_info1("cbInitDecWrite:afCb=0x%04x", (IArg)pCb->afCb); // debug
 
     // Set source select
     pCb->sourceSel = sourceSelect;
@@ -130,9 +129,6 @@ Int cbInitSourceSel(
     // 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
@@ -641,7 +637,9 @@ Int cbWriteAf(
                 
                 // Calculate number of output frames to block reader.
                 // This is sample count reader waits before allowed to actually read samples from the CB.
-                pCb->deltaSamps = (pCb->targetNDSamps - pAfWrt->sampleCount + (pCb->strFrameLen-1)) / pCb->strFrameLen * pCb->strFrameLen;
+                //pCb->deltaSamps = (pCb->targetNDSamps - pAfWrt->sampleCount + (pCb->strFrameLen-1)) / pCb->strFrameLen * pCb->strFrameLen;
+                // FL: CB read decrements by strFrameLen and tests for >0, so rounding to strFrameLen is unnecessary
+                pCb->deltaSamps = pCb->targetNDSamps - pAfWrt->sampleCount;
                 
                 // debug
                 //gSampleCountBuf[gPrimedFlagCnt] = pAfWrt->sampleCount;
@@ -667,6 +665,8 @@ Int cbWriteAf(
             }
             Cache_wait();
 
+#if 0 // (***) FL: shows timing of CB write
+            // debug
             {
                 static Uint8 toggleState = 0;
                if (toggleState == 0)
@@ -675,6 +675,8 @@ Int cbWriteAf(
                    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);
         }
index c632bb96a13444eca0f95040041ac3494d4723bf..f7db4322b2c344a5b88ea7e5f36ba31abee6412a 100644 (file)
@@ -43,18 +43,19 @@ All rights reserved.
 #define ASP_DECOP_CB_INIT_INV_SOURCE_SEL    ( ASP_DECOP_CB_ERR_START-1 )    // error: invalid source selection on init
 #define ASP_DECOP_CB_WRITE_OVERFLOW         ( ASP_DECOP_CB_ERR_START-2 )    // error: write overflow
 
-// Initialize circular buffer for selected source
-Int cbInitSourceSel(
+#define DEF_DEC_OP_FRAME_LEN                ( PAF_SYS_FRAMELENGTH )         // default decoder output frame length
+
+// Initialize circular buffer for Decoder writes
+Int cbInitDecWrite(
     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
     PAF_AudioFrame *pDecInitAf          // pointer to Dec output audio frame used for CB initialization
 );
 
-    // Start writes to circular buffer
+// Start writes to circular buffer
 Int cbWriteStart(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
     Int8 cbIdx                          // decoder output circular buffer index
index 388cdbc6781aec8964e636b634b6312c788b27d5..fbb796030825ebf16da5eb781670a6cc3df5567b 100644 (file)
@@ -843,14 +843,11 @@ Void taskAsdpFxn(
                             // FL: cbInitSourceSel() moved from DSP:ASIT:INIT:decodeInit()
                             //  frameLength: changed to decodeControl.frameLength.
                             //    Written by ASIT:decodeInit:getFrameLengthSourceSel().
-                            //  FRAMELENGTH: pP->frameLength.
-                            //    Formerly ASIT, now ASDT but same value (PAF_SYS_FRAMELENGTH).
-                            //
                             
-                            // Initialize decoder output circular buffer for selected source
-                            errno = cbInitSourceSel(pCbCtl, z, sourceSelect, 
+                            // Initialize decoder output circular buffer
+                            errno = cbInitDecWrite(pCbCtl, z, sourceSelect,
                                 pAstCfg->xDec[z].decodeControl.frameLength, 
-                                FRAMELENGTH, 0, pAfWrt);
+                                0, pAfWrt);
                             if (errno)
                             {
                                 SW_BREAKPOINT; // debug
@@ -878,8 +875,9 @@ Void taskAsdpFxn(
                         //pCb = &pAstCfg->xDecOpCb[z];
                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);                                                
 
-                        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107); // debug
+                        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); // debug
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
+                        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
                         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_WRITE_OVERFLOW))
                         {
                             gCbWrtAfErrCnt++;
index e7349d0546d6fe6027b56aff8cdae955e109d3eb..e19652d08f52e03ae5a471177fc5d443bf6d6e0c 100644 (file)
@@ -268,7 +268,6 @@ Int cbInit(
     return ASP_DECOP_CB_SOK;
 }
 
-
 #if 0 // FL: moved to ARM
 // debug
 //Int8 gCbInitSourceSelCnt=0;
@@ -519,6 +518,43 @@ Int cbInitSourceSel(
 }
 #endif
 
+// Initialize circular buffer for Stream reads
+Int cbInitStreamRead(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    Int16 strFrameLen                   // stream frame length (PCM samples)
+)
+{
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
+    
+    // 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();
+
+    // Set output frame length
+    pCb->strFrameLen = strFrameLen;
+
+    // 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 ret;
+    return ASP_DECOP_CB_SOK;
+}
+
 // Start reads from circular buffer
 Int cbReadStart(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
@@ -712,6 +748,7 @@ Int cbReadAf(
             cbReadMuteWithLastAfInfo(pCb, pAfRd);
             //SW_BREAKPOINT; // FL: debug
             
+#if 0 // (***) FL: shows timing of CB underflow
             // debug
             {
                 static Uint8 toggleState = 0;
@@ -721,6 +758,7 @@ Int cbReadAf(
                     GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
                 toggleState = ~(toggleState);
             }
+#endif
 
             #ifdef CB_RW_OP_CAP_PP // debug
             if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
@@ -887,6 +925,7 @@ Int cbReadAf(
         // FL: this update of Last AF is handled above
         //memcpy (&pCb->lastAf, pAfRd, sizeof(PAF_AudioFrame));
 
+#if 0 // (***) FL: shows timing of successful CB read
         {
             static Uint8 toggleState = 0;
             if (toggleState == 0)
@@ -895,6 +934,7 @@ Int cbReadAf(
                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
             toggleState = ~(toggleState);
         }
+#endif        
     }
     
     if (pCb->drainFlag == 1)
index 56d15396aa465b5ea229270e2d53b07d9072ccfb..1cc7906270f52074edd4497325cb5d93aa66cf2f 100644 (file)
@@ -63,6 +63,13 @@ Int cbInitSourceSel(
 );
 #endif
 
+// Initialize circular buffer for Stream reads
+Int cbInitStreamRead(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    Int16 strFrameLen                   // stream frame length (PCM samples)
+);
+
 // Start reads from circular buffer
 Int cbReadStart(
     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
index 3eb5658f6f564e15cd8d74399320ca5ca1955136..480edc03b841f22c1e9fc2633d156ed2b3af0239 100644 (file)
@@ -2080,6 +2080,19 @@ PAF_ASOT_decodeInit(
 
     for (z=DECODE1; z < DECODEN; z++)
     {
+        //  FRAMELENGTH: pP->frameLength.
+        //    Formerly ASIT, now ASOT but same value (PAF_SYS_FRAMELENGTH).
+        //
+
+        // Initialize decoder output circular buffer for stream reads
+        errno = cbInitStreamRead(pCbCtl, z, FRAMELENGTH);
+        if (errno)
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
+            SW_BREAKPOINT; // debug
+            return errno;
+        }
+        
         // Start decoder output circular buffer reads
         errno = cbReadStart(pCbCtl, z);
         if (errno)
@@ -2088,6 +2101,7 @@ PAF_ASOT_decodeInit(
             SW_BREAKPOINT; // 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
@@ -2305,8 +2319,9 @@ PAF_ASOT_decodeStream(
         // Read decoder output circular buffer
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
         cbErrno = cbReadAf(pCbCtl, z, pAfRd);
+        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
         if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
         {
             gCbReadAfErr++;
@@ -2451,7 +2466,9 @@ PAF_ASOT_decodeEncode(
             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);
+            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
             errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
+            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
             if (errno < 0)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2579,8 +2596,10 @@ PAF_ASOT_decodeEncode(
         if (pAstCfg->xOut[z].hTxSio) 
         {
             TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
+            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);
             if (errno)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2931,6 +2950,14 @@ PAF_ASOT_stopOutput(
     return errno;
 } //PAF_ASOT_stopOutput
 
+UInt32 gNumRateXCalc1=0;
+UInt32 gNumRateXCalc2=0;
+UInt32 gNumDobErrRateChange=0;
+Int gCheck[100];
+float gRateI[100];
+float gRateO[100];
+float gRateX[100];
+
 
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function Helper - SIO Driver Change
@@ -3445,8 +3472,21 @@ static Int PAF_ASOT_initSyncDecInfo1(
         //{
         //    return errno;
         //}
-        outIsCpyAf(pDecInfo1Af, pStrAf);
         
+        // Hack to set ASOT output frame length.
+            // THD sets this to 256 (hard-coded in Dec Info)
+            // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
+            // PCM sets this to 256 (decodeControl.frameLength)
+        pDecInfo1Af->sampleCount = 256;                        // !!!! Revisit !!!!
+        
+        outIsCpyAf(pDecInfo1Af, pStrAf);
+
+        // Hack to set ASOT output frame length
+            // THD sets this to 256 (hard-coded in Dec Info)
+            // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
+            // PCM sets this to 256 (decodeControl.frameLength)
+        //pStrAf->sampleCount = 256;                   // !!!! Revisit !!!!
+
         // outputInfo1():
         //      - ASP chain reset,
         //      - Enc Info
@@ -3640,7 +3680,9 @@ PAF_ASOT_decodeFinalTest(
     zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
 
     // Check circular buffer drain state
+    //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
     errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
+    //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
     if (errno < 0)
     {
         return errno;