[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / common / paf_decOpCircBuf.h
2 /*
3 Copyright (c) 2016, 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 _DEC_OP_CIRC_BUF_H_
37 #define _DEC_OP_CIRC_BUF_H_
39 #include <xdc/std.h>
40 #include "paftyp.h"
42 #define PAF_DECOP_CB_SOK ( 0 ) // ok
43 #define PAF_DECOP_CB_INIT_INV_SOURCE_SEL ( -1 ) // error: invalid source selection on init
44 #define PAF_DECOP_CB_WRITE_OVERFLOW ( -2 ) // error: write overflow
45 #define PAF_DECOP_CB_READ_UNDERFLOW ( -3 ) // error: read underflow
46 #define PAF_DECOP_CB_READ_INVSTATE ( -4 ) // error: circular buffer invalid state on read
48 #define PAF_DECOP_CB_MAX_NUM_AF ( 4 ) // decoder output circular buffer maximum number audio frames
49 #define PAF_DECOP_CB_MAX_NUM_PCM_CH ( 16 ) // decoder output circular buffer maximum number audio PCM channels
50 #define PAF_DECOP_CB_MAX_NUM_PCM_FRAMES ( 2 ) // decoder output circular buffer maximum number PCM frames //Qin - Increased to prevent cb overflow for ddp.
51 #define PAF_DECOP_CB_MAX_PCM_FRAME_LEN ( 6*256 ) // decoder output circular buffer maximum PCM frame length
52 #define PAF_DECOP_CB_PCM_BUF_SZ ( PAF_DECOP_CB_MAX_NUM_PCM_CH * PAF_DECOP_CB_MAX_NUM_PCM_FRAMES * PAF_DECOP_CB_MAX_PCM_FRAME_LEN )
54 // Decoder output circular buffer
55 typedef struct PAF_DecodeOpCircBuf {
56 PAF_AudioFrame *afCb; // audio frame CB
57 PAF_AudioData *pcmBuf; // PCM buffer, contains PCM data associated with audio frames
58 Int8 *metaBuf; // metafdata buffer, contains metadata associated with audio frames //QIN
59 Int8 afRdIdx; // audio frame CB read index
60 Int8 afWrtIdx; // audio frame CB write index
61 Int16 pcmRdIdx; // pcm buffer read index
62 Int8 numAfCb; // current number frames in CB
63 Int8 maxNumAfCb; // maximum number of audio frames in CB
64 Int16 decOpFrameLen; // selected decoder output frame length (input transaction size)
65 Int16 strFrameLen; // stream frame length (output transaction size)
66 Int8 writerActiveFlag; // flag indicates whether CB writer is active
67 Int8 readerActiveFlag; // flag indicates whether CB reader is active
68 Int8 emptyFlag; // flag indicates whether reader should empty (drain) remaining frames in CB
69 Int8 errUndCnt; // underflow count
70 Int8 errOvrCnt; // overflow count
71 } PAF_DecodeOpCircBuf;
73 // Initialize circular buffer
74 Int cbInit(
75 Int8 sourceSelect, // source select (PCM, DDP, etc.)
76 Int16 decOpFrameLen, // decoder output frame length (PCM samples)
77 Int16 strFrameLen, // stream frame length (PCM samples)
78 PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer
79 Int8 resetRwFlags // whether to reset reader, writer, and empty flags
80 );
82 // Start writes to circular buffer
83 Int cbWriteStart(
84 PAF_DecodeOpCircBuf *pCb // decoder output circular buffer
85 );
87 // Stop writes to circular buffer
88 Int cbWriteStop(
89 PAF_DecodeOpCircBuf *pCb // decoder output circular buffer
90 );
92 // Start reads from circular buffer
93 Int cbReadStart(
94 PAF_DecodeOpCircBuf *pCb // decoder output circular buffer
95 );
97 // Stop reads from circular buffer
98 Int cbReadStop(
99 PAF_DecodeOpCircBuf *pCb // decoder output circular buffer
100 );
102 // Read audio frame from circular buffer
103 Int cbReadAf(
104 PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer
105 PAF_AudioFrame *pAfRd // audio frame into which to read
106 );
108 // Write audio frame to circular buffer
109 Int cbWriteAf(
110 PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer
111 PAF_AudioFrame *pAfWrt // audio frame from which to write
112 );
114 // Get next audio frame to write in circular buffer
115 Int cbGetNextWriteAf(
116 PAF_DecodeOpCircBuf *pCb, // decoder output circular buffer
117 PAF_AudioFrame **ppAfWrt // audio frame next to be written
118 );
120 // Output log of circular buffer control variables (debug)
121 Int cbLog(
122 PAF_DecodeOpCircBuf *pCb,
123 Int8 fullLog,
124 char *locInfo
125 );
127 #endif /* _DEC_OP_CIRC_BUF_H_ */