PASDK-53: Experimental code for circular buffer overflow/underflow handling
[processor-sdk/performance-audio-sr.git] / pasdk / test_arm / framework / audioStreamDecodeProc.c
index 38820aeb6a6d64f712329c81a800234ba9590cc2..effd395e41d8ea41477dd533e450733145de04b1 100644 (file)
@@ -101,7 +101,7 @@ PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
-// Underflow threshold before returning error to Top-Level FSM
+// Underflow threshold before circular buffer reset and return error to Top-Level FSM
 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
 UInt32 gDecOpCbWrtAfOvr  =0; // decoder output circular buffer overflow count
 
@@ -118,6 +118,12 @@ UInt32 gSlaveDecInfoCnt         =0;
 UInt32 gSlaveDecDecodeCnt       =0;
 UInt32 gSlaveDecDeactivateCnt   =0;
 
+// debug
+UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count
+
+// FL: (***) debug
+#include "evmc66x_gpio_dbg.h"
+
 
 /*
  *  ======== taskAsdpFxn ========
@@ -493,6 +499,8 @@ Void taskAsdpFxn(
                     {
                         SW_BREAKPOINT;
                     }
+                    gCbWrtAfErrCnt=0;   // debug
+                    gDecOpCbWrtAfOvr=0; // decoder output circular buffer overflow count
                     // FL: debug, log circular buffer control variables
                     cbLog(pCbCtl, z, 1, "cbWriteStart");
                     // Reset audio frame
@@ -712,13 +720,13 @@ Void taskAsdpFxn(
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if (cbErrno < 0)
                         {
+                            gCbWrtAfErrCnt++;
                             //SW_BREAKPOINT; // FL: debug
                             
                             if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
                             {
-                                // Reset circular buffer
-                                cbReset(pCbCtl, z);
-                                // Update overflow count, return if above threshold
+                                // Update underflow count.
+                                // If above underflow threshold, reset circular buffer underflow count.
                                 gDecOpCbWrtAfOvr++;
                                 if (gDecOpCbWrtAfOvr < DEC_OP_CB_WRTAF_OVR_THR)
                                 {
@@ -726,12 +734,28 @@ Void taskAsdpFxn(
                                 }
                                 else 
                                 {
+                                    // Reset circular buffer
+                                    cbReset(pCbCtl, z);
+                                    // 
                                     gDecOpCbWrtAfOvr = 0;
                                 }
                             }
                         }
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
+#if 1 // (***) FL: shows timing of CB write
+                        // (***) debug // B9
+                        {
+                            static Uint8 toggleState = 0;
+                            if (toggleState == 0)
+                                GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
+                            else
+                                GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
+                            toggleState = ~(toggleState);
+                        }
+#endif        
+                        
+                        
                         // FL: debug, log circular buffer control variables
                         cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }