]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/common/aspDecOpCircBuf_common.h
Update MAT-THD submodule
[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 //#define CB_RW_OP_CAP_PP // debug
45 #ifdef CB_RW_OP_CAP_PP
46 #define CB_OP_NONE        0
47 #define CB_OP_W           1     // ARM write
48 #define CB_OP_R           2     // DSP read
49 #define CB_OP_COUNT_MAX   10000
50 #endif
52 // error return codes
53 #define ASP_DECOP_CB_SOK                        ( 0 )                               // ok
54 #define ASP_DECOP_CB_CTL_INIT_INV_GATE          ( ASP_DECOP_CB_SOK-1 )              // error: invalid gate handle
55 #define ASP_DECOP_CB_ERR_START                  ( ASP_DECOP_CB_CTL_INIT_INV_GATE )  // start error return ID for master & slave error return definitions
57 #define ASP_DECOP_CB_MAX_NUM_AF                 ( 30 )      // decoder output circular buffer maximum number audio frames
59 #define ASP_DECOP_CB_MAX_NUM_PCM_CH             ( 16 )      // decoder output circular buffer maximum number audio PCM channels
60 #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.
61 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN          ( 6*256 )   // decoder output circular buffer maximum PCM frame length
63 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP         ( 16 )      // decoder output circular buffer maximum number audio PCM channels for DDP
64 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP   ( 6*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
66 #define ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT         ( 32 )      // decoder output circular buffer maximum number audio PCM channels for MAT
67 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT   ( 4*256 )   // decoder output circular buffer maximum PCM frame length at 48kHz sampling rate
69 #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 )
70 #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 )
72 #define ASP_DECOP_CB_MAX_NUM_AF_PCM             ( 4 )
73 #if (ASP_DECOP_CB_MAX_NUM_AF_PCM > ASP_DECOP_CB_MAX_NUM_AF)
74     #error "CB Max AF PCM error"
75 #endif
76 #define ASP_DECOP_CB_INIT_WRTIDX_PCM            ( 0 )
77 #define ASP_DECOP_CB_INIT_RDIDX_PCM             ( 0 )
78 #define ASP_DECOP_CB_INIT_LAG_PCM               ( 2 )
79 #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
81 #define ASP_DECOP_CB_MAX_NUM_AF_DDP             ( 2 )
82 #if (ASP_DECOP_CB_MAX_NUM_AF_DDP > ASP_DECOP_CB_MAX_NUM_AF)
83     #error "CB Max AF DDP error"
84 #endif
85 #define ASP_DECOP_CB_INIT_WRTIDX_DDP            ( 0 )
86 #define ASP_DECOP_CB_INIT_RDIDX_DDP             ( 0 )
87 #define ASP_DECOP_CB_INIT_LAG_DDP               ( 1 )
88 #define ASP_DECOP_CB_TARGET_ND_SAMPS_48kDDP     ( ASP_DECOP_CB_INIT_LAG_DDP * 1536 ) // DDP target Nominal Delay in number of samples, fs=48 kHz
90 #define ASP_DECOP_CB_MAX_NUM_AF_THD             ( 30 ) //( 15 )
91 #if (ASP_DECOP_CB_MAX_NUM_AF_THD > ASP_DECOP_CB_MAX_NUM_AF)
92     #error "CB Max AF THD error"
93 #endif
94 #define ASP_DECOP_CB_INIT_WRTIDX_THD            ( 0 )
95 #define ASP_DECOP_CB_INIT_RDIDX_THD             ( 0 )
96 //#define ASP_DECOP_CB_INIT_LAG_THD               ( 5 ) // 5*20ms = 100 ms, For the worst case of 100 ms
97 #define ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD     ( 3504 )//( 2224 ) // THD target Nominal Delay in number of samples, fs=48 kHz
99 #define ASP_DECODE_CB_GATE_NAME                 ( "AspDecOpCbGate" ) // name of GateMP used for circular buffer shared memory protection
100 #define ASP_DECODE_CB_GATE_REGION_ID            ( 0 )                // IPC shared region ID used for CB gate allocation   
102 // Decoder output circular buffer
103 typedef struct PAF_AST_DecOpCircBuf 
105     PAF_AudioFrame *afCb;           // audio frame CB
106     PAF_AudioData *pcmBuf;          // PCM buffer, contains PCM data associated with audio frames
107     UInt8 *metaBuf;                 // metadata buffer, contains metadata associated with audio frames
108     Int8 sourceSel;                 // selected source
109     Int8 primedFlag;                // flag indicated whether CB is primed: FALSE - CB not primed, TRUE - CB primed
110     Int16 targetNDSamps;            // target CB Nominal Delay number of samples
111     Int16 deltaSamps;               // number of 256 (N) sample output frames to block reader
112     Int8 afRdIdx;                   // audio frame CB read index
113     Int8 afWrtIdx;                  // audio frame CB write index
114     //Int8 afLagIdx;                  // audio frame CB Lag idx,
115     //Int8 afInitialLag;              // Initial delay/lag between CB write and read
116     Int16 pcmRdIdx;                 // pcm buffer read index
117     Int8 numAfCb;                   // current number frames in CB
118     Int8 maxNumAfCb;                // maximum number of audio frames in CB
119     Int16 decOpFrameLen;            // selected decoder output frame length (input transaction size)
120     Int16 strFrameLen;              // stream frame length (output transaction size)
121     Int8 writerActiveFlag;          // flag indicates whether CB writer is active: FALSE - writer not active, TRUE - writer active
122     Int8 readerActiveFlag;          // flag indicates whether CB reader is active: FALSE - reader not active, TRUE - reader active
123     Int8 drainFlag;                 // flag indicates whether reader should drain (empty) remaining frames in CB: FALSE - reader should not drain, TRUE - reader should drain
124     Int32 readAfWriterInactiveCnt;  // count of read audio frames with inactive writer & not draining
125     Int32 wrtAfReaderInactiveCnt;   // count of write audio frames with inactive reader
126     Int32 wrtAfZeroSampsCnt;        // count of write audio frames with zero samples
127     Int32 errUndCnt;                // read error underflow count
128     Int32 errOvrCnt;                // write error overflow count
129     PAF_AudioData *pcmBufEnd;       // PCM buffer, contains PCM data associated with audio frames end
130     UInt8 *metaBufEnd;              // metadata buffer, contains metadata associated with audio frames end
131     Int8 maxAFChanNum;              // maximum number of audio data channels in audio frame
132     Int16 maxAFSampCount;           // maximum number of sample counts in audio frame
133     PAF_AudioFrame lastAf;          // used to store the last valid read out audio frame info to generate mute frame
134 #ifdef CB_RW_OP_CAP_PP // debug
135     UInt32 *cb_samples_op;          // should be in shared memory, preferred NON cache
136     UInt8 *cb_op_owner;             // should be in shared memory, preferred NON cache
137     UInt8 *cb_afRdIdx;              // should be in shared memory, preferred NON cache
138     UInt8 *cb_afWrtIdx;             // should be in shared memory, preferred NON cache
139     UInt8 *cb_numAfCb;              // should be in shared memory, preferred NON cache
140     UInt32 cb_opCnt;                // range (0 - CB_OP_COUNT_MAX)
141 #endif
142 } PAF_AST_DecOpCircBuf;
144 // Decoder output circular buffer statistics
145 typedef struct PAF_AST_DecOpCircBufStats
147     Int32 readAfWriterInactiveCnt;  // count of read audio frames with inactive writer & not draining
148     Int32 wrtAfReaderInactiveCnt;   // count of write audio frames with inactive reader
149     Int32 wrtAfZeroSampsCnt;        // count of write audio frames with zero samples
150     Int32 errUndCnt;                // read error underflow count
151     Int32 errOvrCnt;                // write error overflow count
152 } PAF_AST_DecOpCircBufStats;
154 // Decoder output circular buffer control
155 typedef struct PAF_AST_DecOpCircBufCtl
157     GateMP_Handle gateHandle;           // circular buffer gate handle
158     Int8 numDecOpCb;                    // number of circular buffers
159     PAF_AST_DecOpCircBuf **pXDecOpCb;   // address of decoder output circular buffer base pointer
160 } PAF_AST_DecOpCircBufCtl;
162 // Initialize circular buffer control
163 Int cbCtlInit(
164     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
165     Int8 numDecOpCb,                    // number of circular buffers
166     PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
167 );
169 // Reset circular buffer
170 Int cbReset(
171     PAF_AST_DecOpCircBufCtl *pCbCtl,
172     Int8 cbIdx
173 );
175 // Get circular buffer statistics
176 Int cbGetStats(
177     PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
178     Int8 cbIdx,                         // decoder output circular buffer index
179     PAF_AST_DecOpCircBufStats *pCbStats // decoder output circular buffer statistics
180     
181 );
183 // Output log of circular buffer control variables (debug)
184 Int cbLog(
185     PAF_AST_DecOpCircBufCtl *pCbCtl,
186     Int8 cbIdx, 
187     Int8 fullLog, 
188     char *locInfo
189 );
192 #endif /* _ASP_DECOP_CB_COMMON_H_ */