]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/common/aspDecOpCircBuf_common.h
PASDK-218:Add rudimentary Dec Op CB status and alpha command interface
[processor-sdk/performance-audio-sr.git] / pasdk / common / aspDecOpCircBuf_common.h
index ec14feeae51f7ad14924a2c763e81cf7b9ceebf1..9303631fcd1fbcf6c01856b2ae9bcf1c37a0349a 100644 (file)
@@ -51,10 +51,15 @@ All rights reserved.
 #define CB_OP_COUNT_MAX   10000
 #endif
 
+// CB control
+#define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
+#define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
+
 // error return codes
-#define ASP_DECOP_CB_SOK                        ( 0 )                               // ok
-#define ASP_DECOP_CB_CTL_INIT_INV_GATE          ( ASP_DECOP_CB_SOK-1 )              // error: invalid gate handle
-#define ASP_DECOP_CB_ERR_START                  ( ASP_DECOP_CB_CTL_INIT_INV_GATE )  // start error return ID for master & slave error return definitions
+#define ASP_DECOP_CB_SOK                        ( 0 )                                       // ok
+#define ASP_DECOP_CB_CTL_INIT_INV_GATE          ( ASP_DECOP_CB_SOK-1 )                      // error: invalid gate handle
+#define ASP_DECOP_CB_RESET_INV_SOURCE_SEL       ( ASP_DECOP_CB_CTL_INIT_INV_GATE - 1 )      // error: invalid source selection on init
+#define ASP_DECOP_CB_ERR_START                  ( ASP_DECOP_CB_RESET_INV_SOURCE_SEL )       // start error return ID for master & slave error return definitions
 
 #define ASP_DECOP_CB_MAX_NUM_AF                 ( 30 )      // decoder output circular buffer maximum number audio frames
 
@@ -68,8 +73,15 @@ All rights reserved.
 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT         ( 32 )      // decoder output circular buffer maximum number audio PCM channels for MAT
 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT   ( 4*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
 
-#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_PCM_BUF_SZ_32CH48kMAT      ( ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT )
+// (***) FL: !!! REVISIT!!! THD 192 kHz "fudge factor" for CB PCM buffer size.
+// Using this factor in PCM buffer size definition, buffer large enough to execute 192 kHz w/o CB OVR/UND.
+// Need to define CB size in different terms than existing macros.
+// (***) FL: !!! REVISIT!!! Allocating memory for max # channels (e.g. 32 for THD).
+// GROSS over allocation for THD 192 kHz, 6ch max.
+#define THD_HSR_FUDGE_FACTOR                    ( 368640 + 240000 )  
+#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 + THD_HSR_FUDGE_FACTOR)
+// FL: unused
+//#define ASP_DECOP_CB_PCM_BUF_SZ_32CH48kMAT      ( ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT )
 
 #define ASP_DECOP_CB_MAX_NUM_AF_PCM             ( 4 )
 #if (ASP_DECOP_CB_MAX_NUM_AF_PCM > ASP_DECOP_CB_MAX_NUM_AF)
@@ -77,17 +89,17 @@ All rights reserved.
 #endif
 #define ASP_DECOP_CB_INIT_WRTIDX_PCM            ( 0 )
 #define ASP_DECOP_CB_INIT_RDIDX_PCM             ( 0 )
-#define ASP_DECOP_CB_INIT_LAG_PCM               ( 2 )
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM     ( ASP_DECOP_CB_INIT_LAG_PCM * 256 ) // PCM target Nominal Delay in number of samples, fs=48 kHz
+//#define ASP_DECOP_CB_INIT_LAG_PCM               ( 2 )
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM     ( (4+1) * 256 ) // PCM target Nominal Delay in number of samples, fs=48 kHz
 
-#define ASP_DECOP_CB_MAX_NUM_AF_DDP             ( 2 )
+#define ASP_DECOP_CB_MAX_NUM_AF_DDP             ( 3 )
 #if (ASP_DECOP_CB_MAX_NUM_AF_DDP > ASP_DECOP_CB_MAX_NUM_AF)
     #error "CB Max AF DDP error"
 #endif
 #define ASP_DECOP_CB_INIT_WRTIDX_DDP            ( 0 )
 #define ASP_DECOP_CB_INIT_RDIDX_DDP             ( 0 )
-#define ASP_DECOP_CB_INIT_LAG_DDP               ( 1 )
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_DDP        ( ASP_DECOP_CB_INIT_LAG_DDP * 1536 ) // DDP target Nominal Delay in number of samples
+//#define ASP_DECOP_CB_INIT_LAG_DDP               ( 1 )
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_DDP        ( (6+6) * 256 ) // DDP target Nominal Delay in number of samples
 
 #define ASP_DECOP_CB_MAX_NUM_AF_THD             ( 30 ) //( 15 )
 #if (ASP_DECOP_CB_MAX_NUM_AF_THD > ASP_DECOP_CB_MAX_NUM_AF)
@@ -96,56 +108,67 @@ All rights reserved.
 #define ASP_DECOP_CB_INIT_WRTIDX_THD            ( 0 )
 #define ASP_DECOP_CB_INIT_RDIDX_THD             ( 0 )
 //#define ASP_DECOP_CB_INIT_LAG_THD               ( 5 ) // 5*20ms = 100 ms, For the worst case of 100 ms
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3504 )//( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_96kTHD     ( ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=96 kHz
-#define ASP_DECOP_CB_TARGET_ND_SAMPS_192kTHD    ( ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=192 kHz
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3600 ) //( 3504 ) //( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_96kTHD     ( 2*ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=96 kHz
+#define ASP_DECOP_CB_TARGET_ND_SAMPS_192kTHD    ( 4*ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD ) // THD target Nominal Delay in number of samples, fs=192 kHz
 
-#define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
-#define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
+//#define DEF_SOURCE_SEL                          ( PAF_SOURCE_PCM )          // default source select
+//#define DEF_DEC_OP_FRAME_LEN                    ( PAF_SYS_FRAMELENGTH )     // default decoder output frame length
+//#define DEF_STR_FRAME_LEN                       ( PAF_SYS_FRAMELENGTH )     // default stream frame length
 
-#define DEF_SOURCE_SEL                          ( PAF_SOURCE_PCM )          // default source select
-#define DEF_DEC_OP_FRAME_LEN                    ( PAF_SYS_FRAMELENGTH )     // default decoder output frame length
-#define DEF_STR_FRAME_LEN                       ( PAF_SYS_FRAMELENGTH )     // default stream frame length
+// Decoder output circular buffer status
+typedef struct PAF_AST_DecOpCircBufStatus
+{
+    Int size;
+    Int16 strFrameLen;                      // stream frame length (output transaction size)
+} PAF_AST_DecOpCircBufStatus;
 
 // Decoder output circular buffer
 typedef struct PAF_AST_DecOpCircBuf 
 {
-    PAF_AudioFrame *afCb;           // audio frame CB
-    PAF_AudioData *pcmBuf;          // PCM buffer, contains PCM data associated with audio frames
-    UInt8 *metaBuf;                 // metadata buffer, contains metadata associated with audio frames
-    Int8 sourceSel;                 // selected source
-    Int8 primedFlag;                // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed
-    Int16 targetNDSamps;            // target CB Nominal Delay number of samples
-    Int16 deltaSamps;               // number of 256 (N) sample output frames to block reader
-    Int8 afRdIdx;                   // audio frame CB read index
-    Int8 afWrtIdx;                  // audio frame CB write index
-    //Int8 afLagIdx;                  // audio frame CB Lag idx,
-    //Int8 afInitialLag;              // Initial delay/lag between CB write and read
-    Int16 pcmRdIdx;                 // pcm buffer read index
-    Int8 numAfCb;                   // current number frames in CB
-    Int8 maxNumAfCb;                // maximum number of audio frames in CB
-    Int16 decOpFrameLen;            // selected decoder output frame length (input transaction size)
-    Int16 strFrameLen;              // stream frame length (output transaction size)
-    Int8 writerActiveFlag;          // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active
-    Int8 readerActiveFlag;          // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active
-    Int8 drainFlag;                 // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain
-    Int32 readAfWriterInactiveCnt;  // count of read audio frames with inactive writer & not draining
-    Int32 wrtAfReaderInactiveCnt;   // count of write audio frames with inactive reader
-    Int32 wrtAfZeroSampsCnt;        // count of write audio frames with zero samples
-    Int32 errUndCnt;                // read error underflow count
-    Int32 errOvrCnt;                // write error overflow count
-    PAF_AudioData *pcmBufEnd;       // PCM buffer, contains PCM data associated with audio frames end
-    UInt8 *metaBufEnd;              // metadata buffer, contains metadata associated with audio frames end
-    Int8 maxAFChanNum;              // maximum number of audio data channels in audio frame
-    Int16 maxAFSampCount;           // maximum number of sample counts in audio frame
-    PAF_AudioFrame lastAf;          // used to store the last valid read out audio frame info to generate mute frame
+    PAF_AudioFrame *afCb;                   // audio frame CB
+    PAF_AudioData *pcmBuf;                  // PCM buffer, contains PCM data associated with audio frames
+    UInt8 *metaBuf;                         // metadata buffer, contains metadata associated with audio frames
+    Int8 sourceSel;                         // selected source
+    Int8 primedFlag;                        // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed
+    Int16 targetNDSamps;                    // target CB Nominal Delay number of samples
+    Int16 deltaSamps;                       // number of 256 (N) sample output frames to block reader
+    Int8 afRdIdx;                           // audio frame CB read index
+    Int8 afWrtIdx;                          // audio frame CB write index
+    //Int8 afLagIdx;                          // audio frame CB Lag idx,
+    //Int8 afInitialLag;                      // Initial delay/lag between CB write and read
+    Int16 pcmRdIdx;                         // pcm buffer read index
+    Int8 prvMdRdIdx;                        // private metadata read index
+    Int8 numAfCb;                           // current number frames in CB
+    Int8 maxNumAfCb;                        // maximum number of audio frames in CB
+    Int32 numPcmSampsPerCh;                 // current number of PCM samples per channel in CB
+    Int32 maxNumPcmSampsPerCh;              // max number of PCM samples per channel in CB
+    Int16 decOpFrameLen;                    // selected decoder output frame length (input transaction size)
+    Int16 strFrameLen;                      // stream frame length (output transaction size)
+    Int8 writerActiveFlag;                  // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active
+    Int8 readerActiveFlag;                  // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active
+    Int8 drainFlag;                         // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain
+    Int32 readAfWriterInactiveCnt;          // count of read audio frames with inactive writer & not draining
+    Int32 readAfNdCnt;                      // count of read audio frames for nominal delay 
+    Int32 wrtAfReaderInactiveCnt;           // count of write audio frames with inactive reader
+    Int32 wrtAfZeroSampsCnt;                // count of write audio frames with zero samples
+    Int32 errAfUndCnt;                      // read error AF underflow count
+    Int32 errAfOvrCnt;                      // write error AF overflow count
+    Int32 errPcmUndCnt;                     // read error PCM underflow count
+    Int32 errPcmOvrCnt;                     // write error PCM overflow count
+    PAF_AudioData *pcmBufEnd;               // PCM buffer, contains PCM data associated with audio frames end
+    UInt8 *metaBufEnd;                      // metadata buffer, contains metadata associated with audio frames end
+    Int8 maxAFChanNum;                      // maximum number of audio data channels in audio frame
+    Int16 maxAFSampCount;                   // maximum number of sample counts in audio frame
+    PAF_AudioFrame lastAf;                  // used to store the last valid read out audio frame info to generate mute frame
+    PAF_AST_DecOpCircBufStatus cbStatus;    // CB status    
 #ifdef CB_RW_OP_CAP_PP // debug
-    UInt32 *cb_samples_op;          // should be in shared memory, preferred NON cache
-    UInt8 *cb_op_owner;             // should be in shared memory, preferred NON cache
-    UInt8 *cb_afRdIdx;              // should be in shared memory, preferred NON cache
-    UInt8 *cb_afWrtIdx;             // should be in shared memory, preferred NON cache
-    UInt8 *cb_numAfCb;              // should be in shared memory, preferred NON cache
-    UInt32 cb_opCnt;                // range (0 - CB_OP_COUNT_MAX)
+    UInt32 *cb_samples_op;                  // should be in shared memory, preferred NON cache
+    UInt8 *cb_op_owner;                     // should be in shared memory, preferred NON cache
+    UInt8 *cb_afRdIdx;                      // should be in shared memory, preferred NON cache
+    UInt8 *cb_afWrtIdx;                     // should be in shared memory, preferred NON cache
+    UInt8 *cb_numAfCb;                      // should be in shared memory, preferred NON cache
+    UInt32 cb_opCnt;                        // range (0 - CB_OP_COUNT_MAX)
 #endif
 } PAF_AST_DecOpCircBuf;
 
@@ -153,10 +176,13 @@ typedef struct PAF_AST_DecOpCircBuf
 typedef struct PAF_AST_DecOpCircBufStats
 {
     Int32 readAfWriterInactiveCnt;  // count of read audio frames with inactive writer & not draining
+    Int32 readAfNdCnt;              // count of read audio frames for nominal delay
     Int32 wrtAfReaderInactiveCnt;   // count of write audio frames with inactive reader
     Int32 wrtAfZeroSampsCnt;        // count of write audio frames with zero samples
-    Int32 errUndCnt;                // read error underflow count
-    Int32 errOvrCnt;                // write error overflow count
+    Int32 errAfUndCnt;              // read error AF underflow count
+    Int32 errAfOvrCnt;              // write error AF overflow count
+    Int32 errPcmUndCnt;             // read error PCM underflow count
+    Int32 errPcmOvrCnt;             // write error PCM overflow count
 } PAF_AST_DecOpCircBufStats;
 
 // Decoder output circular buffer control