PASDK-218:CB updates for THD 192 kHz
authorFrank Livingston <frank-livingston@ti.com>
Sun, 23 Jul 2017 02:32:37 +0000 (21:32 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Sun, 23 Jul 2017 02:32:37 +0000 (21:32 -0500)
- Update CB PCM overflow handling. PCM buffer writer address wrap event
  varies based on dec sample count (PCM buffer not completely filled at
  buffer end), so checking sample count in buffer won't prevent overwrite
  of data not yet read from PCM buffer.
- Increase CB PCM buffer size for 192 kHz (increase "fudge factor") based
  on feedback from CB PCM buffer overflow detection.

pasdk/common/aspDecOpCircBuf_common.h
pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_dsp/framework/audioStreamOutProc.c

index a17aeff67eda9aedfc055c6fb0220c24d117f19b..fc6c9f186da918ac85dd54a06ca07498b9440b50 100644 (file)
@@ -74,11 +74,10 @@ All rights reserved.
 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT   ( 4*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
 
 // (***) !!! REVISIT!!! FL: THD 192 kHz "fudge factor" for CB PCM buffer size.
-// Using this factor in PCM buffer size definition, buffer large enough to execute 96/192 kHz w/o CB OVR/UND.
-// Need to define CB size in different terms than existing macros, e.g. eliminate usage of ASP_DECOP_CB_MAX_NUM_PCM_FRAMES,
-// increase size of ASP_DECOP_CB_MAX_PCM_FRAME_LEN for worst case THD decoder output frame size in 20 msec.
-#define THD_HSR_FUDGE_FACTOR                    ( 2 )  
-#define ASP_DECOP_CB_PCM_BUF_SZ                 ( THD_HSR_FUDGE_FACTOR * ASP_DECOP_CB_MAX_NUM_PCM_CH * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN )
+// Using this factor in PCM buffer size definition, buffer large enough to execute 192 kHz w/o CB OVR/UND.
+// Need to define CB size in different terms than existing macros.
+#define THD_HSR_FUDGE_FACTOR                    ( 488640 )  
+#define ASP_DECOP_CB_PCM_BUF_SZ                 ( ASP_DECOP_CB_MAX_NUM_PCM_CH * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN + THD_HSR_FUDGE_FACTOR)
 // FL: unused
 //#define ASP_DECOP_CB_PCM_BUF_SZ_32CH48kMAT      ( ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT )
 
index e32daef6ca7731a0ab612b534a423a4c6b5504de..79c645bf5bf92f409e311f979c3ef236091ad078 100644 (file)
@@ -441,7 +441,9 @@ Int cbWriteAf(
     PAF_ChannelMask_HD streamMask;
     Int8 i;
     Int16 j;
-    PAF_AudioData *pPcmBuf;UInt8 *pMetaBuf; int nextWrtIdx;PAF_AudioFrame *pAfCbNextAf; 
+    PAF_AudioData *pPcmBuf; UInt8 *pMetaBuf; int nextWrtIdx;PAF_AudioFrame *pAfCbNextAf; 
+    PAF_AudioFrame *pAfCbRd;
+    PAF_AudioData *pPcmBufRd, *pPcmBufWrt;
     
     // Get gate handle
     gateHandle = pCbCtl->gateHandle;
@@ -492,35 +494,81 @@ Int cbWriteAf(
                 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();
-
-                // Leave the gate
-                GateMP_leave(gateHandle, key);
+            //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();
+            //
+            //    // Leave the gate
+            //    GateMP_leave(gateHandle, key);
+            //
+            //    return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
+            //}
 
-                return ASP_DECOP_CB_PCM_WRITE_OVERFLOW;
-            }
-                
-            pAfCb = &pCb->afCb[pCb->afWrtIdx];
-            pPcmBuf = pAfCb->data.sample[0];
-            pMetaBuf = pAfCb->pafPrivateMetadata[0].pMdBuf;
-            if ((pPcmBuf + (pAfWrt->sampleCount * pCb->maxAFChanNum)) >= (pCb->pcmBufEnd))
+            pAfCb = &pCb->afCb[pCb->afWrtIdx]; // get CB AF to be written
+            
+            // Get reader current PCM buffer location for PCM buffer overflow check
+            pAfCbRd = &pCb->afCb[pCb->afRdIdx];
+            //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
+            
+            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
+            
+            // check PCM buffer overflow
+            pPcmBuf = pPcmBufWrt;
+            for (i = 0; i < pCb->maxAFChanNum; i++)
             {
-                pPcmBuf = pCb->pcmBuf;
+                // check PCM buffer wrap
+                if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
+                {
+                    pPcmBuf = pCb->pcmBuf;
+                }
+                
+                // check PCM buffer overflow
+                if ((pPcmBuf < pPcmBufRd) && 
+                    ((pPcmBuf + pAfWrt->sampleCount) >= pPcmBufRd))
+                {
+                    pCb->errPcmOvrCnt++;;
+                    
+                    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;
+                }
+                
+                pPcmBuf += pAfWrt->sampleCount;
             }
             
-            for (i=0; i<pCb->maxAFChanNum; i++)
+            // configure AF sample pointers
+            pPcmBuf = pPcmBufWrt;
+            for (i = 0; i < pCb->maxAFChanNum; i++)
             {
-                pAfCb->data.sample[i] = pPcmBuf;
+                // check PCM buffer wrap
+                if ((pPcmBuf + pAfWrt->sampleCount) >= pCb->pcmBufEnd)
+                {
+                    pPcmBuf = pCb->pcmBuf;
+                }
+                
+                pAfCb->data.sample[i] = pPcmBuf;                
                 pPcmBuf += pAfWrt->sampleCount;
                 pAfCb->data.samsiz[i] = 0;
             }
index 1c71f193c219aec7b3502fdaf773b33f750541ce..a3b16baa15f02a209ed4c9525b26a79cebb8fee3 100644 (file)
@@ -831,9 +831,9 @@ Void taskAsdpFxn(
                         //pCb = &pAstCfg->xDecOpCb[z];
                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);                                                
 
-                        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); // debug
+                        GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99); // debug
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
-                        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
+                        GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
                         if ((cbErrno < 0) && 
                             (cbErrno != ASP_DECOP_CB_AF_WRITE_OVERFLOW) && 
                             (cbErrno != ASP_DECOP_CB_PCM_WRITE_OVERFLOW))
index 3f2f22907911ae1e08f6ba16b978d9836e530f17..ce849f74e45a980ee93e3cd12a09836146575e97 100644 (file)
@@ -2326,9 +2326,9 @@ PAF_ASOT_decodeStream(
         // Read decoder output circular buffer
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
+        GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
         cbErrno = cbReadAf(pCbCtl, z, pAfRd);
-        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+        GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
         if ((cbErrno < 0) && 
             (cbErrno != ASP_DECOP_CB_AF_READ_UNDERFLOW) && 
             (cbErrno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
@@ -2976,14 +2976,6 @@ 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