d63fe0e3f8401ae29518ace9524eedcab79cf3ba
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 #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/uia/events/UIAEvt.h>
41 #include <ti/ipc/GateMP.h>
43 #include "common.h"
44 #include "paftyp.h"
45 #include "pafdec.h"
46 #include "aspDecOpCircBuf_master.h"
48 #include "evmc66x_gpio_dbg.h" // Debug
50 #ifdef CB_RW_OP_CAP_PP // debug
51 // Global variables
52 Uint32 *gCB_samples_op = NULL;
53 Uint8 *gCB_op_owner = NULL;
54 Uint32 *gCB_opCnt = 0;
55 Uint8 *gCB_afRdIdx = NULL;
56 Uint8 *gCB_afWrtIdx = NULL;
57 Uint8 *gCB_numAfCb = NULL;
58 #endif
60 #if 0
61 // Generate mute AF on circular buffer read
62 static Void cbReadAfMute(
63 PAF_AudioFrame *pAfRd, // audio frame into which to read
64 Int16 strFrameLen // stream frame length (output transaction size)
65 );
66 #endif
68 #if 0
69 // Init last audio frame configuration info
70 static Void cbInitLastAfInfo(
71 PAF_AudioFrame *pAfRd // last audio frame stored in CB instance
72 );
73 #endif
75 // Update last audio frame configuration info
76 static Void cbUpdateLastAfInfo(
77 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
78 PAF_AudioFrame *pAfUpd // audio frame used for update
79 );
81 // Generate mute AF on circular buffer read using the last AF configuration info
82 static Void cbReadMuteWithLastAfInfo(
83 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
84 PAF_AudioFrame *pAfRd // audio frame into which to read
85 );
87 #if 0 // FL: moved to common
88 // Initialize circular buffer control
89 Int cbCtlInit(
90 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
91 Int8 numCb, // number of circular buffers
92 PAF_AST_DecOpCircBuf **pXDecOpCb // address of decoder output circular buffer base pointer
93 )
94 {
95 GateMP_Params gateParams;
96 GateMP_Handle gateHandle;
98 GateMP_Params_init(&gateParams);
99 gateParams.localProtect = GateMP_LocalProtect_THREAD;
100 gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM;
101 gateParams.name = ASP_DECODE_CB_GATE_NAME;
102 gateParams.regionId = ASP_DECODE_CB_GATE_REGION_ID;
103 gateHandle = GateMP_create(&gateParams);
104 if (gateHandle != NULL)
105 {
106 pCbCtl->gateHandle = gateHandle;
107 }
108 else
109 {
110 pCbCtl->gateHandle = NULL;
111 return ASP_DECOP_CB_CTL_INIT_INV_GATE;
112 }
114 pCbCtl->numCb = numCb; // init number of circular buffers
115 pCbCtl->pXDecOpCb = pXDecOpCb; // init base address of circular buffers
117 return ASP_DECOP_CB_SOK;
118 }
119 #endif
121 // Initialize circular buffer
122 Int cbInit(
123 PAF_AST_DecOpCircBuf *pCb
124 )
125 {
126 #if 0 // FL: unused
127 PAF_AudioFrame *pAfCb;
128 PAF_AudioData *pPcmBuf;
129 UInt8 *pMetaBuf;
130 Int8 n;
131 Int8 i;
133 // set source select
134 pCb->sourceSel = DEF_SOURCE_SEL;
136 // set input frame length
137 pCb->decOpFrameLen = DEF_DEC_OP_FRAME_LEN;
139 // set output frame length
140 pCb->strFrameLen = DEF_STR_FRAME_LEN;
142 // initialize circular buffer maximum number of audio frames
143 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD; //ASP_DECOP_CB_MAX_NUM_AF_PCM;
144 pCb->afWrtIdx = ASP_DECOP_CB_INIT_LAG_PCM;
145 pCb->afRdIdx = 0;
146 pCb->pcmRdIdx = 0;
148 // Initialize CB primed flag
149 pCb->primedFlag = 0;
150 // Initialize delta samples
151 pCb->deltaSamps = 0;
153 // set default value to PCM configuration
154 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH;
155 pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
156 // initialize audio frames
157 for (n=0; n<pCb->maxNumAfCb; n++)
158 {
159 pAfCb = &pCb->afCb[n];
160 pAfCb->sampleDecode = PAF_SOURCE_PCM;
161 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
162 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
163 pAfCb->sampleCount = DEF_DEC_OP_FRAME_LEN;
164 pAfCb->channelConfigurationRequest.full = 0;
165 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
166 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
167 pAfCb->channelConfigurationStream.full = 0;
168 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
169 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
170 }
172 // initialize circular buffer current number of frames
173 pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
175 // initialize audio frame PCM buffers
176 pPcmBuf = pCb->pcmBuf;
177 pMetaBuf = pCb->metaBuf;
178 for (n=0; n<pCb->maxNumAfCb; n++)
179 {
180 pAfCb = &pCb->afCb[n];
181 pAfCb->data.nChannels = ASP_DECOP_CB_MAX_NUM_PCM_CH;
182 pAfCb->data.nSamples = DEF_DEC_OP_FRAME_LEN;
183 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
184 {
185 pAfCb->data.sample[i] = pPcmBuf;
186 memset(pAfCb->data.sample[i], 0, DEF_DEC_OP_FRAME_LEN);
187 pPcmBuf += DEF_DEC_OP_FRAME_LEN;
189 pAfCb->data.samsiz[i] = 0;
190 }
192 // write metadata information updated by decoder
193 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
194 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
195 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
196 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
198 // Initialize metadata buffers
199 for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
200 {
201 pAfCb->pafPrivateMetadata[i].offset = 0;
202 pAfCb->pafPrivateMetadata[i].size = 0;
203 pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
204 pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
205 }
206 }
208 // reset read/write flags
209 pCb->writerActiveFlag = 0;
210 pCb->readerActiveFlag = 0;
211 pCb->drainFlag = 0;
213 // reset stats
214 pCb->readAfWriterInactiveCnt = 0;
215 pCb->readAfNdCnt = 0;
216 pCb->wrtAfReaderInactiveCnt = 0;
217 pCb->wrtAfZeroSampsCnt = 0;
218 pCb->errUndCnt = 0;
219 pCb->errOvrCnt = 0;
221 #ifdef CB_RW_OP_CAP_PP // debug
222 // Get address in global variables
223 gCB_samples_op = pCb->cb_samples_op;
224 gCB_op_owner = pCb->cb_op_owner;
225 gCB_opCnt = &pCb->cb_opCnt;
226 gCB_afRdIdx = pCb->cb_afRdIdx;
227 gCB_afWrtIdx = pCb->cb_afWrtIdx;
228 gCB_numAfCb = pCb->cb_numAfCb;
229 #endif
231 cbInitLastAfInfo(&pCb->lastAf);
233 // Write back circular buffer configuration
234 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
235 // Write back AF circular buffer
236 Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
237 // Write back PCM data
238 for (n=0; n<pCb->maxNumAfCb; n++)
239 {
240 pAfCb = &pCb->afCb[n];
241 Cache_wb(pAfCb->data.samsiz, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
242 Cache_wb(pAfCb->data.sample, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
243 for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
244 {
245 Cache_wb(pAfCb->data.sample[i], DEF_DEC_OP_FRAME_LEN*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
246 }
247 }
248 Cache_wait();
249 #endif
251 // set source select
252 pCb->sourceSel = PAF_SOURCE_UNKNOWN;
254 #ifdef CB_RW_OP_CAP_PP // debug
255 // Get address in global variables
256 gCB_samples_op = pCb->cb_samples_op;
257 gCB_op_owner = pCb->cb_op_owner;
258 gCB_opCnt = &pCb->cb_opCnt;
259 gCB_afRdIdx = pCb->cb_afRdIdx;
260 gCB_afWrtIdx = pCb->cb_afWrtIdx;
261 gCB_numAfCb = pCb->cb_numAfCb;
262 #endif
264 // Write back circular buffer configuration
265 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
266 Cache_wait();
268 return ASP_DECOP_CB_SOK;
269 }
271 #if 0 // FL: moved to ARM
272 // debug
273 //Int8 gCbInitSourceSelCnt=0;
274 //Int8 gCbInitSourceSelThdCnt=0;
276 // Initialize circular buffer based on selected source
277 Int cbInitSourceSel(
278 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
279 Int8 cbIdx, // decoder output circular buffer index
280 Int8 sourceSelect, // source select (PCM, DDP, etc.)
281 Int16 decOpFrameLen, // decoder output frame length (PCM samples)
282 Int16 strFrameLen, // stream frame length (PCM samples)
283 Int8 resetRwFlags // whether to reset reader, writer, and drain flags
284 )
285 {
286 IArg key;
287 GateMP_Handle gateHandle;
288 PAF_AST_DecOpCircBuf *pCb;
289 PAF_AudioFrame *pAfCb;
290 PAF_AudioData *pPcmBuf;
291 UInt8 *pMetaBuf;
292 Int8 n;
293 Int8 i;
295 //gCbInitSourceSelCnt++; // debug
297 // Get gate handle
298 gateHandle = pCbCtl->gateHandle;
299 // Enter gate
300 key = GateMP_enter(gateHandle);
302 // Get circular buffer base pointer
303 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
305 // Invalidate circular buffer configuration
306 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
307 Cache_wait();
309 //Log_info1("cbInitSourceSel:afCb=0x%04x", (IArg)pCb->afCb); // debug
311 // set source select
312 pCb->sourceSel = sourceSelect;
314 // set input frame length
315 pCb->decOpFrameLen = decOpFrameLen;
317 // set output frame length
318 pCb->strFrameLen = strFrameLen;
320 //pCb->afInitialLag = 0; // default No lag
321 //pCb->afLagIdx = 0;
322 // Initialize CB primed flag
323 pCb->primedFlag = 0;
324 // Initialize delta samples
325 pCb->deltaSamps = 0;
327 // initialize circular buffer maximum number of audio frames
328 if (sourceSelect == PAF_SOURCE_PCM)
329 {
330 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_PCM;
332 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_PCM;
333 // Initialize target nominal delay
334 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kPCM;
336 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_PCM;
337 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_PCM;
338 pCb->pcmRdIdx = 0;
340 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH;
341 pCb->maxAFSampCount = DEF_DEC_OP_FRAME_LEN;
343 // initialize audio frames
344 for (n=0; n<pCb->maxNumAfCb; n++)
345 {
346 pAfCb = &pCb->afCb[n];
347 pAfCb->sampleDecode = sourceSelect;
348 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
349 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
350 pAfCb->sampleCount = decOpFrameLen;
351 pAfCb->channelConfigurationRequest.full = 0;
352 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
353 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
354 pAfCb->channelConfigurationStream.full = 0;
355 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
356 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
358 // write metadata information updated by decoder
359 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
360 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
361 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
362 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
363 }
364 }
365 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
366 {
367 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_DDP;
369 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_DDP;
370 // Initialize target nominal delay
371 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kDDP;
373 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_DDP;
374 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_DDP;
375 pCb->pcmRdIdx = 0;
377 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_DDP;
378 pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kDDP;
380 // initialize audio frames
381 for (n=0; n<pCb->maxNumAfCb; n++)
382 {
383 pAfCb = &pCb->afCb[n];
384 pAfCb->sampleDecode = sourceSelect;
385 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
386 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
387 pAfCb->sampleCount = decOpFrameLen;
388 pAfCb->channelConfigurationRequest.full = 0;
389 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
390 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
391 pAfCb->channelConfigurationStream.full = 0;
392 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
393 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
395 // write metadata information updated by decoder
396 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
397 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
398 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
399 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
400 }
401 }
402 else if (sourceSelect == PAF_SOURCE_THD)
403 {
404 //gCbInitSourceSelThdCnt++; //debug
406 pCb->maxNumAfCb = ASP_DECOP_CB_MAX_NUM_AF_THD;
408 //pCb->afInitialLag = ASP_DECOP_CB_INIT_LAG_THD;
409 // Initialize target nominal delay
410 pCb->targetNDSamps = ASP_DECOP_CB_TARGET_ND_SAMPS_48kTHD;
412 pCb->afWrtIdx = ASP_DECOP_CB_INIT_WRTIDX_THD;
413 pCb->afRdIdx = ASP_DECOP_CB_INIT_RDIDX_THD;
414 pCb->pcmRdIdx = 0;
416 pCb->maxAFChanNum = ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT;
417 pCb->maxAFSampCount = ASP_DECOP_CB_MAX_PCM_FRAME_LEN_48kMAT;
419 // initialize audio frames
420 for (n=0; n<pCb->maxNumAfCb; n++)
421 {
422 pAfCb = &pCb->afCb[n];
423 pAfCb->sampleDecode = sourceSelect;
424 PAF_PROCESS_ZERO(pAfCb->sampleProcess);
425 pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
426 pAfCb->sampleCount = decOpFrameLen;
427 pAfCb->channelConfigurationRequest.full = 0;
428 pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
429 pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
430 pAfCb->channelConfigurationStream.full = 0;
431 pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
432 pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
434 // write metadata information updated by decoder
435 pAfCb->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
436 pAfCb->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
437 pAfCb->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
438 pAfCb->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
439 }
440 }
441 else
442 {
443 SW_BREAKPOINT;
445 // Leave the gate
446 GateMP_leave(gateHandle, key);
448 return ASP_DECOP_CB_INIT_INV_SOURCE_SEL;
449 }
451 // initialize circular buffer current number of frames
452 pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
454 // initialize audio frame PCM buffers
455 pPcmBuf = pCb->pcmBuf;
456 pMetaBuf = pCb->metaBuf;
457 for (n=0; n<pCb->maxNumAfCb; n++)
458 {
459 pAfCb = &pCb->afCb[n];
460 pAfCb->data.nChannels = pCb->maxAFChanNum;
461 pAfCb->data.nSamples = decOpFrameLen;
462 for (i=0; i<pCb->maxAFChanNum; i++)
463 {
464 pAfCb->data.sample[i] = pPcmBuf;
465 memset(pAfCb->data.sample[i], 0, pCb->maxAFSampCount);
466 pPcmBuf += pCb->maxAFSampCount;
468 pAfCb->data.samsiz[i] = 0;
469 }
471 // Initialize metadata buffers
472 for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
473 {
474 pAfCb->pafPrivateMetadata[i].offset = 0;
475 pAfCb->pafPrivateMetadata[i].size = 0;
476 pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
477 pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
478 }
479 }
481 // reset read/write flags
482 if (resetRwFlags)
483 {
484 pCb->writerActiveFlag = 0;
485 pCb->readerActiveFlag = 0;
486 pCb->drainFlag = 0;
487 }
489 // reset stats
490 pCb->readAfWriterInactiveCnt = 0;
491 pCb->readAfNdCnt = 0;
492 pCb->wrtAfReaderInactiveCnt = 0;
493 pCb->wrtAfZeroSampsCnt = 0;
494 pCb->errUndCnt = 0;
495 pCb->errOvrCnt = 0;
497 // Write back circular buffer configuration
498 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
499 // Write back AF circular buffer
500 Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
501 // Write back PCM data
502 for (n=0; n<pCb->maxNumAfCb; n++)
503 {
504 pAfCb = &pCb->afCb[n];
505 Cache_wb(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
506 Cache_wb(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
507 for (i=0; i<pCb->maxAFChanNum; i++)
508 {
509 Cache_wb(pAfCb->data.sample[i], pCb->maxAFSampCount*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
510 }
511 }
512 Cache_wait();
514 // Leave the gate
515 GateMP_leave(gateHandle, key);
517 return ASP_DECOP_CB_SOK;
518 }
519 #endif
521 // Initialize circular buffer for Stream reads
522 Int cbInitStreamRead(
523 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
524 Int8 cbIdx // decoder output circular buffer index
525 )
526 {
527 IArg key;
528 GateMP_Handle gateHandle;
529 PAF_AST_DecOpCircBuf *pCb;
531 // Get gate handle
532 gateHandle = pCbCtl->gateHandle;
533 // Enter gate
534 key = GateMP_enter(gateHandle);
536 // Get circular buffer base pointer
537 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
539 // Invalidate circular buffer configuration
540 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
541 Cache_wait();
543 // Set output frame length
544 pCb->strFrameLen = pCb->cbStatus.strFrameLen;
546 // Write back circular buffer configuration
547 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
548 Cache_wait();
550 // Leave the gate
551 GateMP_leave(gateHandle, key);
553 //return ret;
554 return ASP_DECOP_CB_SOK;
555 }
557 // Start reads from circular buffer
558 Int cbReadStart(
559 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
560 Int8 cbIdx // decoder output circular buffer index
561 )
562 {
563 IArg key;
564 GateMP_Handle gateHandle;
565 PAF_AST_DecOpCircBuf *pCb;
567 // Get gate handle
568 gateHandle = pCbCtl->gateHandle;
569 // Enter gate
570 key = GateMP_enter(gateHandle);
572 // Get circular buffer base pointer
573 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
575 // Invalidate circular buffer configuration
576 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
577 Cache_wait();
579 //Log_info1("cbReadStart:afCb=0x%04x", (IArg)pCb->afCb); // debug
581 // update flags
582 pCb->readerActiveFlag = 1;
584 // Write back circular buffer configuration
585 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
586 Cache_wait();
588 // Leave the gate
589 GateMP_leave(gateHandle, key);
591 return ASP_DECOP_CB_SOK;
592 }
594 // Stop reads from circular buffer
595 Int cbReadStop(
596 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
597 Int8 cbIdx // decoder output circular buffer index
598 )
599 {
600 IArg key;
601 GateMP_Handle gateHandle;
602 PAF_AST_DecOpCircBuf *pCb;
604 // Get gate handle
605 gateHandle = pCbCtl->gateHandle;
606 // Enter gate
607 key = GateMP_enter(gateHandle);
609 // Get circular buffer base pointer
610 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
612 // Invalidate circular buffer configuration
613 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
614 Cache_wait();
616 //Log_info1("cbReadStop:afCb=0x%04x", (IArg)pCb->afCb); // debug
618 // update flags
619 pCb->readerActiveFlag = 0;
621 // Write back circular buffer configuration
622 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
623 Cache_wait();
625 // Leave the gate
626 GateMP_leave(gateHandle, key);
628 return ASP_DECOP_CB_SOK;
629 }
631 // debug
632 //Int16 gDeltaSampsBuf[20];
633 //Int8 gDeltaSampsBufIdx=0;
635 // Read audio frame from circular buffer
636 Int cbReadAf(
637 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
638 Int8 cbIdx, // decoder output circular buffer index
639 PAF_AudioFrame *pAfRd // audio frame into which to read
640 )
641 {
642 IArg key;
643 GateMP_Handle gateHandle; // CB gate handle to arbitrate CB r/w access
644 PAF_AST_DecOpCircBuf *pCb; // pointer to CB
645 PAF_AudioFrame *pAfCb; // pointer to current CB AF
646 PAF_ChannelMask_HD streamMask; // CB AF stream mask
647 Int16 numSampsRd; // number of samples to read from current CB AF
648 Int16 totNumSampsRd; // total number of samples read from CB
649 Int16 pcmWrtIdx; // read audio frame PCM write index
650 Int8 prvMdWrtIdx; // read audio frame metadata write index
651 Int8 i;
652 Int16 j;
654 // Get gate handle
655 gateHandle = pCbCtl->gateHandle;
656 // Enter gate
657 key = GateMP_enter(gateHandle);
659 // Get circular buffer base pointer
660 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
662 // Invalidate circular buffer configuration.
663 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
664 Cache_wait();
666 //Log_info1("cbReadAf:afCb=0x%04x", (IArg)pCb->afCb); // debug
668 //
669 // Check (writerActiveFlag,drainFlag)=(1,1)
670 //
671 if ((pCb->writerActiveFlag == 1) && (pCb->drainFlag == 1))
672 {
673 //
674 // This shouldn't occur:
675 // writer is active AND draining circular buffer
676 //
678 //Log_info2("cbReadAf: ERROR: writerActiveFlag=%d, drainFlag=%d", pCb->writerActiveFlag, pCb->drainFlag); // debug
679 SW_BREAKPOINT; // debug
681 // Leave the gate
682 GateMP_leave(gateHandle, key);
684 return ASP_DECOP_CB_READ_INVSTATE;
685 }
687 //
688 // Check (writerActiveFlag,drainFlag)=(0,0)
689 //
690 //if (((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0)) || (pCb->afLagIdx < pCb->afInitialLag))
691 if ((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 0))
692 {
693 //
694 // Writer inactive, not draining circular buffer.
695 // Skip UNDerflow check, mute output.
696 //
698 pCb->readAfWriterInactiveCnt++;
700 // Mute output if write inactive and not draining CB
701 //cbReadAfMute(pAfRd, pCb->strFrameLen);
702 cbReadMuteWithLastAfInfo(pCb, pAfRd);
704 // Write back circular buffer configuration.
705 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
706 Cache_wait();
708 // Leave the gate
709 GateMP_leave(gateHandle, key);
711 return ASP_DECOP_CB_SOK;
712 }
714 if ((pCb->writerActiveFlag == 0) && (pCb->drainFlag == 1))
715 {
716 //
717 // Writer inactive, but remaining frames in circular buffer.
718 // Update drain flag.
719 //
721 if (pCb->numAfCb <= 0)
722 {
723 pCb->drainFlag = 0;
725 // Mute output if CB drained
726 cbReadMuteWithLastAfInfo(pCb, pAfRd);
728 // Write back circular buffer configuration.
729 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
730 Cache_wait();
732 // Leave the gate
733 GateMP_leave(gateHandle, key);
735 return ASP_DECOP_CB_SOK;
736 }
737 }
739 //
740 // Hold off read of PCM samples from CB until Nominal Delay satisfied
741 //
742 if ((pCb->primedFlag == 0) || (pCb->deltaSamps > 0))
743 {
744 pCb->readAfNdCnt++;
746 cbReadMuteWithLastAfInfo(pCb, pAfRd);
748 // Write back circular buffer configuration.
749 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
750 Cache_wait();
752 // Leave the gate
753 GateMP_leave(gateHandle, key);
755 return ASP_DECOP_CB_SOK;
756 }
758 //
759 // (writerActiveFlag,drainFlag)= (0,0) and (1,1) states checked above
760 // (writerActiveFlag,drainFlag)=(1,0) and (0,1) states are left
761 // Checking (writerActiveFlag,drainFlag)=(1,0) state here
762 //
763 if (pCb->writerActiveFlag == 1)
764 {
765 // check underflow
766 if (pCb->numAfCb <= 0)
767 {
768 //
769 // Increment underflow count
770 //
771 pCb->errAfUndCnt++;
773 // Mute output on underflow
774 //cbReadAfMute(pAfRd, pCb->strFrameLen);
775 cbReadMuteWithLastAfInfo(pCb, pAfRd);
776 //SW_BREAKPOINT; // debug
778 #if 0 // (***) FL: shows timing of CB underflow
779 // debug
780 {
781 static Uint8 toggleState = 0;
782 if (toggleState == 0)
783 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
784 else
785 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
786 toggleState = ~(toggleState);
787 }
788 #endif
790 #ifdef CB_RW_OP_CAP_PP // debug
791 if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
792 {
793 if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
794 {
795 // log sample count
796 pCb->cb_samples_op[pCb->cb_opCnt] = 0; // due to underflow
797 pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_R;
798 // log idxs
799 pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
800 pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
801 pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
802 pCb->cb_opCnt++;
803 }
804 }
805 #endif
807 // Write back circular buffer configuration.
808 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
809 Cache_wait();
811 // Leave the gate
812 GateMP_leave(gateHandle, key);
814 return ASP_DECOP_CB_AF_READ_UNDERFLOW;
815 }
816 }
818 //
819 // Checking (writerActiveFlag,drainFlag)=(1,0) state above and here
820 // Checking (writerActiveFlag,drainFlag)=(0,1) state here
821 //
822 if ((pCb->writerActiveFlag == 1) || (pCb->drainFlag == 1))
823 {
824 //
825 // Writer active or draining remaining frames in circular buffer.
826 // Read next audio frame.
827 //
829 //
830 // Read Audio Frame from CB Audio Frames.
831 // Read PCM & associated metadata from CB AFs until Read AF is filled.
832 //
833 // If multiple CB AFs are read in creating Read AF, CB AF parameters
834 // can *change* between read CB AFs. Since only one Read AF is produced
835 // per CB read, this is a "data collision", i.e. can't have more than
836 // one set of CB AF parameters in Read AF.
837 //
838 // Currently applying parameters from earliest read CB AF to Read Af.
839 // This can result in delay (or skip) w.r.t. application of additional
840 // CB AF parameters not used for creating Read AF. This is reasonable
841 // given there's no way to "interpolate" AF parameters, e.g. how to
842 // interpolation change in in bit-stream metadata type, or CC stream?
843 //
845 // Get pointer to current CB Audio Frame
846 pAfCb = &pCb->afCb[pCb->afRdIdx];
848 // Cache invalidate CB AF
849 Cache_inv(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
850 Cache_wait();
852 // Read CB AF information updated by decoder
853 pAfRd->sampleDecode = pAfCb->sampleDecode;
854 PAF_PROCESS_COPY(pAfRd->sampleProcess, pAfCb->sampleProcess);
855 pAfRd->sampleRate = pAfCb->sampleRate;
856 pAfRd->channelConfigurationRequest = pAfCb->channelConfigurationRequest;
857 pAfRd->channelConfigurationStream = pAfCb->channelConfigurationStream;
858 // Read CB AF bit-stream metadata information updated by decoder
859 pAfRd->bsMetadata_type = pAfCb->bsMetadata_type; /* non zero if private metadata is attached. */
860 pAfRd->pafBsMetadataUpdate = pAfCb->pafBsMetadataUpdate; /* indicates whether bit-stream metadata update */
861 pAfRd->bsMetadata_offset = pAfCb->bsMetadata_offset; /* offset into audio frame for change in bsMetadata_type field */
863 #ifdef DTS_BUILD
864 pAfRd->mode = pAfCb->mode; /* mode is used in DTSX to pass info to PARMA */
865 pAfRd->numChansUsedForMetadata = pAfCb->numChansUsedForMetadata; /* if metadata is used in DTSX */
866 pAfRd->pafBsFixedData = pAfCb->pafBsFixedData; /* if true, do not convert float to fixed in DTSX metadata transfer */
867 pAfRd->root = pAfCb->root; /* used for channel MASK in DTSX. BAD IDEA, need fix */
868 pAfRd->resetCount = pAfCb->resetCount; /* used for communication between DTSX and PARMA */
870 #endif
871 // Compute stream mask for current CB AF.
872 // Mask indicates which channels are present in AF.
873 // Mask needed for cache invalidate and read of PCM samples in AF.
874 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfCb->channelConfigurationStream);
876 // Cache invalidate CB AF samsiz (volume scaling exponent) array
877 Cache_inv(pAfCb->data.samsiz, pCb->maxAFChanNum*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
878 Cache_wait();
880 // Read CB AF samsiz array
881 for (i = 0; i < pCb->maxAFChanNum; i++)
882 {
883 #ifndef DTS_BUILD
884 if ((streamMask >> i) & 0x1)
885 #endif
886 {//DTSX needs up to 16 channels to transfer metadata.
887 pAfRd->data.samsiz[i] = pAfCb->data.samsiz[i];
888 }
889 }
891 // FL: brute force clear of Read AF PCM data
892 // Reset Read AF PCM data
893 //for (i = 0; i < pCb->maxAFChanNum; i++)
894 //{
895 // if ((streamMask >> i) & 0x1)
896 // {
897 // memset(pAfRd->data.sample[i], 0, pCb->strFrameLen);
898 // }
899 //}
901 // FL: This brute force approach shouldn't be necessary if
902 // decoders properly set, and downstream components
903 // properly use, number of private metadata in frame
904 // Reset Read AF metadata
905 for (i = 0; i < PAF_MAX_NUM_PRIVATE_MD; i++)
906 {
907 pAfRd->pafPrivateMetadata[i].offset = 0;
908 pAfRd->pafPrivateMetadata[i].size = 0;
909 }
911 totNumSampsRd = 0; // init total number of samples read from CB
912 pcmWrtIdx = 0; // init Read AF PCM write index
913 prvMdWrtIdx = 0; // init Read AF metadata write index
914 while ((totNumSampsRd < pCb->strFrameLen) && (pCb->numAfCb > 0))
915 {
916 // Compute how many PCM samples can be read from CB AF
917 // Number of samples left in current CB AF: pAfCb->sampleCount - pCb->pcmRdIdx
918 // Number of samples left to write to Read AF: pCb->strFrameLen - totNumSampsRd
919 numSampsRd = (pAfCb->sampleCount - pCb->pcmRdIdx) < (pCb->strFrameLen - totNumSampsRd) ?
920 (pAfCb->sampleCount - pCb->pcmRdIdx) : (pCb->strFrameLen - totNumSampsRd);
922 // Cache invalidate CB AF PCM sample channel pointers
923 Cache_inv(pAfCb->data.sample, pCb->maxAFChanNum*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
924 Cache_wait();
926 // Cache invalidate CB AF PCM samples
927 for (i = 0; i < pCb->maxAFChanNum; i++)
928 {
929 #ifndef DTS_BUILD
930 if ((streamMask >> i) & 0x1)
931 #endif
932 {//DTSX needs up to 16 channels to transfer metadata.
933 Cache_inv(&pAfCb->data.sample[i][pCb->pcmRdIdx], numSampsRd*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
934 }
935 }
936 Cache_wait();
938 // Read PCM samples from CB AF
939 for (i = 0; i < pCb->maxAFChanNum; i++)
940 {
941 #ifndef DTS_BUILD
942 if ((streamMask >> i) & 0x1)
943 #endif
944 {//DTSX needs up to 16 channels to transfer metadata.
945 for (j = 0; j < numSampsRd; j++)
946 {
947 pAfRd->data.sample[i][pcmWrtIdx+j] = pAfCb->data.sample[i][pCb->pcmRdIdx+j];
948 }
949 }
950 }
952 // Cache invalidate CB AF unused metadata
953 for (i = pCb->prvMdRdIdx; i < pAfCb->numPrivateMetadata; i++)
954 {
955 Cache_inv(pAfCb->pafPrivateMetadata[i].pMdBuf, pAfCb->pafPrivateMetadata[i].size, Cache_Type_ALLD, 0); // only update metadata package size
956 }
957 Cache_wait();
959 // Read CB AF metadata
960 while (((pCb->prvMdRdIdx < pAfCb->numPrivateMetadata) &&
961 (pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].offset >= pCb->pcmRdIdx) &&
962 (pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].offset < (pCb->pcmRdIdx + numSampsRd)) &&
963 (pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].size)) &&
964 (prvMdWrtIdx < PAF_MAX_NUM_PRIVATE_MD))
965 {
966 // Write Read AF metadata offset.
967 // Compute relative offset of PCM samples being read from CB AF.
968 // Compute absolute offset of PCM samples written to Read AF by
969 // adding relative offset to Read AF PCM write index.
970 pAfRd->pafPrivateMetadata[prvMdWrtIdx].offset =
971 (pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].offset - pCb->pcmRdIdx) + // offset relative to samples being read from CB AF
972 pcmWrtIdx; // absolute offset into samples being written to read AF
973 // Write Read AF metadata size
974 pAfRd->pafPrivateMetadata[prvMdWrtIdx].size = pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].size;
975 // Write Read AF metadata payload
976 memcpy(pAfRd->pafPrivateMetadata[prvMdWrtIdx].pMdBuf, pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].pMdBuf, pAfCb->pafPrivateMetadata[pCb->prvMdRdIdx].size);
978 pCb->prvMdRdIdx++; // update CB metadata read index
979 prvMdWrtIdx++; // update CB metadata write index
980 }
982 // Update CB control
983 pCb->pcmRdIdx += numSampsRd; // update PCM read index
984 if (pCb->pcmRdIdx >= pAfCb->sampleCount)
985 {
986 // Finished reading PCM samples from current CB AF.
987 // Move to next AF in CB.
989 // Update audio frame read index.
990 // Wrap index if required.
991 pCb->afRdIdx++;
992 if (pCb->afRdIdx >= pCb->maxNumAfCb)
993 {
994 pCb->afRdIdx = 0;
995 }
997 // Reset PCM read index
998 pCb->pcmRdIdx = 0;
999 // Reset metadata read index
1000 pCb->prvMdRdIdx = 0;
1002 // Update number of audio frames in circular buffer
1003 pCb->numAfCb--;
1004 }
1006 // Update PCM write index
1007 pcmWrtIdx += numSampsRd;
1009 // Update total number of samples read
1010 totNumSampsRd += numSampsRd;
1012 if (totNumSampsRd < pCb->strFrameLen)
1013 {
1014 //
1015 // Need to read another AF from CB to obtain all PCM/metadata for Read AF
1016 //
1018 // Get pointer to current CB Audio Frame
1019 pAfCb = &pCb->afCb[pCb->afRdIdx];
1021 // Cache invalidate CB AF
1022 Cache_inv(pAfCb, sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
1023 Cache_wait();
1024 }
1025 }
1027 pAfRd->sampleCount = totNumSampsRd; // write Read AF sample count
1028 pAfRd->numPrivateMetadata = prvMdWrtIdx; // write Read AF number of metadata
1030 pCb->numPcmSampsPerCh -= totNumSampsRd; // update PCM samples per channel
1032 if (totNumSampsRd < pCb->strFrameLen)
1033 {
1034 // Clear remaining Read AF PCM samples
1035 for (i = 0; i < pCb->maxAFChanNum; i++)
1036 {
1037 #ifndef DTS_BUILD
1038 if ((streamMask >> i) & 0x1)
1039 #endif
1040 {//DTSX needs up to 16 channels to transfer metadata.
1041 memset(&pAfRd->data.sample[i][pcmWrtIdx], 0, (pCb->strFrameLen-totNumSampsRd));
1042 }
1043 }
1045 if (pCb->writerActiveFlag == 1)
1046 {
1047 //
1048 // UNDerflow,
1049 // read stopped due to insufficient PCM samples in CB to fill Read AF
1050 //
1052 //
1053 // Increment underflow count
1054 //
1055 pCb->errPcmUndCnt++;
1057 // Mute output on underflow
1058 cbReadMuteWithLastAfInfo(pCb, pAfRd);
1060 #if 0 // (***) FL: shows timing of CB underflow
1061 // debug
1062 {
1063 static Uint8 toggleState = 0;
1064 if (toggleState == 0)
1065 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
1066 else
1067 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
1068 toggleState = ~(toggleState);
1069 }
1070 #endif
1072 #ifdef CB_RW_OP_CAP_PP // debug
1073 if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
1074 {
1075 if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
1076 {
1077 // log sample count
1078 pCb->cb_samples_op[pCb->cb_opCnt] = 0; // due to underflow
1079 pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_R;
1080 // log idxs
1081 pCb->cb_afRdIdx[pCb->cb_opCnt] = pCb->afRdIdx;
1082 pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
1083 pCb->cb_numAfCb[pCb->cb_opCnt] = pCb->numAfCb; // numAfCb might not be pointing to this instance
1084 pCb->cb_opCnt++;
1085 }
1086 }
1087 #endif
1089 // Write back circular buffer configuration.
1090 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1091 Cache_wait();
1093 // Leave the gate
1094 GateMP_leave(gateHandle, key);
1096 return ASP_DECOP_CB_PCM_READ_UNDERFLOW;
1097 }
1098 }
1100 // Read AF complete, update Last CB AF Info
1101 cbUpdateLastAfInfo(pCb, pAfRd);
1103 #if 0 // (***) FL: shows timing of successful CB read
1104 {
1105 static Uint8 toggleState = 0;
1106 if (toggleState == 0)
1107 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
1108 else
1109 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
1110 toggleState = ~(toggleState);
1111 }
1112 #endif
1114 #ifdef CB_RW_OP_CAP_PP // debug
1115 if (pCb->cb_opCnt < CB_OP_COUNT_MAX)
1116 {
1117 if ((pCb->cb_samples_op != NULL) && (pCb->cb_op_owner != NULL))
1118 {
1119 // log sample count
1120 pCb->cb_samples_op[pCb->cb_opCnt] = pAfRd->sampleCount;
1121 pCb->cb_op_owner[pCb->cb_opCnt] = CB_OP_R;
1122 // log idxs
1123 pCb->cb_afRdIdx[pCb->cb_opCnt] = (pCb->pcmRdIdx == 0) ? (pCb->afRdIdx-1) : (pCb->afRdIdx);
1124 pCb->cb_afWrtIdx[pCb->cb_opCnt] = pCb->afWrtIdx;
1125 pCb->cb_numAfCb[pCb->cb_opCnt] = (pCb->pcmRdIdx == 0) ? (pCb->numAfCb+1) : (pCb->numAfCb); // numAfCb might not be pointing to this instance
1126 pCb->cb_opCnt++;
1127 }
1128 }
1129 #endif
1130 }
1132 #if 0
1133 if (pCb->drainFlag == 1)
1134 {
1135 //
1136 // Writer inactive, but remaining frames in circular buffer.
1137 // Update drain flag.
1138 //
1139 if (pCb->numAfCb <= 0)
1140 {
1141 pCb->drainFlag = 0;
1142 }
1143 }
1144 #endif
1146 // Write back circular buffer configuration.
1147 // NOTE: Probably only a subset of this information needs to be updated.
1148 Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1149 Cache_wait();
1151 // Leave the gate
1152 GateMP_leave(gateHandle, key);
1154 return ASP_DECOP_CB_SOK;
1155 }
1157 #if 0
1158 // Generate mute AF on circular buffer read
1159 static Void cbReadAfMute(
1160 PAF_AudioFrame *pAfRd, // audio frame into which to read
1161 Int16 strFrameLen // stream frame length (output transaction size)
1162 )
1163 {
1164 PAF_ChannelMask_HD streamMask;
1165 Int8 i;
1167 pAfRd->sampleDecode = PAF_SOURCE_PCM;
1168 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
1169 pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
1170 pAfRd->sampleCount = strFrameLen;
1171 pAfRd->channelConfigurationRequest.full = 0;
1172 pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
1173 pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
1174 pAfRd->channelConfigurationStream.full = 0;
1175 pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
1176 pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
1178 // compute stream mask
1179 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
1180 // Clear PCM data
1181 for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
1182 {
1183 #ifndef DTS_BUILD
1184 if ((streamMask >> i) & 0x1)
1185 #endif
1186 {//DTSX needs up to 16 channels to transfer metadata.
1187 memset(pAfRd->data.sample[i], 0, strFrameLen*sizeof(PAF_AudioData));
1188 }
1189 pAfRd->data.samsiz[i] = 0;
1190 }
1191 // write metadata information updated by decoder
1192 pAfRd->bsMetadata_type = PAF_bsMetadata_channelData; /* non zero if metadata is attached. */
1193 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
1194 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
1195 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1196 }
1197 #endif
1199 #if 0 // FL: unused
1200 // Init last audio frame configuration info
1201 static Void cbInitLastAfInfo(
1202 PAF_AudioFrame *pAfRd // last audio frame stored in CB instance
1203 )
1204 {
1205 pAfRd->sampleDecode = PAF_SOURCE_PCM;
1206 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
1207 pAfRd->sampleRate = PAF_SAMPLERATE_48000HZ;
1208 pAfRd->sampleCount = DEF_DEC_OP_FRAME_LEN;
1209 pAfRd->channelConfigurationRequest.full = 0;
1210 pAfRd->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
1211 pAfRd->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
1212 pAfRd->channelConfigurationStream.full = 0;
1213 pAfRd->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
1214 pAfRd->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
1216 pAfRd->bsMetadata_type = PAF_bsMetadata_none; /* non zero if metadata is attached. */
1217 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
1218 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
1219 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1220 }
1221 #endif
1223 // Update last audio frame configuration info
1224 static Void cbUpdateLastAfInfo(
1225 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
1226 PAF_AudioFrame *pAfUpd // audio frame used for update
1227 )
1228 {
1229 // FL: full copy shouldn't be necessary
1230 // Note currently (data.nChannels, data.nSamples)=(32,256) is fixed in ASOT stream AF.
1231 // There parameters aren't copied from CB on CB read.
1232 //memcpy (&pCb->lastAf, pAfUpd, sizeof(PAF_AudioFrame));
1234 // These are parameters used in cbReadMuteWithLastAfInfo()
1235 pCb->lastAf.sampleDecode = pAfUpd->sampleDecode;
1236 pCb->lastAf.sampleRate = pAfUpd->sampleRate;
1237 pCb->lastAf.channelConfigurationRequest.full = pAfUpd->channelConfigurationRequest.full;
1238 pCb->lastAf.channelConfigurationStream.full = pAfUpd->channelConfigurationStream.full;
1239 }
1241 // Generate mute AF on circular buffer read using the last AF configuration info
1242 static Void cbReadMuteWithLastAfInfo(
1243 PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer control
1244 PAF_AudioFrame *pAfRd // audio frame into which to read
1245 )
1246 {
1247 PAF_ChannelMask_HD streamMask;
1248 Int8 i;
1250 pAfRd->sampleDecode = pCb->lastAf.sampleDecode;
1251 PAF_PROCESS_ZERO(pAfRd->sampleProcess);
1252 pAfRd->sampleRate = pCb->lastAf.sampleRate;
1253 pAfRd->sampleCount = pCb->strFrameLen;
1254 pAfRd->channelConfigurationRequest.full = pCb->lastAf.channelConfigurationRequest.full;
1255 //pAfRd->channelConfigurationRequest.part.sat = pCb->lastAf.channelConfigurationRequest.part.sat; // FL: not necessary since full in union already copied
1256 //pAfRd->channelConfigurationRequest.part.sub = pCb->lastAf.channelConfigurationRequest.part.sub;
1257 pAfRd->channelConfigurationStream.full = pCb->lastAf.channelConfigurationStream.full;
1258 //pAfRd->channelConfigurationStream.part.sat = pCb->lastAf.channelConfigurationStream.part.sat;
1259 //pAfRd->channelConfigurationStream.part.sub = pCb->lastAf.channelConfigurationStream.part.sub;
1261 // compute stream mask
1262 streamMask = pAfRd->fxns->channelMask(pAfRd, pAfRd->channelConfigurationStream);
1263 // Clear PCM data
1264 for (i = 0; i < ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
1265 {
1266 #ifndef DTS_BUILD
1267 if ((streamMask >> i) & 0x1)
1268 #endif
1269 {//DTSX needs up to 16 channels to transfer metadata.
1270 memset(pAfRd->data.sample[i], 0, pAfRd->sampleCount*sizeof(PAF_AudioData));
1271 }
1272 pAfRd->data.samsiz[i] = 0;
1273 }
1274 pAfRd->bsMetadata_type = PAF_bsMetadata_none; /* non zero if metadata is attached. */
1275 pAfRd->pafBsMetadataUpdate = 0; /* indicates whether bit-stream metadata update */
1276 pAfRd->numPrivateMetadata = 0; /* number of valid private metadata (0 or 1 if metadata filtering enabled) */
1277 pAfRd->bsMetadata_offset = 0; /* offset into audio frame for change in bsMetadata_type field */
1278 #ifdef DTS_BUILD
1279 pAfRd->mode = 0; /* mode used by PARMA */
1280 pAfRd->numChansUsedForMetadata = 15; /* constant of 15 */
1281 pAfRd->pafBsFixedData = TRUE; /* if true, do not convert float to fixed in DTSX metadata transfer */
1282 pAfRd->root = 0x1BF; /* used for channel MASK in DTSX. 0x1BF = 7.1 as defined in dtshd_dec_api_common.h */
1283 pAfRd->resetCount = 0; /* used for communication between DTSX and PARMA */
1284 #endif
1285 }
1287 // Check circular buffer drain state
1288 Int cbCheckDrainState(
1289 PAF_AST_DecOpCircBufCtl *pCbCtl, // decoder output circular buffer control
1290 Int8 cbIdx, // decoder output circular buffer index, or indicator combined drain state desired
1291 Int8 *pDrainedFlag // output drain state indicator (combined or for selected circular buffer)
1292 )
1293 {
1294 IArg key;
1295 GateMP_Handle gateHandle;
1296 PAF_AST_DecOpCircBuf *pCb;
1297 Int8 drainedFlag;
1298 Int8 i;
1300 // Get gate handle
1301 gateHandle = pCbCtl->gateHandle;
1302 // Enter gate
1303 key = GateMP_enter(gateHandle);
1305 if (cbIdx != ASP_DECOP_CHECK_DRAINSTATE_ALL)
1306 {
1307 //
1308 // Check drain state for selected circular buffer
1309 //
1311 // Get circular buffer base pointer
1312 pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
1314 // Invalidate circular buffer configuration
1315 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1316 Cache_wait();
1318 drainedFlag = !pCb->writerActiveFlag && !pCb->drainFlag;
1319 }
1320 else
1321 {
1322 //
1323 // Check combined drain state for all circular buffers.
1324 // Combined drain state is logical AND of drain state for all circular buffers.
1325 //
1327 drainedFlag = 1; // init combined drained flag to TRUE
1328 for (i = 0; i < pCbCtl->numDecOpCb; i++)
1329 {
1330 // Get circular buffer base pointer
1331 pCb = &((*pCbCtl->pXDecOpCb)[i]);
1333 // Invalidate circular buffer configuration
1334 Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
1335 Cache_wait();
1337 // Update combined drain state
1338 drainedFlag = drainedFlag && (!pCb->writerActiveFlag && !pCb->drainFlag);
1339 }
1340 }
1342 *pDrainedFlag = drainedFlag;
1344 // Leave the gate
1345 GateMP_leave(gateHandle, key);
1347 return ASP_DECOP_CB_SOK;
1348 }