Add Decoder Output Circular Buffer reset function
authorFrank Livingston <frank-livingston@ti.com>
Sat, 10 Sep 2016 19:55:43 +0000 (14:55 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Sat, 10 Sep 2016 19:55:43 +0000 (14:55 -0500)
processor_audio_sdk_1_00_00_00/pasdk/common/aspDecOpCircBuf_common.c
processor_audio_sdk_1_00_00_00/pasdk/common/aspDecOpCircBuf_common.h
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/audioStreamDecodeProc.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/application/itopo/evmk2g/atboot.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/audioStreamInpProc.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/audioStreamOutProc.c

index aab3e8cfc6ef870a3184b53740575e4b39490dfc..b127faff89125cedcbbe5ea65c2e7b5c699c6cd2 100644 (file)
@@ -33,6 +33,7 @@ All rights reserved.
 *
 */
 
+#include <string.h> // for memset()
 #include <xdc/std.h>
 #include <xdc/runtime/Log.h>
 #include <ti/sysbios/hal/Cache.h>
@@ -40,6 +41,88 @@ All rights reserved.
 
 #include "aspDecOpCircBuf_common.h"
 
+// Reset circular buffer
+Int cbReset(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,
+    Int8 cbIdx
+)
+{
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
+    PAF_AudioFrame *pAfCb;
+    Int8 n;
+    Int8 i;
+
+    // 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();
+
+    if (pCb->sourceSel == PAF_SOURCE_PCM)
+    {
+        // 2*256 in behind
+        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
+        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
+        pCb->pcmRdIdx = 0;
+    }
+    else if (pCb->sourceSel == PAF_SOURCE_DDP)
+    {
+        // 4*256 in behind
+        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
+        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
+        pCb->pcmRdIdx = pCb->decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DDP*pCb->strFrameLen;
+    }
+
+    // initialize circular buffer current number of frames
+    pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
+
+    for (n=0; n<pCb->maxNumAfCb; n++)
+    {
+        pAfCb = &pCb->afCb[n];
+        
+        // clear PCM data
+        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
+        {
+            memset(pAfCb->data.sample[i], pCb->decOpFrameLen, 0);
+        }
+        
+        // clear metadata
+        pAfCb->numPrivateMetadata = 0;
+    }
+    
+    // reset error counts
+    pCb->errUndCnt = 0;
+    pCb->errOvrCnt = 0;
+
+    // Write back circular buffer configuration
+    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+
+    // Write back AF circular buffer
+    Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
+    for (n=0; n<pCb->maxNumAfCb; n++)
+    {
+        pAfCb = &pCb->afCb[n];
+        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
+        {
+            Cache_wb(pAfCb->data.sample[i], pCb->decOpFrameLen*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
+        }
+    }
+    Cache_wait();
+
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
+    return ASP_DECOP_CB_SOK;
+}
+
 // Output log of circular buffer control variables (debug)
 Int cbLog(
     PAF_AST_DecOpCircBufCtl *pCbCtl,
index 8b9994de3f27d28dd9d9f9690ddb1268ffc095ae..7d3decca8034ec7d611209414f4fd5d92e023c26 100644 (file)
@@ -39,6 +39,7 @@ All rights reserved.
 #include <xdc/std.h>
 #include <ti/ipc/GateMP.h>
 #include "paftyp.h"
+#include "pafdec.h"
 
 #define ASP_DECOP_CB_SOK                    ( 0 )       // ok
 #define ASP_DECOP_CB_CTL_INIT_INV_GATE      ( ASP_DECOP_CB_SOK-1 )  // error: invalid gate handle
@@ -50,6 +51,16 @@ All rights reserved.
 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN      ( 6*256 )   // decoder output circular buffer maximum PCM frame length
 #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 )
 
+#define ASP_DECOP_CB_MAX_NUM_AF_PCM         ( 4 )
+#define ASP_DECOP_CB_INIT_LAG_PCM           ( 2 ) // 1...3
+#define ASP_DECOP_CB_INIT_WRTIDX_PCM        ( ASP_DECOP_CB_INIT_LAG_PCM )
+#define ASP_DECOP_CB_INIT_RDIDX_PCM         ( 0 )
+
+#define ASP_DECOP_CB_MAX_NUM_AF_DDP         ( 2 )
+#define ASP_DECOP_CB_INIT_LAG_DDP           ( 4 ) // 0...5
+#define ASP_DECOP_CB_INIT_WRTIDX_DDP        ( 1 )
+#define ASP_DECOP_CB_INIT_RDIDX_DDP         ( 0 )
+
 #define ASP_DECODE_CB_GATE_NAME             ( "AspDecOpCbGate" )
 #define ASP_DECODE_CB_GATE_REGION_ID        ( 0 )
 
@@ -88,6 +99,12 @@ Int cbCtlInit(
     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
 );
 
+// Reset circular buffer
+Int cbReset(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,
+    Int8 cbIdx
+);
+
 // Output log of circular buffer control variables (debug)
 Int cbLog(
     PAF_AST_DecOpCircBufCtl *pCbCtl,
index 3545757375b0d9e634dd0ccd04b64b21dd25e132..3af87fc8a1183d0d2cf51033f0dab69919cf298a 100644 (file)
@@ -230,6 +230,7 @@ Int cbWriteAf(
         //Log_info2("cbWriteAf:pCb->numAfCb=%d, pCb->maxNumAfCb=%d", (IArg)pCb->readerActiveFlag, (IArg)pCb->maxNumAfCb); // FL: debug
     
         // check overflow
+        //while (pCb->numAfCb >= pCb->maxNumAfCb); // FL: debug
         if (pCb->numAfCb >= pCb->maxNumAfCb)
         {
             pCb->errOvrCnt++;
index 6a3fee8704cf67153e0167ea63f07e5c92a6c3bc..20db1fb76c982b06e1d7467e7e1d271852779ce0 100644 (file)
@@ -98,6 +98,10 @@ 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
+#define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
+UInt32 gDecOpCbWrtAfOvr  =0; // decoder output circular buffer overflow count
+
 // Global debug counters */
 UInt32 gSlaveStartErrCnt        =0;
 UInt32 gSlaveStartCnt           =0;
@@ -639,7 +643,23 @@ Void taskAsdpFxn(
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if (cbErrno < 0)
                         {
-                            SW_BREAKPOINT;
+                            //SW_BREAKPOINT; // FL: debug
+                            
+                            if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
+                            {
+                                // Reset circular buffer
+                                cbReset(pCbCtl, z);
+                                // Update underflow count, return if above threshold
+                                gDecOpCbWrtAfOvr++;
+                                if (gDecOpCbWrtAfOvr < DEC_OP_CB_WRTAF_OVR_THR)
+                                {
+                                    cbErrno = 0;
+                                }
+                                else 
+                                {
+                                    gDecOpCbWrtAfOvr = 0;
+                                }
+                            }
                         }
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
index 947e7b145d3afdcaaa30de6f82980899180829bc..cf124696497fb449de652daff6d40eb85987a1cb 100644 (file)
@@ -64,6 +64,7 @@ All rights reserved.
     //execPAIInAnalog
     //execPAIOutAnalog, \
     //execPAIInDigital    
+    //writeDDPJOCDecodeModeDisable, \
 #else
 
 #define CUS_ATBOOT_S \
index dbeb8100e18af5609d522761c86df08c0586156a..1e677e35b6875afb4c14869f852ad27cbbd80398 100644 (file)
@@ -49,12 +49,6 @@ All rights reserved.
 #define DEF_DEC_OP_FRAME_LEN    ( 256 )     // default decoder output frame length
 #define DEF_STR_FRAME_LEN       ( 256 )     // default stream frame length
 
-#define MAX_NUM_AF_PCM      ( 4 )
-#define CB_INIT_RD_LAG_PCM  ( 2 ) // 0...3
-
-#define MAX_NUM_AF_DDP      ( 2 )
-#define CB_INIT_RD_LAG_DDP  ( 4 ) // 0...5
-
 // Generate mute AF on circular buffer read
 static Void cbReadAfMute(
     PAF_AudioFrame *pAfRd,      // audio frame into which to read
@@ -114,8 +108,8 @@ Int cbInit(
     pCb->strFrameLen = DEF_STR_FRAME_LEN;
     
     // initialize circular buffer maximum number of audio frames
-    pCb->maxNumAfCb = MAX_NUM_AF_PCM;
-    pCb->afWrtIdx = CB_INIT_RD_LAG_PCM;
+    pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
+    pCb->afWrtIdx = ASP_DECOP_CB_INIT_LAG_PCM;
     pCb->afRdIdx = 0;
     pCb->pcmRdIdx = 0; // 2*256 in behind
     
@@ -245,16 +239,17 @@ Int cbInitSourceSel(
     // initialize circular buffer maximum number of audio frames
     if (sourceSelect == PAF_SOURCE_PCM)
     {
-        pCb->maxNumAfCb = MAX_NUM_AF_PCM;
-        pCb->afWrtIdx = CB_INIT_RD_LAG_PCM;
-        pCb->afRdIdx = 0;
-        pCb->pcmRdIdx = 0; // 2*256 in behind
+        pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
+        // 2*256 in behind
+        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
+        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
+        pCb->pcmRdIdx = 0;
         
         // initialize audio frames
         for (n=0; n<pCb->maxNumAfCb; n++)
         {
             pAfCb = &pCb->afCb[n];
-            pAfCb->sampleDecode = PAF_SOURCE_PCM;
+            pAfCb->sampleDecode = sourceSelect;
             PAF_PROCESS_ZERO(pAfCb->sampleProcess);
             pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
             pAfCb->sampleCount = decOpFrameLen;
@@ -268,16 +263,17 @@ Int cbInitSourceSel(
     }
     else if (sourceSelect == PAF_SOURCE_DDP)
     {
-        pCb->maxNumAfCb = MAX_NUM_AF_DDP;
-        pCb->afWrtIdx = 1;
-        pCb->afRdIdx = 0;
-        pCb->pcmRdIdx = decOpFrameLen - CB_INIT_RD_LAG_DDP*strFrameLen; // 4*256 behind
+        pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_DDP;
+        // 4*256 in behind
+        pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
+        pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
+        pCb->pcmRdIdx = decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DDP*strFrameLen; // 4*256 behind
         
         // initialize audio frames
         for (n=0; n<pCb->maxNumAfCb; n++)
         {
             pAfCb = &pCb->afCb[n];
-            pAfCb->sampleDecode = PAF_SOURCE_DDP;
+            pAfCb->sampleDecode = sourceSelect;
             PAF_PROCESS_ZERO(pAfCb->sampleProcess);
             pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
             pAfCb->sampleCount = decOpFrameLen;
index f8085b8e909543cf23d99bedfd12d2dc44ad4348..e1952fe9625f1bfaf6a2b95b3c02e106908a4693 100644 (file)
@@ -3027,11 +3027,17 @@ PAF_ASIT_decodeDecode(
                 pC->xDec[z].decodeStatus.bufferRatio);
 #else
             if (sourceSelect == PAF_SOURCE_PCM)
+            {
                 frameLength = 256;
+            }
             else if (sourceSelect == PAF_SOURCE_DDP)
+            {
                 frameLength = 1536;
+            }
             else
+            {
                 frameLength = 256;
+            }
 #endif                    
 
 // ............................................................................
index 7d0b61271fe644663849a3fb7098e0d4b459cafa..6438e654f71fd3f6039d1bba768f6becc0993326 100644 (file)
@@ -119,6 +119,10 @@ 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
+UInt32 gDecOpCbRdAfUnd  =0; // decoder output circular buffer underflow count
+
 // Global debug counters */
 UInt32 gTaskAsopCnt=0; // debug
 UInt32 gAsopInitCnt     =0;
@@ -1842,7 +1846,7 @@ PAF_ASOT_decodeStream(
         Int zS = pP->streamsFromDecodes[z];
         
         //
-        // (***) FL: read circular buffer
+        // Read decoder output circular buffer
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
         cbErrno = cbReadAf(pCbCtl, z, pAfRd);
@@ -1850,7 +1854,20 @@ PAF_ASOT_decodeStream(
         {
             TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
             //SW_BREAKPOINT; // FL: debug
-            //return cbErrno; // (***) FL: ignoring read failures??
+            
+            if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
+            {
+                // Reset circular buffer
+                cbReset(pCbCtl, z);
+
+                // Update underflow count, return if above threshold
+                gDecOpCbRdAfUnd++;
+                if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR)
+                {
+                    gDecOpCbRdAfUnd = 0;
+                    return cbErrno;
+                }
+            }
         }
         //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");