From 61d16f694f113240138536c1fe7b83630efdf453 Mon Sep 17 00:00:00 2001 From: Frank Livingston Date: Tue, 28 Feb 2017 12:36:03 -0600 Subject: [PATCH] PASDK-53: Experimental code for circular buffer overflow/underflow handling --- .../framework/audioStreamDecodeProc.c | 32 ++++++++++++++++--- pasdk/test_dsp/framework/audioStreamInpProc.c | 6 ++-- pasdk/test_dsp/framework/audioStreamOutProc.c | 30 +++++++++++------ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/pasdk/test_arm/framework/audioStreamDecodeProc.c b/pasdk/test_arm/framework/audioStreamDecodeProc.c index 38820aeb..effd395e 100644 --- a/pasdk/test_arm/framework/audioStreamDecodeProc.c +++ b/pasdk/test_arm/framework/audioStreamDecodeProc.c @@ -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"); } diff --git a/pasdk/test_dsp/framework/audioStreamInpProc.c b/pasdk/test_dsp/framework/audioStreamInpProc.c index cb0adfaf..e791f6c1 100644 --- a/pasdk/test_dsp/framework/audioStreamInpProc.c +++ b/pasdk/test_dsp/framework/audioStreamInpProc.c @@ -311,7 +311,8 @@ UInt32 gcapIb_cnt =0; UInt32 gAsipInfo2_PrimaryErrCnt =0; UInt32 gAsipInfo2_ErrCnt =0; // debug -UInt32 gCbErrnoCnt =0; // decoder circular buffer error count (write on ARM returned to DSP) +UInt32 gCbWrtAfErrCnt =0; // // decoder output circular buffer write error count (returned from ARM to DSP) + #include "dbgDib.h" // debug @@ -321,7 +322,6 @@ extern struct { } IACP_STD_BETA_TABLE; // FL: debug -#include "evmc66x_pinmux.h" #include "evmc66x_gpio_dbg.h" /* @@ -3447,7 +3447,7 @@ PAF_ASIT_decodeDecode( cbErrno = *(Int32 *)&pAspMsg->buf[argIdx]; if (cbErrno != 0) { - gCbErrnoCnt++; + gCbWrtAfErrCnt++; TRACE_TERSE1("CB write error=%d", cbErrno); //SW_BREAKPOINT; // temporary } diff --git a/pasdk/test_dsp/framework/audioStreamOutProc.c b/pasdk/test_dsp/framework/audioStreamOutProc.c index 2395334e..eae79357 100644 --- a/pasdk/test_dsp/framework/audioStreamOutProc.c +++ b/pasdk/test_dsp/framework/audioStreamOutProc.c @@ -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; //} } -- 2.39.2