]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/common/aspDecOpCircBuf_common.h
PASDK-443:Update CB PCM buffer size to avoid overflow for 192 kHz tests.
[processor-sdk/performance-audio-sr.git] / pasdk / common / aspDecOpCircBuf_common.h
2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #ifndef _ASP_DECOP_CB_COMMON_H_
37 #define _ASP_DECOP_CB_COMMON_H_
39 #include <xdc/std.h>
40 #include <ti/ipc/GateMP.h>
41 #include "paftyp.h"
42 #include "pafdec.h"
44 //#include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
46 //#define CB_RW_OP_CAP_PP // debug
47 #ifdef CB_RW_OP_CAP_PP
48 #define CB_OP_NONE        0
49 #define CB_OP_W           1     // ARM write
50 #define CB_OP_R           2     // DSP read
51 #define CB_OP_COUNT_MAX   10000
52 #endif
54 // CB control
55 #define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
56 #define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
58 // error return codes
59 #define ASP_DECOP_CB_SOK                        ( 0 )                                       // ok
60 #define ASP_DECOP_CB_CTL_INIT_INV_GATE          ( ASP_DECOP_CB_SOK-1 )                      // error: invalid gate handle
61 #define ASP_DECOP_CB_RESET_INV_SOURCE_SEL       ( ASP_DECOP_CB_CTL_INIT_INV_GATE - 1 )      // error: invalid source selection on init
62 #define ASP_DECOP_CB_ERR_START                  ( ASP_DECOP_CB_RESET_INV_SOURCE_SEL )       // start error return ID for master & slave error return definitions
64 #define ASP_DECOP_CB_MAX_NUM_AF                 ( 30 )      // decoder output circular buffer maximum number audio frames
66 #define ASP_DECOP_CB_MAX_NUM_PCM_CH             ( 16 )      // decoder output circular buffer maximum number audio PCM channels
67 #define ASP_DECOP_CB_MAX_NUM_PCM_FRAMES         ( 15 )      // decoder output circular buffer maximum number PCM frames //Qin - Increased to prevent cb overflow for ddp.
68 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN          ( 6*256 )   // decoder output circular buffer maximum PCM frame length
70 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_AAC         ( 16 )      // decoder output circular buffer maximum number audio PCM channels for AAC
71 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kAAC   ( 6*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
73 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP         ( 16 )      // decoder output circular buffer maximum number audio PCM channels for DDP
74 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP   ( 6*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
76 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT         ( 32 )      // decoder output circular buffer maximum number audio PCM channels for MAT
77 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT   ( 4*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
79 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_DTS        ( 32 )      // decoder output circular buffer maximum number audio PCM channels for MAT
80 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDTS  ( 16*256 )  // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
82 // (***) FL: !!! REVISIT!!! THD 192 kHz "fudge factor" for CB PCM buffer size.
83 // Using this factor in PCM buffer size definition, buffer large enough to execute 192 kHz w/o CB OVR/UND.
84 // Need to define CB size in different terms than existing macros.
85 // (***) FL: !!! REVISIT!!! Allocating memory for max # channels (e.g. 32 for THD).
86 // GROSS over allocation for THD 192 kHz, 6ch max.
87 #define THD_HSR_FUDGE_FACTOR                    ( 368640 + 240000 + 384000 )  
88 #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)
89 // FL: unused
90 //#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 )
92 #define ASP_DECOP_CB_MAX_NUM_AF_PCM             ( 4 )
93 #if (ASP_DECOP_CB_MAX_NUM_AF_PCM > ASP_DECOP_CB_MAX_NUM_AF)
94     #error "CB Max AF PCM error"
95 #endif
96 #define ASP_DECOP_CB_INIT_WRTIDX_PCM            ( 0 )
97 #define ASP_DECOP_CB_INIT_RDIDX_PCM             ( 0 )
98 //#define ASP_DECOP_CB_INIT_LAG_PCM               ( 2 )
99 #define ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM     ( (4+1) * 256 ) // PCM target Nominal Delay in number of samples, fs=48 kHz
101 #define ASP_DECOP_CB_MAX_NUM_AF_AAC             ( 4 )
102 #define ASP_DECOP_CB_INIT_WRTIDX_AAC            ( 0 )
103 #define ASP_DECOP_CB_INIT_RDIDX_AAC             ( 0 )
104 #define ASP_DECOP_CB_TARGET_ND_SAMPS_AAC        ( (4+1) * 256 )
106 #define ASP_DECOP_CB_MAX_NUM_AF_DDP             ( 3 )
107 #if (ASP_DECOP_CB_MAX_NUM_AF_DDP > ASP_DECOP_CB_MAX_NUM_AF)
108     #error "CB Max AF DDP error"
109 #endif
110 #define ASP_DECOP_CB_INIT_WRTIDX_DDP            ( 0 )
111 #define ASP_DECOP_CB_INIT_RDIDX_DDP             ( 0 )
112 //#define ASP_DECOP_CB_INIT_LAG_DDP               ( 1 )
113 #define ASP_DECOP_CB_TARGET_ND_SAMPS_DDP        ( (6+6) * 256 ) // DDP target Nominal Delay in number of samples
115 #define ASP_DECOP_CB_MAX_NUM_AF_THD             ( 30 ) //( 15 )
116 #if (ASP_DECOP_CB_MAX_NUM_AF_THD > ASP_DECOP_CB_MAX_NUM_AF)
117     #error "CB Max AF THD error"
118 #endif
119 #define ASP_DECOP_CB_INIT_WRTIDX_THD            ( 0 )
120 #define ASP_DECOP_CB_INIT_RDIDX_THD             ( 0 )
121 //#define ASP_DECOP_CB_INIT_LAG_THD               ( 5 ) // 5*20ms = 100 ms, For the worst case of 100 ms
122 #define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3600 ) //( 3504 ) //( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
123 #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
124 #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
125 //#define DEF_SOURCE_SEL                          ( PAF_SOURCE_PCM )          // default source select
126 //#define DEF_DEC_OP_FRAME_LEN                    ( PAF_SYS_FRAMELENGTH )     // default decoder output frame length
127 //#define DEF_STR_FRAME_LEN                       ( PAF_SYS_FRAMELENGTH )     // default stream frame length
129 // DTS - update for DTS
130 #define ASP_DECOP_CB_MAX_NUM_AF_DTS         ( 10 )
131 #if (ASP_DECOP_CB_MAX_NUM_AF_DTS > ASP_DECOP_CB_MAX_NUM_AF)
132     #error "CB Max AF DTS error"
133 #endif
134 #define ASP_DECOP_CB_INIT_LAG_DTS           ( 2 )
135 #define ASP_DECOP_CB_INIT_WRTIDX_DTS        ( 3 )
136 #define ASP_DECOP_CB_INIT_RDIDX_DTS         ( 0 )
139 // Decoder output circular buffer status
140 typedef struct PAF_AST_DecOpCircBufStatus
142     Int size;
143     Int16 strFrameLen;                      // stream frame length (output transaction size)
144 } PAF_AST_DecOpCircBufStatus;
146 // Decoder output circular buffer
147 typedef struct PAF_AST_DecOpCircBuf 
149     PAF_AudioFrame *afCb;                   // audio frame CB
150     PAF_AudioData *pcmBuf;                  // PCM buffer, contains PCM data associated with audio frames
151     UInt8 *metaBuf;                         // metadata buffer, contains metadata associated with audio frames
152     Int8 sourceSel;                         // selected source
153     Int8 primedFlag;                        // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed
154     Int16 targetNDSamps;                    // target CB Nominal Delay number of samples
155     Int16 deltaSamps;                       // number of 256 (N) sample output frames to block reader
156     Int8 afRdIdx;                           // audio frame CB read index
157     Int8 afWrtIdx;                          // audio frame CB write index
158     //Int8 afLagIdx;                          // audio frame CB Lag idx,
159     //Int8 afInitialLag;                      // Initial delay/lag between CB write and read
160     Int16 pcmRdIdx;                         // pcm buffer read index
161     Int8 prvMdRdIdx;                        // private metadata read index
162     Int8 numAfCb;                           // current number frames in CB
163     Int8 maxNumAfCb;                        // maximum number of audio frames in CB
164     Int32 numPcmSampsPerCh;                 // current number of PCM samples per channel in CB
165     Int32 maxNumPcmSampsPerCh;              // max number of PCM samples per channel in CB
166     Int16 decOpFrameLen;                    // selected decoder output frame length (input transaction size)
167     Int16 strFrameLen;                      // stream frame length (output transaction size)
168     Int8 writerActiveFlag;                  // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active
169     Int8 readerActiveFlag;                  // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active
170     Int8 drainFlag;                         // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain
171     Int32 readAfWriterInactiveCnt;          // count of read audio frames with inactive writer & not draining
172     Int32 readAfNdCnt;                      // count of read audio frames for nominal delay 
173     Int32 wrtAfReaderInactiveCnt;           // count of write audio frames with inactive reader
174     Int32 wrtAfZeroSampsCnt;                // count of write audio frames with zero samples
175     Int32 errAfUndCnt;                      // read error AF underflow count
176     Int32 errAfOvrCnt;                      // write error AF overflow count
177     Int32 errPcmUndCnt;                     // read error PCM underflow count
178     Int32 errPcmOvrCnt;                     // write error PCM overflow count
179     PAF_AudioData *pcmBufEnd;               // PCM buffer, contains PCM data associated with audio frames end
180     UInt8 *metaBufEnd;                      // metadata buffer, contains metadata associated with audio frames end
181     Int8 maxAFChanNum;                      // maximum number of audio data channels in audio frame
182     Int16 maxAFSampCount;                   // maximum number of sample counts in audio frame
183     PAF_AudioFrame lastAf;                  // used to store the last valid read out audio frame info to generate mute frame
184     PAF_AST_DecOpCircBufStatus cbStatus;    // CB status    
185 #ifdef CB_RW_OP_CAP_PP // debug
186     UInt32 *cb_samples_op;                  // should be in shared memory, preferred NON cache
187     UInt8 *cb_op_owner;                     // should be in shared memory, preferred NON cache
188     UInt8 *cb_afRdIdx;                      // should be in shared memory, preferred NON cache
189     UInt8 *cb_afWrtIdx;                     // should be in shared memory, preferred NON cache
190     UInt8 *cb_numAfCb;                      // should be in shared memory, preferred NON cache
191     UInt32 cb_opCnt;                        // range (0 - CB_OP_COUNT_MAX)
192 #endif
193 } PAF_AST_DecOpCircBuf;
195 // Decoder output circular buffer statistics
196 typedef struct PAF_AST_DecOpCircBufStats
198     Int32 readAfWriterInactiveCnt;  // count of read audio frames with inactive writer & not draining
199     Int32 readAfNdCnt;              // count of read audio frames for nominal delay
200     Int32 wrtAfReaderInactiveCnt;   // count of write audio frames with inactive reader
201     Int32 wrtAfZeroSampsCnt;        // count of write audio frames with zero samples
202     Int32 errAfUndCnt;              // read error AF underflow count
203     Int32 errAfOvrCnt;              // write error AF overflow count
204     Int32 errPcmUndCnt;             // read error PCM underflow count
205     Int32 errPcmOvrCnt;             // write error PCM overflow count
206 } PAF_AST_DecOpCircBufStats;
208 // Decoder output circular buffer control
209 typedef struct PAF_AST_DecOpCircBufCtl
211     GateMP_Handle gateHandle;           // circular buffer gate handle
212     Int8 numDecOpCb;                    // number of circular buffers
213     PAF_AST_DecOpCircBuf **pXDecOpCb;   // address of decoder output circular buffer base pointer
214 } PAF_AST_DecOpCircBufCtl;
216 // Initialize circular buffer control
217 Int cbCtlInit(
218     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
219     Int8 numDecOpCb,                    // number of circular buffers
220     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
221 );
223 // Reset circular buffer
224 Int cbReset(
225     PAF_AST_DecOpCircBufCtl *pCbCtl,
226     Int8 cbIdx
227 );
229 // Get circular buffer statistics
230 Int cbGetStats(
231     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
232     Int8 cbIdx,                         // decoder output circular buffer index
233     PAF_AST_DecOpCircBufStats *pCbStats // decoder output circular buffer statistics
234     
235 );
237 // Output log of circular buffer control variables (debug)
238 Int cbLog(
239     PAF_AST_DecOpCircBufCtl *pCbCtl,
240     Int8 cbIdx, 
241     Int8 fullLog, 
242     char *locInfo
243 );
246 #endif /* _ASP_DECOP_CB_COMMON_H_ */