PASDK-53: Experimental code for circular buffer overflow/underflow handling
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
index 2395334e7899a833b0aee625d52d69fbbb95392f..eae79357db92cd1c75ef626540721e7f1774a0cd 100644 (file)
@@ -119,8 +119,8 @@ PAF_ASOT_Config gPAF_ASOT_config = {
     &gPAF_AST_config    // pAstCfg
 };
 
-// Underflow threshold before returning error to Top-Level FSM
-#define DEC_OP_CB_RDAF_UND_THR  ( 20 ) // FL: arbitrary setting
+// 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 gDecOpCbRdAfUnd  =0; // decoder output circular buffer underflow count
 
 // Global debug counters */
@@ -1665,6 +1665,9 @@ PAF_ASOT_decodeInit(
             SW_BREAKPOINT; // FL: debug
             return errno;
         }
+        gCbReadAfErr=0;     // debug
+        gDecOpCbRdAfUnd=0;  // decoder output circular buffer underflow count
+
         // FL: debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
     }
@@ -1693,6 +1696,7 @@ PAF_ASOT_decodeInit(
         }
     }
     
+    
     return 0;
 }
 
@@ -1868,15 +1872,23 @@ PAF_ASOT_decodeStream(
             
             if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
             {
-                // Reset circular buffer
-                //cbReset(pCbCtl, z);
-                //Log_info0("PAF_ASOT_decodeStream:cbReset");
-
-                // Update underflow count, return if above threshold
+                // 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
+                // Underflows are accumulated across streams since ASOT continues to run.
+                // This means underflow threshold will be reached if enough streams are run.
+                // Need to check behavior on exit/re-entry into Output processing.
+                
+                // Update underflow count.
+                // If above underflow threshold, reset circular buffer underflow count.
                 gDecOpCbRdAfUnd++;
-                //if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR)
+                //if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR) 
                 //{
-                //    gDecOpCbRdAfUnd = 0;
+                //    // Reset circular buffer
+                //    cbReset(pCbCtl, z);
+                //    Log_info0("PAF_ASOT_decodeStream:cbReset");
+                //
+                //    gDecOpCbRdAfUnd = 0; // reset underflow count
                 //    return cbErrno;
                 //}
             }