From: Frank Livingston Date: Thu, 1 Sep 2016 16:03:27 +0000 (-0500) Subject: Update Dec Output circular buffer X-Git-Url: https://git.ti.com/gitweb?p=processor-sdk%2Fperformance-audio-sr.git;a=commitdiff_plain;h=0c0325f60c7f9680d27f1982ae044870536350e1 Update Dec Output circular buffer Add reset flags parameter to cbInit function Change cb latency for DDP back to 512 samples Add underflow/overflow error count stats Add cache invalidate at beginning of read/write flag update functions Add cache wait at end of read/write flag update functions --- diff --git a/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.c b/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.c index 0b9dda9b..12e80a66 100644 --- a/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.c +++ b/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.c @@ -38,6 +38,7 @@ All rights reserved. #include #include +#include "common.h" #include "pafdec.h" #include "pafsp.h" #include "paf_decOpCircBuf.h" @@ -52,7 +53,8 @@ Int cbInit( Int8 sourceSelect, // source select (PCM, DDP, etc.) Int16 decOpFrameLen, // decoder output frame length (PCM samples) Int16 strFrameLen, // stream frame length (PCM samples) - PAF_DecodeOpCircBuf *pCb // decoder output circular buffer + PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer + Int8 resetRwFlags // whether to reset reader, writer, and empty flags ) { PAF_AudioFrame *pAfCb; @@ -95,8 +97,8 @@ Int cbInit( { pCb->maxNumAfCb = MAX_NUM_AF_DDP; pCb->afRdIdx = 0; - pCb->afWrtIdx = 0;//1;//QIN - Reduce delay to prevent cb overflow. Need further investigation. - pCb->pcmRdIdx = 0;//decOpFrameLen - CB_INIT_RD_LAG*strFrameLen; //QIN - Reduce delay to prevent cb overflow. Need further investigation. + pCb->pcmRdIdx = decOpFrameLen - CB_INIT_RD_LAG*strFrameLen; + pCb->afWrtIdx = 1; // initialize audio frames for (n=0; nmaxNumAfCb; n++) @@ -147,11 +149,17 @@ Int cbInit( pMetaBuf += PAF_MAX_PRIVATE_MD_SZ; } } - // update flags - pCb->writerActiveFlag = 0; - pCb->readerActiveFlag = 0; - pCb->emptyFlag = 0; - //pCb->cbWriteAfInit = 0; + + // reset read/write flags + if (resetRwFlags) + { + pCb->writerActiveFlag = 0; + pCb->readerActiveFlag = 0; + pCb->emptyFlag = 0; + } + // reset error counts + pCb->errUndCnt = 0; + pCb->errOvrCnt = 0; // (***) FL: revisit // Write back circular buffer configuration @@ -213,6 +221,7 @@ Int cbWriteStart( // (***) FL: revisit // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); return PAF_DECOP_CB_SOK; }; @@ -222,6 +231,10 @@ Int cbWriteStop( PAF_DecodeOpCircBuf *pCb // decoder output circular buffer ) { + // Invalidate circular buffer configuration + Cache_inv(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); + // update flags pCb->writerActiveFlag = 0; pCb->emptyFlag = 1; @@ -229,6 +242,7 @@ Int cbWriteStop( // (***) FL: revisit // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); return PAF_DECOP_CB_SOK; } @@ -238,12 +252,17 @@ Int cbReadStart( PAF_DecodeOpCircBuf *pCb // decoder output circular buffer ) { + // Invalidate circular buffer configuration + Cache_inv(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); + // update flags pCb->readerActiveFlag = 1; // (***) FL: revisit // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); return PAF_DECOP_CB_SOK; } @@ -253,31 +272,17 @@ Int cbReadStop( PAF_DecodeOpCircBuf *pCb // decoder output circular buffer ) { - // update flags - pCb->readerActiveFlag = 0; - - // (***) FL: revisit - // Write back circular buffer configuration - Cache_wb(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); - - return PAF_DECOP_CB_SOK; -} -// restore read/write flags of the circular buffer. - QIN -Int cbReadWriteRestore( - PAF_DecodeOpCircBuf *pCb // decoder output circular buffer -) -{ - // Invalidate circular buffer configuration. + // Invalidate circular buffer configuration Cache_inv(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); Cache_wait(); - + // update flags - pCb->readerActiveFlag = 1; - pCb->writerActiveFlag = 1; + pCb->readerActiveFlag = 0; // (***) FL: revisit // Write back circular buffer configuration Cache_wb(pCb, sizeof(PAF_DecodeOpCircBuf), Cache_Type_ALLD, 0); + Cache_wait(); return PAF_DECOP_CB_SOK; } @@ -303,6 +308,7 @@ Int cbReadAf( // This shouldn't occur: // writer is active AND draining circular buffer Log_info2("cbReadAf: ERROR: writerActiveFlag=%d, emptyFlag=%d", pCb->writerActiveFlag, pCb->emptyFlag); + SW_BREAKPOINT; // FL: debug return PAF_DECOP_CB_READ_INVSTATE; } @@ -312,7 +318,6 @@ Int cbReadAf( // No active writer, not draining circular buffer. // Skip UNDerflow check, mute output. // - pAfRd->sampleDecode = PAF_SOURCE_PCM; PAF_PROCESS_ZERO(pAfRd->sampleProcess); pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ; @@ -344,6 +349,9 @@ Int cbReadAf( // check underflow if (pCb->numAfCb <= 0) { + pCb->errUndCnt++; + //SW_BREAKPOINT; // FL: debug + Log_info1("cbReadAf: ERROR: underflow, numAfCb=%d", pCb->numAfCb); return PAF_DECOP_CB_READ_UNDERFLOW; } } @@ -413,7 +421,7 @@ Int cbReadAf( for (i = 0; i < PAF_MAX_NUM_PRIVATE_MD; i++) { //Invalidate metadata data - Cache_inv(&pAfCb->pafPrivateMetadata[i], sizeof(PAF_PrivateMetadata), Cache_Type_ALLD, 0); + Cache_inv(&pAfCb->pafPrivateMetadata[i], sizeof(PAF_PrivateMetadata), Cache_Type_ALLD, 0); Cache_wait(); if ((pAfCb->pafPrivateMetadata[i].offset >= pCb->pcmRdIdx) &&(pAfCb->pafPrivateMetadata[i].offset < (pCb->pcmRdIdx + pCb->strFrameLen)) @@ -512,13 +520,15 @@ Int cbWriteAf( } #endif - // check overflow - //if (pCb->numAfCb >= pCb->maxNumAfCb) - //{ - // return PAF_DECOP_CB_WRITE_OVERFLOW; - //} - while (pCb->numAfCb >= pCb->maxNumAfCb); //Qin replace with while loop for debugging + if (pCb->numAfCb >= pCb->maxNumAfCb) + { + pCb->errOvrCnt++; + //SW_BREAKPOINT; + Log_info1("cbWriteAf: ERROR: overflow, numAfCb=%d", pCb->numAfCb); + return PAF_DECOP_CB_WRITE_OVERFLOW; + } + //while (pCb->numAfCb >= pCb->maxNumAfCb); //Qin replace with while loop for debugging // get pointer to current audio frame in circular buffer pAfCb = &pCb->afCb[pCb->afWrtIdx]; @@ -552,7 +562,7 @@ Int cbWriteAf( //Write metadata to circular buffer //QIN for (i = 0; i < PAF_MAX_NUM_PRIVATE_MD; i++) { - if (pAfWrt->pafPrivateMetadata[i].size ) + if (pAfWrt->pafPrivateMetadata[i].size) { pAfCb->pafPrivateMetadata[i].offset = pAfWrt->pafPrivateMetadata[i].offset; pAfCb->pafPrivateMetadata[i].size = pAfWrt->pafPrivateMetadata[i].size; @@ -588,7 +598,7 @@ Int cbWriteAf( Cache_wb(pAfCb->data.sample[i], pCb->decOpFrameLen*sizeof(PAF_AudioData), Cache_Type_ALLD, 0); } } - + // write back private metadata for (i=0; ipafPrivateMetadata[i], sizeof(PAF_PrivateMetadata), Cache_Type_ALLD, 0); @@ -622,16 +632,19 @@ Int cbGetNextWriteAf( // Output log of circular buffer control variables (debug) Int cbLog( PAF_DecodeOpCircBuf *pCb, - Int8 fullLog + Int8 fullLog, + char *locInfo ) { - Log_info4("afRdIdx=%d, pcmRdIdx=%d, afWrtIdx=%d, numAfCb=%d", pCb->afRdIdx, pCb->pcmRdIdx, + Log_info1("CB: %s", (IArg)locInfo); + Log_info3("CB: readerActiveFlag=%d, writerActiveFlag=%d, emptyFlag=%d", pCb->readerActiveFlag, pCb->writerActiveFlag, pCb->emptyFlag); + Log_info4("CB: afRdIdx=%d, pcmRdIdx=%d, afWrtIdx=%d, numAfCb=%d", pCb->afRdIdx, pCb->pcmRdIdx, pCb->afWrtIdx, pCb->numAfCb); if (fullLog) { - Log_info1("maxNumAfCb=%d", pCb->maxNumAfCb); - Log_info2("decOpFrameLen=%d, strFrameLen=%d", pCb->decOpFrameLen, pCb->strFrameLen); + Log_info1("CB: maxNumAfCb=%d", pCb->maxNumAfCb); + Log_info2("CB: decOpFrameLen=%d, strFrameLen=%d", pCb->decOpFrameLen, pCb->strFrameLen); //Log_info1("cbWriteInit=%d", pCb->cbWriteAfInit); } diff --git a/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.h b/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.h index 2e6808d9..b7bcf6c3 100644 --- a/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.h +++ b/processor_audio_sdk_1_00_00_00/pasdk/common/paf_decOpCircBuf.h @@ -66,9 +66,19 @@ typedef struct PAF_DecodeOpCircBuf { Int8 writerActiveFlag; // flag indicates whether CB writer is active Int8 readerActiveFlag; // flag indicates whether CB reader is active Int8 emptyFlag; // flag indicates whether reader should empty (drain) remaining frames in CB - //Int cbWriteAfInit; // indicates whether CB has been initialized for AF writes + Int8 errUndCnt; // underflow count + Int8 errOvrCnt; // overflow count } PAF_DecodeOpCircBuf; +// Initialize circular buffer +Int cbInit( + Int8 sourceSelect, // source select (PCM, DDP, etc.) + Int16 decOpFrameLen, // decoder output frame length (PCM samples) + Int16 strFrameLen, // stream frame length (PCM samples) + PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer + Int8 resetRwFlags // whether to reset reader, writer, and empty flags +); + // Start writes to circular buffer Int cbWriteStart( PAF_DecodeOpCircBuf *pCb // decoder output circular buffer @@ -110,11 +120,8 @@ Int cbGetNextWriteAf( // Output log of circular buffer control variables (debug) Int cbLog( PAF_DecodeOpCircBuf *pCb, - Int8 fullLog -); -// restore read/write flags of the circular buffer. - QIN -Int cbReadWriteRestore( - PAF_DecodeOpCircBuf *pCb // decoder output circular buffer + Int8 fullLog, + char *locInfo ); #endif /* _DEC_OP_CIRC_BUF_H_ */