b127faff89125cedcbbe5ea65c2e7b5c699c6cd2
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / common / aspDecOpCircBuf_common.c
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 #include <string.h> // for memset()
37 #include <xdc/std.h>
38 #include <xdc/runtime/Log.h>
39 #include <ti/sysbios/hal/Cache.h>
40 #include <ti/ipc/GateMP.h>
42 #include "aspDecOpCircBuf_common.h"
44 // Reset circular buffer
45 Int cbReset(
46 PAF_AST_DecOpCircBufCtl *pCbCtl,
47 Int8 cbIdx
48 )
49 {
50 IArg key;
51 GateMP_Handle gateHandle;
52 PAF_AST_DecOpCircBuf *pCb;
53 PAF_AudioFrame *pAfCb;
54 Int8 n;
55 Int8 i;
57 // Get gate handle
58 gateHandle = pCbCtl->gateHandle;
59 // Enter gate
60 key = GateMP_enter(gateHandle);
62 // Get circular buffer base pointer
63 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
65 // Invalidate circular buffer configuration
66 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
67 Cache_wait();
69 if (pCb->sourceSel == PAF_SOURCE_PCM)
70 {
71 // 2*256 in behind
72 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
73 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
74 pCb->pcmRdIdx = 0;
75 }
76 else if (pCb->sourceSel == PAF_SOURCE_DDP)
77 {
78 // 4*256 in behind
79 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
80 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
81 pCb->pcmRdIdx = pCb->decOpFrameLen - ASP_DECOP_CB_INIT_LAG_DDP*pCb->strFrameLen;
82 }
84 // initialize circular buffer current number of frames
85 pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
87 for (n=0; n<pCb->maxNumAfCb; n++)
88 {
89 pAfCb = &pCb->afCb[n];
91 // clear PCM data
92 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
93 {
94 memset(pAfCb->data.sample[i], pCb->decOpFrameLen, 0);
95 }
97 // clear metadata
98 pAfCb->numPrivateMetadata = 0;
99 }
101 // reset error counts
102 pCb->errUndCnt = 0;
103 pCb->errOvrCnt = 0;
105 // Write back circular buffer configuration
106 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
108 // Write back AF circular buffer
109 Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
110 for (n=0; n<pCb->maxNumAfCb; n++)
111 {
112 pAfCb = &pCb->afCb[n];
113 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
114 {
115 Cache_wb(pAfCb->data.sample[i], pCb->decOpFrameLen*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
116 }
117 }
118 Cache_wait();
120 // Leave the gate
121 GateMP_leave(gateHandle, key);
123 return ASP_DECOP_CB_SOK;
124 }
126 // Output log of circular buffer control variables (debug)
127 Int cbLog(
128 PAF_AST_DecOpCircBufCtl *pCbCtl,
129 Int8 cbIdx,
130 Int8 fullLog,
131 char *locInfo
132 )
133 {
134 IArg key;
135 GateMP_Handle gateHandle;
136 PAF_AST_DecOpCircBuf *pCb;
138 // Get gate handle
139 gateHandle = pCbCtl->gateHandle;
140 // Enter gate
141 key = GateMP_enter(gateHandle);
143 // Get circular buffer base pointer
144 pCb = &(*pCbCtl->pXDecOpCb)[cbIdx];
146 // Invalidate circular buffer configuration.
147 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
148 Cache_wait();
150 Log_info1("CB: %s", (IArg)locInfo);
151 Log_info3("CB: readerActiveFlag=%d, writerActiveFlag=%d, emptyFlag=%d", pCb->readerActiveFlag, pCb->writerActiveFlag, pCb->emptyFlag);
152 Log_info4("CB: afRdIdx=%d, pcmRdIdx=%d, afWrtIdx=%d, numAfCb=%d", pCb->afRdIdx, pCb->pcmRdIdx,
153 pCb->afWrtIdx,
154 pCb->numAfCb);
155 if (fullLog)
156 {
157 Log_info1("CB: maxNumAfCb=%d", pCb->maxNumAfCb);
158 Log_info2("CB: decOpFrameLen=%d, strFrameLen=%d", pCb->decOpFrameLen, pCb->strFrameLen);
159 //Log_info1("cbWriteInit=%d", pCb->cbWriteAfInit);
160 }
162 // Leave the gate
163 GateMP_leave(gateHandle, key);
165 return ASP_DECOP_CB_SOK;
166 }