ee8ecf5e1315a66235041875a80a2b3fd30a959a
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_arm / framework / audioStreamDecodeProc.c
1 /*
2 * ======== audioStreamDecodeProc.c ========
3 */
5 #include <xdc/cfg/global.h>
6 #include <xdc/runtime/Error.h>
7 #include <xdc/runtime/Log.h>
8 #include <xdc/runtime/Memory.h>
9 #include <ti/sysbios/BIOS.h>
10 #include <ti/sysbios/hal/Cache.h>
11 #include <ti/sysbios/knl/Task.h>
12 #include <ti/ipc/Ipc.h>
13 #include <ti/ipc/MessageQ.h>
14 #include <ti/ipc/MultiProc.h>
16 #include <acp_mds.h>
17 #include <pcm.h>
18 #include "audioStreamProc_params.h"
19 #include "audioStreamProc_patchs.h"
20 #include "audioStreamProc_config.h"
21 #include "paf_decOpCircBuf.h"
23 #include "common.h"
24 #include "aspMsg_common.h"
25 #include "aspMsg_slave.h"
27 #include "audioStreamProc_common.h"
28 #include "audioStreamDecodeProc.h"
30 // FL: debug
31 //#include "fwkSim.h"
32 #include "dbgCapAf.h"
33 #include "dbgDib.h"
36 //
37 // Decoder Definitions
38 //
39 #define decLinkInit pQ->i_decLinkInit
41 #define __TASK_NAME__ "TaskAsdp"
43 LINNO_DEFN(TaskAsdp); /* Line number macros */
44 ERRNO_DEFN(TaskAsdp); /* Error number macros */
46 extern struct {
47 Int size;
48 IALG_Status *pStatus[512];
49 } IACP_STD_BETA_TABLE;
51 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
52 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT;
54 // Global debug counters */
55 extern Uint32 gTaskAsdpCnt; // debug counter for ASDP task
57 PAF_AudioFrame *gpDecAudioFrame=NULL;
58 PAF_AudioData *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
59 PAF_AudioSize gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
60 PAF_AudioData *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
62 // Debug counters
63 UInt32 gSlaveStartErrCnt =0;
64 UInt32 gSlaveStartCnt =0;
65 UInt32 gSlaveSourceSelectCnt =0;
66 UInt32 gSlaveExitCnt =0;
67 UInt32 gSlaveDecExitCnt =0;
68 UInt32 gSlaveDecControlCnt =0;
69 UInt32 gSlaveDecActivateCnt =0;
70 UInt32 gSlaveDecResetCnt =0;
71 UInt32 gSlaveDecInfoCnt =0;
72 UInt32 gSlaveDecDecodeCnt =0;
73 UInt32 gSlaveDecDeactivateCnt =0;
76 /*
77 * ======== taskAsdpFxn ========
78 * Audio Stream Decode Processing task function
79 */
80 Void taskAsdpFxn(
81 // Int betaPrimeValue, // FL: revisit
82 const PAF_AST_Params *pP,
83 const PAF_AST_Patchs *pQ
84 )
85 {
86 Int as; /* Audio Stream Number (1, 2, etc.) */
87 Int z; /* input/encode/stream/decode/output counter */
88 Int i; /* phase */
89 Int zMD, zMS;
90 Bool done;
91 Bool decDone;
92 ALG_Handle alg[DECODEN_MAX];
93 ASP_Slave_Cmd slaveCmd;
94 Int sourceSelect;
95 DEC_Handle dec;
96 IALG_Cmd decCtrlCmd; // decoder control command
97 Int decCtrlRet; // decoder control return
98 Int errno; /* error number */
99 Int size;
100 Int argIdx;
101 // Decoder output circular buffer
102 PAF_DecodeOpCircBuf *pCb;
103 PAF_AudioFrame *pAfWrt;
104 Int cbErrno;
105 // Messaging
106 PAF_InpBufConfig *pIpBufConfig;
107 ASP_Msg *pAspMsg;
108 MessageQ_QueueId queId;
109 Int status;
110 Int zI;
113 Log_info0("Enter taskAsdpFxn()");
115 //
116 // Audio Framework Parameters & Patch (*pP, *pQ):
117 //
118 if (!pP)
119 {
120 TRACE_TERSE0("TaskAsdp: No Parameters defined. Exiting.");
121 LINNO_RPRT(TaskAsdp, -1);
122 return;
123 }
125 if (!pQ)
126 {
127 TRACE_TERSE0("TaskAsdp: No Patchs defined. Exiting.");
128 LINNO_RPRT(TaskAsdp, -1);
129 return;
130 }
132 // wait for initialization message from master
133 do {
134 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
135 //TRACE_TERSE1("Rx ASP message: status=%d", status);
136 //} while ((status != MessageQ_S_SUCCESS || (pAspMsg->cmd != ASP_SLAVE_START));
137 } while (status != MessageQ_S_SUCCESS);
138 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
139 (pAspMsg->cmd != ASP_SLAVE_START))
140 {
141 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
142 SW_BREAKPOINT;
143 }
144 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
145 gSlaveStartCnt++;
146 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
148 Cache_inv(&gPAF_AST_config, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
149 Cache_inv(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
150 Cache_wait();
151 if (!pC)
152 {
153 TRACE_TERSE0("TaskAsdp: No Configuration defined. Exiting.");
154 LINNO_RPRT(TaskAsdp, -1);
155 return;
156 }
158 // (***) FL: revisit
159 // invalidate Dec configuration
160 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
161 Cache_wait();
163 // (***) FL: revisit
164 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0); // invalidate entire beta table
165 Cache_wait();
167 // Audio Framework Configuration (*pC):
168 as = pC->as; // obtain audio stream number
170 //
171 // Initialize message log trace and line number reporting
172 //
173 for (z=STREAM1; z < STREAMN; z++)
174 {
175 TRACE_TERSE1("TaskAsdp: AS%d: initiated", as+z);
176 }
177 LINNO_RPRT(TaskAsdp, -1);
179 // Get decoder and stream index associated with the master input
180 zMD = pC->masterDec;
181 zMS = pC->masterStr;
183 //
184 // Initialize per parameterized phases.
185 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
186 // - Common: Common Algorithm Initialization
187 // - AlgKey: Dec/Enc chain to Array Initialization
188 // - Unused: (available)
189 //
190 LINNO_RPRT(TaskAsdp, -2);
191 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
192 {
193 Int linno;
194 if (pP->fxns->initPhase[i])
195 {
196 if ((linno = pP->fxns->initPhase[i](pP, pQ, pC)))
197 {
198 LINNO_RPRT(TaskAsdp, linno);
199 return;
200 }
201 }
202 else
203 {
204 TRACE_TERSE1("TaskAsdp: AS%d: initialization phase - null", as+zMS);
205 }
206 TRACE_TERSE2("TaskAsdp: AS%d: initialization phase - %d completed", as+zMS, i);
207 LINNO_RPRT(TaskAsdp, -i-3);
208 }
210 //
211 // End of Initialization -- final memory usage report.
212 //
213 if (pP->fxns->memStatusPrint)
214 {
215 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
216 }
218 // (***) FL: revisit
219 // write back Status structure addresses for Beta Units initialized on Slave
220 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
221 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
222 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
223 //Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
224 //Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
225 Cache_wait();
227 // (***) FL: revisit
228 // write back Status structures for Beta Units initialized on Slave
229 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
230 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
231 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
232 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
233 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
234 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
235 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
236 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
237 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
238 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
239 Cache_wait();
241 // (***) FL: revisit
242 // write back Dec configuration
243 Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
244 Cache_wait();
246 // Send initialization complete message to master
247 queId = MessageQ_getReplyQueue(pAspMsg);
248 pAspMsg->procId = hAspMsgSlave->slaveProcId;
249 pAspMsg->cmd = ASP_MASTER_START_DONE;
250 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
251 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
252 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
253 if (status != MessageQ_S_SUCCESS)
254 {
255 SW_BREAKPOINT;
256 }
258 done = FALSE;
259 while (done==FALSE)
260 {
261 // wait for source select message from master
262 do {
263 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
264 } while ((status < 0) || (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT));
265 if ((pAspMsg->procId != hAspMsgSlave->masterProcId) ||
266 (pAspMsg->cmd != ASP_SLAVE_DEC_SOURCE_SELECT))
267 {
268 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
269 SW_BREAKPOINT;
270 }
271 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
272 sourceSelect = *(Int32 *)&pAspMsg->buf[0];
273 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
274 TRACE_MSG1("sourceSelect=%d.", sourceSelect);
275 // send source select complete message to master
276 queId = MessageQ_getReplyQueue(pAspMsg);
277 pAspMsg->procId = hAspMsgSlave->slaveProcId;
278 pAspMsg->cmd = ASP_MASTER_DEC_SOURCE_SELECT_DONE;
279 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
280 gSlaveSourceSelectCnt++;
281 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
282 MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
284 for (z=DECODE1; z < DECODEN; z++)
285 {
286 alg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
287 }
288 alg[zMD] = pC->xDec[zMD].decAlg[sourceSelect];
290 // FL: debug, reset IB capture buffer
291 //capIbReset();
292 //Log_info0("capIbReset()");
293 // FL: debug, reset audio frame capture buffer
294 //capAfReset();
296 decDone = FALSE;
297 while (decDone==FALSE)
298 {
299 // wait for received message from master
300 do {
301 status = MessageQ_get(hAspMsgSlave->slaveQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
302 } while (status < 0);
303 if (pAspMsg->procId != hAspMsgSlave->masterProcId)
304 {
305 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
306 SW_BREAKPOINT;
307 }
308 hAspMsgSlave->masterMessageId = pAspMsg->messageId;
309 slaveCmd = pAspMsg->cmd;
310 TRACE_MSG3("Rx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
312 switch (slaveCmd)
313 {
314 case ASP_SLAVE_NULL:
315 case ASP_SLAVE_START:
316 gSlaveStartErrCnt++;
317 TRACE_TERSE1("ERROR: unexpected slaveCmd=%d", slaveCmd);
319 break;
321 case ASP_SLAVE_EXIT:
322 gSlaveExitCnt++;
323 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
325 decDone = TRUE;
326 done = TRUE;
327 break;
329 case ASP_SLAVE_DEC_EXIT:
330 gSlaveDecExitCnt++;
331 TRACE_TERSE1("slaveCmd=%d", slaveCmd);
333 // send dec exit complete message to master
334 queId = MessageQ_getReplyQueue(pAspMsg);
335 pAspMsg->procId = hAspMsgSlave->slaveProcId;
336 pAspMsg->cmd = ASP_MASTER_DEC_EXIT_DONE;
337 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
338 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
339 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
340 if (status != MessageQ_S_SUCCESS)
341 {
342 SW_BREAKPOINT;
343 }
345 decDone=TRUE;
346 break;
348 case ASP_SLAVE_DEC_CONTROL:
349 gSlaveDecControlCnt++;
350 // simulate dec control load
351 //simLoad(DEC_CONTROL_LOAD);
353 argIdx = 0; // get decIdx
354 z = *(Int32 *)&pAspMsg->buf[argIdx];
355 argIdx += sizeof(Int32);
356 decCtrlCmd = *(IALG_Cmd *)&pAspMsg->buf[argIdx]; // get decCtrlCmd
357 TRACE_MSG3("slaveCmd=%d, decIdx=%d, decCtrlCmd=%d", slaveCmd, z, decCtrlCmd);
359 decCtrlRet = alg[z]->fxns->algControl(alg[z], decCtrlCmd, NULL);
361 // send dec control complete message to master
362 queId = MessageQ_getReplyQueue(pAspMsg);
363 pAspMsg->procId = hAspMsgSlave->slaveProcId;
364 pAspMsg->cmd = ASP_MASTER_DEC_CONTROL_DONE;
365 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
366 argIdx = 0; // set decCtrlRet
367 *(Int32 *)&pAspMsg->buf[argIdx] = decCtrlRet;
368 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
369 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
370 if (status != MessageQ_S_SUCCESS)
371 {
372 SW_BREAKPOINT;
373 }
375 break;
377 case ASP_SLAVE_DEC_ACTIVATE:
378 gSlaveDecActivateCnt++;
379 // simulate dec activate load
380 //simLoad(DEC_ACTIVATE_LOAD);
382 // (***) FL: revisit
383 // invalidate Status structures for shared Beta Units
384 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
385 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
386 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
387 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
388 Cache_wait();
390 argIdx = 0; // get decIdx
391 z = *(Int32 *)&pAspMsg->buf[argIdx];
392 TRACE_MSG2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
394 if (alg[z]->fxns->algActivate)
395 {
396 alg[z]->fxns->algActivate(alg[z]);
397 }
399 // Start writes to circular buffer
400 pCb = &pC->xDec[z].decOpCb;
401 cbWriteStart(pCb);
402 // Reset audio frame
403 resetAf(pP, z, sourceSelect);
405 // send dec activate complete message to master
406 queId = MessageQ_getReplyQueue(pAspMsg);
407 pAspMsg->procId = hAspMsgSlave->slaveProcId;
408 pAspMsg->cmd = ASP_MASTER_DEC_ACTIVATE_DONE;
409 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
410 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
411 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
412 if (status != MessageQ_S_SUCCESS)
413 {
414 SW_BREAKPOINT;
415 }
417 break;
419 case ASP_SLAVE_DEC_RESET:
420 gSlaveDecResetCnt++;
421 // simulate dec reset load
422 //simLoad(DEC_RESET_LOAD);
424 argIdx = 0; // get decIdx
425 z = *(Int32 *)&pAspMsg->buf[argIdx];
426 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
428 dec = (DEC_Handle)alg[z];
429 errno = 0;
430 if (dec->fxns->reset)
431 {
432 errno = dec->fxns->reset(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
433 }
435 // (***) FL: revisit
436 // write back Status structures for shared Beta Units
437 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
438 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
439 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
440 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
441 Cache_wait();
443 // send dec reset complete message to master
444 queId = MessageQ_getReplyQueue(pAspMsg);
445 pAspMsg->procId = hAspMsgSlave->slaveProcId;
446 pAspMsg->cmd = ASP_MASTER_DEC_RESET_DONE;
447 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
448 argIdx = 0; // set decErrno
449 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
450 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
451 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
452 if (status != MessageQ_S_SUCCESS)
453 {
454 SW_BREAKPOINT;
455 }
457 break;
459 case ASP_SLAVE_DEC_INFO:
460 gSlaveDecInfoCnt++;
461 // simulate dec info load
462 //simLoad(DEC_INFO_LOAD);
464 argIdx = 0; // get decIdx
465 z = *(Int32 *)&pAspMsg->buf[argIdx];
466 TRACE_TERSE2("slaveCmd=%d,decIdx=%d", slaveCmd, z);
467 // Get input associated w/ decoder
468 zI = pP->inputsFromDecodes[z];
470 // (***) FL: revisit
471 // invalidate Inp configuration
472 Cache_inv(&gPAF_AST_config.xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
473 // invalidate input data
474 pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
475 size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
476 if (sourceSelect == PAF_SOURCE_PCM)
477 {
478 size *= pIpBufConfig->stride;
479 }
480 Cache_inv((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
481 // invalidate Dec configuration
482 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
483 // status for selected decoder should be invalidated
484 Cache_wait();
486 dec = (DEC_Handle)alg[z];
487 errno = 0;
488 if (dec->fxns->info)
489 {
490 errno = dec->fxns->info(dec, NULL, &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus);
491 }
493 // write back Dec configuration
494 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
495 Cache_wait();
497 // Re-initialize audio frame if decoder is disabled or
498 // doesn't have a valid input
499 if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
500 {
501 pP->fxns->initFrame1(pP, pQ, pC, z, 0);
502 }
504 // send dec info complete message to master
505 queId = MessageQ_getReplyQueue(pAspMsg);
506 pAspMsg->procId = hAspMsgSlave->slaveProcId;
507 pAspMsg->cmd = ASP_MASTER_DEC_INFO_DONE;
508 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
509 argIdx = 0; // set decErrno
510 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
511 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
512 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
513 if (status != MessageQ_S_SUCCESS)
514 {
515 SW_BREAKPOINT;
516 }
518 break;
520 case ASP_SLAVE_DEC_DECODE:
521 gSlaveDecDecodeCnt++;
522 // simulate dec info load
523 //simLoad(DEC_DECODE_LOAD);
525 argIdx = 0; // get decIdx
526 z = *(Int32 *)&pAspMsg->buf[argIdx];
527 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
528 // Get input associated w/ decoder
529 zI = pP->inputsFromDecodes[z];
531 // Reset AF samsiz
532 resetAfSamsiz(z);
534 // invalidate Dec configuration
535 Cache_inv(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
536 Cache_wait();
537 //TRACE_TERSE0("Dec:cache wb done");
539 dec = (DEC_Handle)alg[z];
540 //TRACE_TERSE1("Dec:dec handle=0x%04x", (IArg)dec);
542 errno = 0;
543 cbErrno = 0;
544 if (dec->fxns->decode)
545 {
546 // FL: debug, capture input buffer
547 //capIb(pC->xInp[z].pInpBuf);
549 errno = dec->fxns->decode(dec, NULL, &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct);
550 if (errno < 0)
551 {
552 SW_BREAKPOINT;
553 }
554 //TRACE_TERSE0("Dec:decode done");
556 // copy decoder output to decoder output circular buffers
557 pCb = &pC->xDec[z].decOpCb;
558 //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
560 pAfWrt = pC->xDec[z].decodeOutStruct.pAudioFrame;
561 //TRACE_TERSE1("Dec:pAfWrt=0x%04x", (IArg)pAfWrt);
562 //TRACE_TERSE1("nSamples=%d",pAfWrt->data.nSamples);
564 // FL: debug, capture audio frame
565 //if (capAfWrite(pAfWrt, PAF_CNTR) != CAP_AF_SOK)
566 //{
567 // Log_info0("capAfWrite() error");
568 //}
570 cbErrno = cbWriteAf(pCb, pAfWrt);
571 if (cbErrno < 0)
572 {
573 SW_BREAKPOINT;
574 }
575 //TRACE_TERSE0("Dec:cbWriteAf() complete");
577 // FL: debug, log circular buffer control variables
578 cbLog(pCb, 0);
579 }
581 // write back Dec configuration
582 Cache_wb(&gPAF_AST_config.xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
583 Cache_wait();
585 // Re-initialize audio frame if decoder is disabled or
586 // doesn't have a valid input
587 if (!pC->xDec[z].decodeStatus.mode || !pC->xInp[zI].hRxSio)
588 {
589 pP->fxns->initFrame1(pP, pQ, pC, z, 0);
590 }
592 // send dec info complete message to master
593 queId = MessageQ_getReplyQueue(pAspMsg);
594 pAspMsg->procId = hAspMsgSlave->slaveProcId;
595 pAspMsg->cmd = ASP_MASTER_DEC_DECODE_DONE;
596 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
597 argIdx = 0; // set decErrno
598 *(Int32 *)&pAspMsg->buf[argIdx] = errno;
599 argIdx += sizeof(Int32); // set cbErrno
600 *(Int32 *)&pAspMsg->buf[argIdx] = cbErrno;
601 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
602 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
603 if (status != MessageQ_S_SUCCESS)
604 {
605 SW_BREAKPOINT;
606 }
608 break;
610 case ASP_SLAVE_DEC_DEACTIVATE:
611 gSlaveDecDeactivateCnt++;
612 // simulate dec info load
613 //simLoad(DEC_DEACTIVATE_LOAD);
615 argIdx = 0; // get decIdx
616 z = *(Int32 *)&pAspMsg->buf[argIdx];
617 TRACE_TERSE2("slaveCmd=%d, decIdx=%d", slaveCmd, z);
619 if (alg[z]->fxns->algDeactivate)
620 {
621 alg[z]->fxns->algDeactivate(alg[z]);
622 }
624 // Stop writes to circular buffer
625 pCb = &pC->xDec[z].decOpCb;
626 cbWriteStop(pCb);
628 // send dec deactivate complete message to master
629 queId = MessageQ_getReplyQueue(pAspMsg);
630 pAspMsg->procId = hAspMsgSlave->slaveProcId;
631 pAspMsg->cmd = ASP_MASTER_DEC_DEACTIVATE_DONE;
632 pAspMsg->messageId = hAspMsgSlave->masterMessageId | ((UInt32)1<<31);
633 TRACE_MSG3("Tx ASP message, procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
634 status = MessageQ_put(queId, (MessageQ_Msg)pAspMsg); /* send message back */
635 if (status != MessageQ_S_SUCCESS)
636 {
637 SW_BREAKPOINT;
638 }
640 break;
642 default:
643 TRACE_TERSE1("ERROR: invalid slaveCmd=%d", slaveCmd);
644 break;
645 }
646 }
647 }
649 Log_info0("exit taskAsdpFxn()");
650 }
653 // -----------------------------------------------------------------------------
654 // AST Initialization Function - Memory Allocation
655 //
656 // Name: PAF_AST_initPhaseMalloc
657 // Purpose: Audio Stream Task Function for initialization of data pointers
658 // by allocation of memory.
659 // From: audioStream1Task or equivalent
660 // Uses: See code.
661 // States: x
662 // Return: 0 on success.
663 // Source code line number on MEM_calloc failure.
664 // Trace: Message Log "trace" in Debug Project Configuration reports:
665 // * State information as per parent.
666 // * Memory allocation errors.
667 //
668 Int
669 PAF_ASDT_initPhaseMalloc(
670 const PAF_AST_Params *pP,
671 const PAF_AST_Patchs *pQ,
672 PAF_AST_Config *pC
673 )
674 {
675 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
676 Int zMS = pC->masterStr;
677 Error_Block eb;
679 TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: initialization phase - memory allocation", as+zMS);
681 // Initialize error block
682 Error_init(&eb);
684 if (!(gpDecAudioFrame = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL1,
685 DECODEN * sizeof (PAF_AudioFrame), 4, &eb)))
686 {
687 TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: Memory_calloc failed", as+zMS);
688 SW_BREAKPOINT;
689 return __LINE__;
690 }
691 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (gpAudioFrameSlave) %d bytes from space %d at 0x%x.",
692 DECODEN * sizeof (PAF_AudioFrame),
693 HEAP_ID_INTERNAL1, (IArg)gpDecAudioFrame);
695 TRACE_TERSE1("PAF_AST_initPhaseMallocSlave: AS%d: initialization phase - memory allocation complete.", as+zMS);
696 return 0;
697 } //PAF_ASDT_initPhaseMalloc
699 // -----------------------------------------------------------------------------
700 // AST Initialization Function - Memory Initialization from Configuration
701 //
702 // Name: PAF_AST_initPhaseConfig
703 // Purpose: Audio Stream Task Function for initialization of data values
704 // from parameters.
705 // From: audioStream1Task or equivalent
706 // Uses: See code.
707 // States: x
708 // Return: 0 on success.
709 // Other as per initFrame0 and initFrame1.
710 // Trace: Message Log "trace" in Debug Project Configuration reports:
711 // * State information as per parent.
712 //
714 Int
715 PAF_ASDT_initPhaseConfig(
716 const PAF_AST_Params *pP,
717 const PAF_AST_Patchs *pQ,
718 PAF_AST_Config *pC
719 )
720 {
721 Int z;
723 // overwrite pointer to audio frame in framework decode control
724 for (z=DECODE1; z < DECODEN; z++)
725 {
726 //Int zS = pP->streamsFromDecodes[z]; // FL: slave
727 //pC->xDec[z].decodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame; // FL: slave
728 //pC->xDec[z].decodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame; // FL: slave
729 pC->xDec[z].decodeControl.pAudioFrame = &gpDecAudioFrame[z];
730 pC->xDec[z].decodeInStruct.pAudioFrame = &gpDecAudioFrame[z];
731 pP->fxns->initFrame0(pP, pQ, pC, z);
732 }
734 return 0;
735 } //PAF_ASDT_initPhaseConfig
737 // -----------------------------------------------------------------------------
738 // AST Initialization Function - ACP Algorithm Instantiation
739 //
740 // Name: PAF_AST_initPhaseAcpAlg
741 // Purpose: Audio Stream Task Function for initialization of ACP by
742 // instantiation of the algorithm.
743 // From: audioStream1Task or equivalent
744 // Uses: See code.
745 // States: x
746 // Return: 0 on success.
747 // Source code line number on ACP Algorithm creation failure.
748 // Trace: Message Log "trace" in Debug Project Configuration reports:
749 // * State information as per parent.
750 // * Memory allocation errors.
751 //
752 Int
753 PAF_ASDT_initPhaseAcpAlg(
754 const PAF_AST_Params *pP,
755 const PAF_AST_Patchs *pQ,
756 PAF_AST_Config *pC
757 )
758 {
759 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
760 Int z; /* input/encode/stream/decode/output */
761 /* counter */
762 Int betaPrimeOffset;
763 ACP_Handle acp;
764 Int zMS = pC->masterStr;
765 Int zS; //, zX;
767 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
769 ACP_MDS_init();
771 if (!(acp = (ACP_Handle )ACP_MDS_create (NULL)))
772 {
773 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
774 return __LINE__;
775 }
776 pC->acpSlave = acp;
778 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle)acp,
779 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
781 #if 0 // FL: master
782 for (z=INPUT1; z < INPUTN; z++)
783 {
784 zS = z;
785 for (zX = DECODE1; zX < DECODEN; zX++)
786 {
787 if (pP->inputsFromDecodes[zX] == z)
788 {
789 zS = pP->streamsFromDecodes[zX];
790 break;
791 }
792 }
793 acp->fxns->attach(acp, ACP_SERIES_STD,
794 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
795 (IALG_Status *)&pC->xInp[z].inpBufStatus);
796 /* Ignore errors, not reported. */
797 }
798 #endif
800 for (z=DECODE1; z < DECODEN; z++)
801 {
802 zS = pP->streamsFromDecodes[z];
803 acp->fxns->attach(acp, ACP_SERIES_STD,
804 STD_BETA_DECODE + betaPrimeOffset * (as-1+zS),
805 (IALG_Status *)&pC->xDec[z].decodeStatus);
806 /* Ignore errors, not reported. */
807 }
809 #if 0 // FL: master
810 for (z=ENCODE1; z < ENCODEN; z++)
811 {
812 zS = pP->streamsFromEncodes[z];
813 acp->fxns->attach(acp, ACP_SERIES_STD,
814 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
815 (IALG_Status *)&pC->xEnc[z].encodeStatus);
816 acp->fxns->attach(acp, ACP_SERIES_STD,
817 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
818 (IALG_Status *)&pC->xEnc[z].volumeStatus);
819 /* Ignore errors, not reported. */
820 }
821 #endif
823 #if 0 // FL: master
824 for (z=OUTPUT1; z < OUTPUTN; z++)
825 {
826 zS = z;
827 for (zX = ENCODE1; zX < ENCODEN; zX++)
828 {
829 if (pP->outputsFromEncodes[zX] == z)
830 {
831 zS = pP->streamsFromEncodes[zX];
832 break;
833 }
834 }
835 acp->fxns->attach(acp, ACP_SERIES_STD,
836 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
837 (IALG_Status *)&pC->xOut[z].outBufStatus);
838 /* Ignore errors, not reported. */
839 }
840 #endif
842 TRACE_TERSE1("PAF_ASDT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
844 return 0;
845 } //PAF_AST_initPhaseAcpAlg
847 // -----------------------------------------------------------------------------
848 // AST Initialization Function - Common Memory and Algorithms
849 //
850 // Name: PAF_AST_initPhaseCommon
851 // Purpose: Audio Stream Task Function for initialization of data pointers
852 // by allocation for common memory and by instantiation for
853 // algorithms.
854 // From: audioStream1Task or equivalent
855 // Uses: See code.
856 // States: x
857 // Return: 0 on success.
858 // Source code line number on PAF_ALG_alloc failure.
859 // Source code line number on PAF_ALG_mallocMemory failure.
860 // Source code line number on Decode Chain initialization failure.
861 // Source code line number on ASP Chain initialization failure.
862 // Source code line number on Encode Chain initialization failure.
863 // Trace: Message Log "trace" in Debug Project Configuration reports:
864 // * State information as per parent.
865 // * Memory allocation errors.
866 //
868 #include <pafsio_ialg.h>
870 Int
871 PAF_ASDT_initPhaseCommon(
872 const PAF_AST_Params *pP,
873 const PAF_AST_Patchs *pQ,
874 PAF_AST_Config *pC
875 )
876 {
877 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
878 Int z; /* stream counter */
879 //Int g; /* gear */
880 ACP_Handle acp = pC->acpSlave;
881 PAF_IALG_Config pafAlgConfig;
882 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
884 TRACE_TERSE0("PAF_AST_initPhaseCommonSlav: initialization phase - Common Algorithms");
886 //
887 // Determine memory needs and instantiate algorithms across audio streams
888 //
890 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_setup.");
891 PAF_ALG_setup(&pafAlgConfig,
892 HEAP_ID_INTERNAL, HEAP_INTERNAL,
893 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
894 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
895 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
896 HEAP_CLEAR);
898 if (pP->fxns->headerPrint)
899 pP->fxns->headerPrint();
901 for (z=STREAM1; z < STREAMN; z++)
902 {
903 //Int zD, zE, zX;
904 Int zD, zX;
906 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Common Algorithms", as+z);
908 //
909 // Determine common memory needs of Decode Algorithms
910 //
911 PAF_ALG_init (common[z], lengthof (common[z]), COMMONSPACE);
913 zD = -1;
914 for (zX = DECODE1; zX < DECODEN; zX++)
915 {
916 if (pP->streamsFromDecodes[zX] == z)
917 {
918 zD = zX;
919 break;
920 }
921 }
923 #if 0 // FL: master
924 zE = -1;
925 for (zX = ENCODE1; zX < ENCODEN; zX++)
926 {
927 if (pP->streamsFromEncodes[zX] == z)
928 {
929 zE = zX;
930 break;
931 }
932 }
933 #endif
935 if (zD >= 0)
936 {
937 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: calling PAF_ALG_ALLOC for decoder common[%d].", z);
938 if (PAF_ALG_ALLOC (decLinkInit[zD-DECODE1], common[z]))
939 {
940 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
941 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, common[z]->space);
943 SW_BREAKPOINT;
944 return __LINE__;
945 }
946 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
947 if(pP->fxns->allocPrint)
948 pP->fxns->allocPrint ((const PAF_ALG_AllocInit *)(decLinkInit[z-DECODE1]),sizeof (*(decLinkInit[z-DECODE1])), &pafAlgConfig);
949 }
951 #if 0 // FL: master
952 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
953 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC for stream common[%d].", (IArg)__FUNCTION__, __LINE__, z);
954 if (PAF_ALG_ALLOC (aspLinkInit[z-STREAM1][0], common[z]))
955 {
956 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
957 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
958 SW_BREAKPOINT;
959 return __LINE__;
960 }
961 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
962 if(pP->fxns->allocPrint)
963 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
964 #endif
966 #if 0 // FL: master
967 if (zE >= 0)
968 {
969 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC/ for encoder common[%d].", (IArg)__FUNCTION__, __LINE__, z);
970 if (PAF_ALG_ALLOC (encLinkInit[zE-ENCODE1], common[z]))
971 {
972 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed",
973 as+z, (IArg)__FUNCTION__, __LINE__);
974 SW_BREAKPOINT;
975 return __LINE__;
976 }
977 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
978 if(pP->fxns->allocPrint)
979 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
980 }
981 #endif
983 //
984 // Determine common memory needs of Logical IO drivers
985 //
987 #if 0 // FL: master
988 // really need to loop over all inputs for this stream using the tables
989 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
990 // patch, and not needed for FS11, since there is only one input.
991 if (INPUT1 <= z && z < INPUTN)
992 {
993 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: alloc inpLinkInit common[%d]", as+z, __LINE__, z);
994 if (PAF_ALG_ALLOC (inpLinkInit[z-INPUT1], common[z]))
995 {
996 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
997 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
998 SW_BREAKPOINT;
999 return __LINE__;
1000 }
1001 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1002 if(pP->fxns->allocPrint)
1003 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1004 }
1005 #endif
1007 #if 0 // FL: master
1008 if (OUTPUT1 <= z && z < OUTPUTN)
1009 {
1010 TRACE_TERSE3("%s.%d: calling PAF_ALG_ALLOC outLinkInit common[%d].", (IArg)__FUNCTION__, __LINE__, z);
1011 if (PAF_ALG_ALLOC (outLinkInit[z-OUTPUT1], common[z]))
1012 {
1013 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_alloc failed", as+z, (IArg)__FUNCTION__, __LINE__);
1014 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1015 SW_BREAKPOINT;
1016 return __LINE__;
1017 }
1018 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1019 if(pP->fxns->allocPrint)
1020 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1021 }
1022 #endif
1023 }
1024 {
1025 // Changes made to share scratch between zones
1026 // Assume maximum 3 zones and scratch common memory is at offset 0;
1027 int max=0;
1028 for (z=STREAM1; z < STREAMN; z++)
1029 {
1030 if (max<common[z][0].size)
1031 max=common[z][0].size;
1032 }
1033 common[STREAM1][0].size=max;
1034 for (z=STREAM1+1; z < STREAMN; z++)
1035 common[z][0].size=0;
1036 }
1038 //
1039 // Provide common memory needs of Decode Algorithms
1040 //
1041 for (z=STREAM1; z < STREAMN; z++)
1042 {
1043 //Int zD, zE, zX;
1044 Int zD, zX;
1046 zD = -1;
1047 for (zX = DECODE1; zX < DECODEN; zX++)
1048 {
1049 if (pP->streamsFromDecodes[zX] == z)
1050 {
1051 zD = zX;
1052 break;
1053 }
1054 }
1056 #if 0 // FL: master
1057 zE = -1;
1058 for (zX = ENCODE1; zX < ENCODEN; zX++)
1059 {
1060 if (pP->streamsFromEncodes[zX] == z)
1061 {
1062 zE = zX;
1063 break;
1064 }
1065 }
1066 #endif
1068 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1069 if (PAF_ALG_mallocMemory (common[z], &pafAlgConfig))
1070 {
1071 TRACE_TERSE3("AS%d: %s.%d: PAF_ALG_mallocMemory failed", as+z, (IArg)__FUNCTION__, __LINE__);
1072 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1073 SW_BREAKPOINT;
1074 return __LINE__;
1075 }
1076 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1077 // share zone0 scratch with all zones
1078 common[z][0].base=common[0][0].base;
1079 if (pP->fxns->commonPrint)
1080 pP->fxns->commonPrint (common[z], &pafAlgConfig);
1082 //
1083 // Instantiate Decode Algorithms
1084 //
1085 if (zD >= 0)
1086 {
1087 PAF_ASP_Chain *chain;
1088 TRACE_TERSE0("PAF_ASDT_initPhaseCommon: calling PAF_ASP_chainInit for decode.");
1089 chain =
1090 PAF_ASP_chainInit (&pC->xDec[zD].decChainData, pP->pChainFxns,
1091 HEAP_INTERNAL, as+z, acp, &trace,
1092 decLinkInit[zD-DECODE1], NULL, common[z], &pafAlgConfig);
1093 if (!chain)
1094 {
1095 TRACE_TERSE1("AS%d: Decode chain initialization failed", as+z);
1096 return __LINE__;
1097 }
1098 }
1100 #if 0 // FL: master
1101 pC->xStr[z].aspChain[0] = NULL;
1102 for (g=0; g < GEARS; g++)
1103 {
1104 PAF_ASP_Chain *chain;
1105 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for ASPs.", (IArg)__FUNCTION__, __LINE__);
1106 chain =
1107 PAF_ASP_chainInit (&pC->xStr[z].aspChainData[g], pP->pChainFxns,
1108 HEAP_INTERNAL, as+z, acp, &trace,
1109 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1110 if (! chain)
1111 {
1112 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1113 return __LINE__;
1114 }
1115 else
1116 pC->xStr[z].aspChain[g] = chain;
1117 }
1118 #endif
1120 #if 0 // FL: master
1121 if (zE >= 0)
1122 {
1123 PAF_ASP_Chain *chain;
1124 TRACE_TERSE2("%s.%d: calling PAF_ASP_chainInit for encode.", (IArg)__FUNCTION__, __LINE__);
1125 chain =
1126 PAF_ASP_chainInit (&pC->xEnc[zE].encChainData, pP->pChainFxns,
1127 HEAP_INTERNAL, as+z, acp, &trace,
1128 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1129 if (!chain)
1130 {
1131 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1132 return __LINE__;
1133 }
1134 }
1135 #endif
1137 #if 0 // FL: master
1138 //
1139 // Allocate non-common memories for Logical IO drivers
1140 // Since these structures are used at run-time we allocate from external memory
1141 if (INPUT1 <= z && z < INPUTN)
1142 {
1143 PAF_ASP_Chain *chain;
1144 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common input chain init for %d",
1145 as+z, __LINE__, z);
1146 chain = PAF_ASP_chainInit (&pC->xInp[z].inpChainData, pP->pChainFxns,
1147 HEAP_EXTERNAL, as+z, acp, &trace,
1148 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1149 if (!chain)
1150 {
1151 TRACE_TERSE1("AS%d: Input chain initialization failed", as+z);
1152 return __LINE__;
1153 }
1154 }
1155 #endif
1157 #if 0 // FL: master
1158 if (OUTPUT1 <= z && z < OUTPUTN)
1159 {
1160 PAF_ASP_Chain *chain;
1161 TRACE_TERSE3("AS%d: PAF_AST_initPhaseCommon.%d: non-common output chain init for %d",
1162 as+z, __LINE__, z);
1163 chain = PAF_ASP_chainInit (&pC->xOut[z].outChainData, pP->pChainFxns,
1164 HEAP_EXTERNAL, as+z, acp, &trace,
1165 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1166 if (!chain)
1167 {
1168 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1169 return __LINE__;
1170 }
1171 }
1172 #endif
1173 }
1174 TRACE_TERSE1("PAF_ASDT_initPhaseCommon: AS%d: Returning complete.", as+z);
1176 return 0;
1177 } //PAF_ASDT_initPhaseCommon
1179 // -----------------------------------------------------------------------------
1180 // AST Initialization Function - Algorithm Keys
1181 //
1182 // Name: PAF_AST_initPhaseAlgKey
1183 // Purpose: Audio Stream Task Function for initialization of data values
1184 // from parameters for Algorithm Keys.
1185 // From: audioStream1Task or equivalent
1186 // Uses: See code.
1187 // States: x
1188 // Return: 0.
1189 // Trace: Message Log "trace" in Debug Project Configuration reports:
1190 // * State information as per parent.
1191 //
1192 // .............................................................................
1193 Int
1194 PAF_ASDT_initPhaseAlgKey(
1195 const PAF_AST_Params *pP,
1196 const PAF_AST_Patchs *pQ,
1197 PAF_AST_Config *pC
1198 )
1199 {
1200 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1201 Int z; /* decode/encode counter */
1202 Int s; /* key number */
1203 PAF_ASP_Link *that;
1205 (void)as; // clear warning.
1207 TRACE_VERBOSE1("PAF_ASDT_initPhaseCommon: AS%d: initialization phase - Algorithm Keys", as);
1209 for (z=DECODE1; z < DECODEN; z++)
1210 {
1211 for (s=0; s < pP->pDecAlgKey->length; s++)
1212 {
1213 if ((pP->pDecAlgKey->code[s].full != 0)
1214 && (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1215 {
1216 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1217 /* Cast in interface, for now --Kurt */
1218 }
1219 else
1220 pC->xDec[z].decAlg[s] = NULL;
1221 }
1222 }
1224 #if 0 // FL: master
1225 for (z=ENCODE1; z < ENCODEN; z++)
1226 {
1227 for (s=0; s < pP->pEncAlgKey->length; s++)
1228 {
1229 if (pP->pEncAlgKey->code[s].full != 0
1230 && (that = PAF_ASP_chainFind (&pC->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1231 pC->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1232 /* Cast in interface, for now --Kurt */
1233 else
1234 pC->xEnc[z].encAlg[s] = NULL;
1235 }
1236 }
1237 #endif
1239 return 0;
1240 } //PAF_AST_initPhaseAlgKey
1242 Int
1243 PAF_ASDT_initFrame0(
1244 const PAF_AST_Params *pP,
1245 const PAF_AST_Patchs *pQ,
1246 PAF_AST_Config *pC,
1247 Int z
1248 )
1249 {
1250 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1251 Int aLen;
1252 Int aSize = sizeof(PAF_AudioData);
1253 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1254 Int maxFrameLength = pP->maxFramelength;
1255 PAF_AudioData *aBuf=NULL;
1256 XDAS_UInt8 *metadataBuf;
1257 Error_Block eb;
1258 PAF_AudioFrame *pAudioFrame;
1259 Int i;
1261 pAudioFrame = &gpDecAudioFrame[z];
1262 if (pAudioFrame == NULL)
1263 {
1264 SW_BREAKPOINT;
1265 }
1267 // Initialize error block
1268 Error_init(&eb);
1270 //maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO; // compute maximum framelength (needed for ARC support)
1271 aLen = numchan[z] * maxFrameLength;
1273 //
1274 // Initialize audio frame elements directly
1275 //
1276 pAudioFrame->fxns = pP->pAudioFrameFunctions;
1277 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1278 pAudioFrame->data.nSamples = FRAMELENGTH;
1279 pAudioFrame->data.sample = gDecAudioFrameChannelPointers;
1280 pAudioFrame->data.samsiz = gDecAudioFrameChannelSizes;
1281 pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1283 //
1284 // Allocate memory for and initialize pointers to audio data buffers
1285 //
1286 // The NUMCHANMASK is used to identify the channels for which data
1287 // buffers can be allocated. Using this mask and switch statement
1288 // rather than some other construct allows efficient code generation,
1289 // providing just the code necessary (with significant savings).
1290 //
1291 if (pP->fxns->bufMemPrint)
1292 {
1293 pP->fxns->bufMemPrint(z, aLen*aSize, HEAP_ID_FRMBUF, 2);
1294 }
1296 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1298 if (aLen != 0)
1299 {
1300 if (!(aBuf = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen*aSize, aAlign, &eb)))
1301 {
1302 TRACE_TERSE2("AS%d: %s: MEM_calloc failed", as+z, (IArg)__FUNCTION__);
1303 TRACE_TERSE2(" maxFrameLength: %d. aLen*aSize: %d", maxFrameLength, aLen*aSize);
1304 SW_BREAKPOINT;
1305 return __LINE__;
1306 }
1307 }
1309 TRACE_TERSE3(" maxFrameLength: %d. aLen*aSize: %d. aBuf: 0x%x", maxFrameLength, aLen*aSize, (IArg)aBuf);
1311 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1312 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1313 {
1314 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: Memory_calloc failed", as+z);
1315 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1316 SW_BREAKPOINT;
1317 return __LINE__;
1318 }
1320 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1321 {
1322 gDecAudioFrameChannelPointers[i] = NULL;
1323 }
1325 if ((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1326 {
1327 TRACE_TERSE1("PAF_ASDT_initFrame0: AS%d: unsupported option", as+z);
1328 return __LINE__;
1329 }
1330 else
1331 {
1332 Int j = 0;
1333 TRACE_TERSE1("PAF_ASDT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1334 for (i=0; i<numchan[z]; i++)
1335 {
1336 Int8 chan = AFChanPtrMap[numchan[z]][i];
1337 if (chan != -1)
1338 {
1339 gDecAudioFrameChannelPointers[chan] = aBuf + maxFrameLength*(j+1) - FRAMELENGTH;
1340 j++;
1341 TRACE_TERSE3("PAF_ASDT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1342 TRACE_TERSE2("PAF_ASDT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)gDecAudioFrameChannelPointers[chan]);
1343 }
1344 }
1345 }
1347 // Initialize original audio frame channel pointers
1348 for (i=PAF_LEFT; i < PAF_MAXNUMCHAN_AF; i++)
1349 {
1350 if (gDecAudioFrameChannelPointers[i])
1351 {
1352 gDecOrigAudioFrameChannelPointers[i] = gDecAudioFrameChannelPointers[i];
1353 }
1354 }
1356 //
1357 // Initialize meta data elements
1358 //
1359 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1360 pAudioFrame->numPrivateMetadata = 0;
1361 pAudioFrame->bsMetadata_offset = 0;
1362 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1363 pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1364 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1365 {
1366 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1367 pAudioFrame->pafPrivateMetadata[i].size = 0;
1368 pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1369 }
1371 return 0;
1372 } //PAF_ASDT_initFrame0
1374 // -----------------------------------------------------------------------------
1375 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1376 // AST Decoding Function - Reinitialization of Audio Frame
1377 //
1378 // Name: PAF_ASOT_initFrame1
1379 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1380 // zation of the Audio Frame(s) by loading of data values of a
1381 // time-varying nature.
1382 // From: audioStream1Task or equivalent
1383 // AST Parameter Function -> decodeInfo
1384 // AST Parameter Function -> decodeDecode
1385 // Uses: See code.
1386 // States: x
1387 // Return: 0.
1388 // Trace: None.
1389 //
1390 Int
1391 PAF_ASDT_initFrame1(
1392 const PAF_AST_Params *pP,
1393 const PAF_AST_Patchs *pQ,
1394 PAF_AST_Config *pC,
1395 Int z,
1396 Int apply
1397 )
1398 {
1399 PAF_AudioFrame *pAudioFrame;
1401 //
1402 // Reinitialize audio frame elements:
1403 //
1404 // Channel Configurations during sys init = Unknown
1405 // " " during info or decode = None
1406 //
1407 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1408 //
1410 pAudioFrame = &gpDecAudioFrame[z];
1412 if (apply < 0)
1413 {
1414 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1415 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1416 }
1417 else
1418 {
1419 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1420 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1421 }
1423 if (apply < 1)
1424 {
1425 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1426 pAudioFrame->sampleCount = 0;
1427 }
1429 return 0;
1430 } //PAF_ASDT_initFrame1
1432 // Reset AF, invoked during decode ACTIVATE (during state=INIT on Master)
1433 Int resetAf(
1434 const PAF_AST_Params *pP,
1435 Int z,
1436 Int sourceSelect
1437 )
1438 {
1439 PAF_AudioFrame *pAudioFrame;
1440 Int ch;
1441 Int i;
1443 // Get audio frame
1444 pAudioFrame = &gpDecAudioFrame[z];
1445 if (pAudioFrame == NULL)
1446 {
1447 SW_BREAKPOINT;
1448 }
1450 // Reinitialize audio frame elements
1451 pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1452 pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1453 pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1454 pAudioFrame->sampleCount = 0;
1455 pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1457 if (sourceSelect == PAF_SOURCE_PCM)
1458 {
1459 pAudioFrame->data.nSamples = FRAMELENGTH;
1460 }
1461 else if (sourceSelect == PAF_SOURCE_DDP)
1462 {
1463 pAudioFrame->data.nSamples = 1536;
1464 }
1465 else
1466 {
1467 pAudioFrame->data.nSamples = FRAMELENGTH;
1468 }
1470 // Reset audio frame channel pointers
1471 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1472 {
1473 if (gDecAudioFrameChannelPointers[ch])
1474 {
1475 gDecAudioFrameChannelPointers[ch] = gDecOrigAudioFrameChannelPointers[ch];
1476 }
1477 }
1479 // Reset audio frame meta data elements
1480 pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1481 pAudioFrame->numPrivateMetadata = 0;
1482 pAudioFrame->bsMetadata_offset = 0;
1483 pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1484 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1485 {
1486 pAudioFrame->pafPrivateMetadata[i].offset = 0;
1487 pAudioFrame->pafPrivateMetadata[i].size = 0;
1488 }
1490 return 0;
1491 }
1493 // Reset AF samsiz, invoked during DECODE
1494 Int resetAfSamsiz(
1495 Int z
1496 )
1497 {
1498 PAF_AudioFrame *pAudioFrame;
1499 Int ch;
1501 // Get audio frame
1502 pAudioFrame = &gpDecAudioFrame[z];
1503 if (pAudioFrame == NULL)
1504 {
1505 SW_BREAKPOINT;
1506 }
1508 // Clear samsiz for all channels - MID 208.
1509 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
1510 {
1511 pAudioFrame->data.samsiz[ch] = 0;
1512 }
1514 return 0;
1515 }