[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamOutProc.c
1 /*
2 * ======== audioStreamOutProc.c ========
3 */
5 #include <string.h> // for memset
6 #include <xdc/runtime/Log.h>
7 #include <xdc/runtime/Error.h>
8 #include <xdc/runtime/Memory.h>
9 #include <ti/sysbios/knl/Clock.h>
10 #include <ti/sysbios/knl/Task.h>
12 #include "paferr.h"
13 #include <acp_mds.h>
14 #include <pcm.h>
15 #include <pce.h>
16 #include <pafsio_ialg.h>
17 #include <stdasp.h>
18 #include <doberr.h>
19 #include "asperr.h"
21 #include "common.h"
22 #include "aspMsg_common.h"
23 #include "aspMsg_master.h"
24 #include "audioStreamProc_common.h"
25 #include "audioStreamOutProc.h"
27 #define TRACE_TIME(a)
29 //
30 // Audio Stream Definitions
31 //
33 //
34 // Audio Stream Processing Definitions
35 //
36 #define aspLinkInit pQ->i_aspLinkInit
38 //
39 // Encoder Definitions
40 //
41 #define encLinkInit pQ->i_encLinkInit
43 //
44 // Output Definitions
45 //
46 #define outLinkInit pP->i_outLinkInit
48 /* ---------------------------------------------------------------- */
49 /* Parameter macro definitions end here. */
50 /* ---------------------------------------------------------------- */
52 //
53 // Standardized Definitions
54 //
56 #define ENC_Handle PCE_Handle /* works for all: PCE */
58 #define __TASK_NAME__ "TaskAsop"
60 /* FL: Check if at least one output selected */
61 static Int checkOutSel(
62 const PAF_AST_Params *pP,
63 PAF_AST_Config *pC,
64 Int *pOutSel
65 );
67 /* FL: Check if at least one output sio changed */
68 static Int checkOutSio(
69 const PAF_AST_Params *pP,
70 PAF_AST_Config *pC,
71 Int *pOutSioUpdate
72 );
75 LINNO_DEFN(TaskAsop); /* Line number macros */
76 ERRNO_DEFN(TaskAsop); /* Error number macros */
78 // Global debug counters */
79 UInt32 gTaskAsopCnt=0; // debug
80 UInt32 gAsopInitCnt =0;
81 UInt32 gAsopStreamCnt =0;
82 UInt32 gAsopEncodeCnt =0;
83 UInt32 gAsopFinalCnt =0;
84 UInt32 gAsopQuitCnt =0;
87 /*
88 * ======== taskAsopFxn ========
89 * Audio Stream Output Processing task function
90 */
91 Void taskAsopFxn(
92 // Int betaPrimeValue, // FL: revisit
93 const PAF_AST_Params *pP,
94 const PAF_AST_Patchs *pQ
95 )
96 {
97 Int as; /* Audio Stream Number (1, 2, etc.) */
98 Int z; /* input/encode/stream/decode/output counter */
99 Int i; /* phase */
100 Int errno; /* error number */
101 Int zMS;
102 Int loopCount = 0; // used to stop trace to see startup behavior.
104 Log_info0("Enter taskAsopFxn()");
106 //
107 // Audio Framework Configuration (*pC):
108 //
109 pC = &gPAF_AST_config;
111 TRACE_TERSE1("TaskAsop: Started with betaPrimeValue=%d.", gBetaPrimeValue);
112 as = pC->as; /* Audio Stream Number (1, 2, etc.) */
114 //
115 // Audio Framework Parameters & Patch (*pP, *pQ)
116 //
117 if (!pP)
118 {
119 TRACE_TERSE1("TaskAso: AS%d: No Parameters defined. Exiting.", as);
120 LINNO_RPRT(TaskAsop, -1);
121 return;
122 }
124 if (!pQ)
125 {
126 TRACE_TERSE1("TaskAsip: AS%d: No Patchs defined. Exiting.", as);
127 LINNO_RPRT(TaskAsop, -1);
128 return;
129 }
131 //
132 // Initialize message log trace and line number reporting
133 //
134 for (z=STREAM1; z < STREAMN; z++)
135 {
136 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
137 }
138 LINNO_RPRT(TaskAsop, -1);
140 //
141 // Determine stream index
142 //
143 zMS = pC->masterStr;
145 // Initialize as per parametrized phases:
146 //
147 // In standard form these are:
148 // - Malloc: Memory Allocation
149 // - Config: Configuration Initialization
150 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
151 // - Common: Common Memory Initialization
152 // - AlgKey: Dec/Enc chain to Array Initialization
153 // - Device: I/O Device Initialization
154 // - Unused: (available)
155 // - Unused: (available)
156 //
157 LINNO_RPRT(TaskAsop, -2);
158 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
159 {
160 Int linno;
161 if (pP->fxns->initPhase[i])
162 {
163 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
164 {
165 LINNO_RPRT(TaskAsop, linno);
166 return;
167 }
168 }
169 else
170 {
171 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
172 }
173 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
174 LINNO_RPRT(TaskAsop, -i-3);
175 }
177 //
178 // End of Initialization -- display memory usage report.
179 //
180 if (pP->fxns->memStatusPrint)
181 {
182 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
183 }
185 //
186 // Main processing loop
187 //
188 for (z=STREAM1; z < STREAMN; z++)
189 {
190 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
191 }
193 errno = 0;
194 for (;;)
195 {
196 Int outSel;
198 loopCount++;
199 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
201 // any error forces idling of output
202 if (errno)
203 {
204 for (z=OUTPUT1; z < OUTPUTN; z++)
205 {
206 if (pC->xOut[z].hTxSio)
207 {
208 SIO_idle(pC->xOut[z].hTxSio);
209 }
210 }
212 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
213 ERRNO_RPRT(TaskAsop, errno);
214 }
216 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
217 Task_sleep(1);
219 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
220 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
221 {
222 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
223 continue;
224 }
226 // if no output selected skip any remaining processing
227 if (errno = checkOutSel(pP, pC, &outSel))
228 {
229 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
230 continue;
231 }
232 else if (!outSel)
233 {
234 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
235 continue;
236 }
238 TRACE_VERBOSE0("TaskAsop: calling outputProcessing.");
239 errno = pP->fxns->decodeProcessing(pP, pQ, pC, -1);
240 if (errno)
241 {
242 TRACE_TERSE1("TaskAsop: outputProcessing returns 0x%x, continue", errno);
243 }
244 else
245 {
246 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
247 }
248 } // End of main processing loop for (;;)
250 Log_info0("Exit taskAsopFxn()");
251 }
253 // -----------------------------------------------------------------------------
254 // AST Initialization Function - Memory Allocation
255 //
256 // Name: PAF_ASOT_initPhaseMalloc
257 // Purpose: Audio Stream Output Task Function for initialization of data pointers
258 // by allocation of memory.
259 // From: audioStream1Task or equivalent
260 // Uses: See code.
261 // States: x
262 // Return: 0 on success.
263 // Source code line number on MEM_calloc failure.
264 // Trace: Message Log "trace" in Debug Project Configuration reports:
265 // * State information as per parent.
266 // * Memory allocation errors.
267 //
269 Int
270 PAF_ASOT_initPhaseMalloc (
271 const PAF_AST_Params *pP,
272 const PAF_AST_Patchs *pQ,
273 PAF_AST_Config *pC
274 )
275 {
276 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
277 Int zMS = pC->masterStr;
278 Error_Block eb;
279 //Int i;
281 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
283 // Initialize error block
284 Error_init(&eb);
286 /* Stream memory */
287 if (!(pC->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pC->xStr), 4, &eb)))
288 {
289 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
290 SW_BREAKPOINT;
291 return __LINE__;
292 }
293 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (pC->xStr) %d bytes from space %d at 0x%x.",
294 STREAMN * sizeof (*pC->xStr),
295 HEAP_ID_INTERNAL, (IArg)pC->xStr);
297 {
298 Int z; /* stream counter */
300 PAF_AudioFrame *fBuf;
302 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
303 {
304 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
305 SW_BREAKPOINT;
306 return __LINE__;
307 }
308 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
309 STREAMS * sizeof (*fBuf),
310 HEAP_ID_INTERNAL, (IArg)fBuf);
312 for (z=STREAM1; z < STREAMN; z++)
313 {
314 pC->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
315 TRACE_TERSE2("pC->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pC->xStr[z].pAudioFrame);
316 }
317 }
319 /* Encode memory */
320 if (!(pC->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pC->xEnc), 4, &eb)))
321 {
322 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
323 SW_BREAKPOINT;
324 return __LINE__;
325 }
326 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (pC->xEnc) %d bytes from space %d at 0x%x.",
327 ENCODEN * sizeof (*pC->xEnc),
328 HEAP_ID_INTERNAL, (IArg)pC->xEnc);
330 /* Output memory */
331 if (!(pC->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pC->xOut), 4, &eb)))
332 {
333 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
334 SW_BREAKPOINT;
335 return __LINE__;
336 }
337 TRACE_TERSE3("PAF_AST_initPhaseMalloc. (pC->xOut) %d bytes from space %d at 0x%x.",
338 OUTPUTN * sizeof (*pC->xOut),
339 HEAP_ID_INTERNAL, (IArg)pC->xOut);
341 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
342 return 0;
343 } //PAF_ASOT_initPhaseMalloc
345 // -----------------------------------------------------------------------------
346 // ASOT Initialization Function - Memory Initialization from Configuration
347 //
348 // Name: PAF_ASOT_initPhaseConfig
349 // Purpose: Audio Stream Output Task Function for initialization of data values
350 // from parameters.
351 // From: audioStream1Task or equivalent
352 // Uses: See code.
353 // States: x
354 // Return: 0 on success.
355 // Other as per initFrame0 and initFrame1.
356 // Trace: Message Log "trace" in Debug Project Configuration reports:
357 // * State information as per parent.
358 //
359 Int
360 PAF_ASOT_initPhaseConfig(
361 const PAF_AST_Params *pP,
362 const PAF_AST_Patchs *pQ,
363 PAF_AST_Config *pC
364 )
365 {
366 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
367 Int z; /* input/encode/stream/decode/output counter */
368 Int zMS = pC->masterStr;
370 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
372 //
373 // Unspecified elements have been initialized to zero during alloc
374 //
376 for (z=STREAM1; z < STREAMN; z++)
377 {
378 Int linno;
379 if (linno = pP->fxns->initFrame0(pP, pQ, pC, z))
380 {
381 return linno;
382 }
383 if (linno = pP->fxns->initFrame1(pP, pQ, pC, z, -1))
384 {
385 return linno;
386 }
387 }
389 for (z=ENCODE1; z < ENCODEN; z++)
390 {
391 Int zO = pP->outputsFromEncodes[z];
392 Int zS = pP->streamsFromEncodes[z];
393 pC->xEnc[z].encodeControl.size = sizeof(pC->xEnc[z].encodeControl);
394 pC->xEnc[z].encodeControl.pAudioFrame = pC->xStr[zS].pAudioFrame;
395 pC->xEnc[z].encodeControl.pVolumeStatus = &pC->xEnc[z].volumeStatus;
396 pC->xEnc[z].encodeControl.pOutBufConfig = &pC->xOut[zO].outBufConfig;
397 pC->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
398 pC->xEnc[z].encodeControl.encActive = pC->xEnc[z].encodeStatus.select;
399 pC->xEnc[z].volumeStatus = *pP->pVolumeStatus;
400 pC->xEnc[z].encodeInStruct.pAudioFrame = pC->xStr[zS].pAudioFrame;
401 }
403 for (z=OUTPUT1; z < OUTPUTN; z++)
404 {
405 pC->xOut[z].outBufStatus = *pP->pOutBufStatus;
406 }
408 TRACE_TERSE1("PAF_AST_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
409 return 0;
410 } //PAF_ASOT_initPhaseConfig
412 // -----------------------------------------------------------------------------
413 // ASOT Initialization Function - ACP Algorithm Instantiation
414 //
415 // Name: PAF_ASOT_initPhaseAcpAlg
416 // Purpose: Audio Stream Input Task Function for initialization of ACP by
417 // instantiation of the algorithm.
418 // From: audioStream1Task or equivalent
419 // Uses: See code.
420 // States: x
421 // Return: 0 on success.
422 // Source code line number on ACP Algorithm creation failure.
423 // Trace: Message Log "trace" in Debug Project Configuration reports:
424 // * State information as per parent.
425 // * Memory allocation errors.
426 //
427 Int
428 PAF_ASOT_initPhaseAcpAlg(
429 const PAF_AST_Params *pP,
430 const PAF_AST_Patchs *pQ,
431 PAF_AST_Config *pC
432 )
433 {
434 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
435 Int z; /* input/encode/stream/decode/output counter */
436 Int betaPrimeOffset;
437 ACP_Handle acp;
438 Int zMS = pC->masterStr;
439 Int zS, zX;
441 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
443 ACP_MDS_init();
445 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
446 {
447 TRACE_TERSE1("PAF_AST_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
448 return __LINE__;
449 }
450 pC->acp = acp;
452 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
453 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
455 for (z=ENCODE1; z < ENCODEN; z++)
456 {
457 zS = pP->streamsFromEncodes[z];
458 acp->fxns->attach(acp, ACP_SERIES_STD,
459 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
460 (IALG_Status *)&pC->xEnc[z].encodeStatus);
461 acp->fxns->attach(acp, ACP_SERIES_STD,
462 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
463 (IALG_Status *)&pC->xEnc[z].volumeStatus);
464 /* Ignore errors, not reported. */
465 }
467 for (z=OUTPUT1; z < OUTPUTN; z++)
468 {
469 zS = z;
470 for (zX = ENCODE1; zX < ENCODEN; zX++)
471 {
472 if (pP->outputsFromEncodes[zX] == z)
473 {
474 zS = pP->streamsFromEncodes[zX];
475 break;
476 }
477 }
478 acp->fxns->attach(acp, ACP_SERIES_STD,
479 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
480 (IALG_Status *)&pC->xOut[z].outBufStatus);
481 /* Ignore errors, not reported. */
482 }
484 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
486 return 0;
487 } //PAF_ASOT_initPhaseAcpAlg
489 // -----------------------------------------------------------------------------
490 // ASOT Initialization Function - Common Memory
491 //
492 // Name: PAF_ASOT_initPhaseCommon
493 // Purpose: Audio Stream Output Task Function for allocation of common memory.
494 // From: audioStream1Task or equivalent
495 // Uses: See code.
496 // States: x
497 // Return: 0 on success.
498 // Source code line number on PAF_ALG_alloc failure.
499 // Source code line number on PAF_ALG_mallocMemory failure.
500 // Source code line number on Decode Chain initialization failure.
501 // Source code line number on ASP Chain initialization failure.
502 // Source code line number on Encode Chain initialization failure.
503 // Trace: Message Log "trace" in Debug Project Configuration reports:
504 // * State information as per parent.
505 // * Memory allocation errors.
506 //
507 Int
508 PAF_ASOT_initPhaseCommon(
509 const PAF_AST_Params *pP,
510 const PAF_AST_Patchs *pQ,
511 PAF_AST_Config *pC
512 )
513 {
514 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
515 Int z; /* stream counter */
516 Int g; /* gear */
517 ACP_Handle acp = pC->acp;
518 PAF_IALG_Config pafAlgConfig;
519 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
521 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
523 //
524 // Determine memory needs and instantiate algorithms across audio streams
525 //
526 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
527 PAF_ALG_setup(&pafAlgConfig,
528 HEAP_ID_INTERNAL, HEAP_INTERNAL,
529 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
530 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
531 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
532 HEAP_CLEAR);
534 if (pP->fxns->headerPrint)
535 {
536 pP->fxns->headerPrint();
537 }
539 for (z = STREAM1; z < STREAMN; z++)
540 {
541 //Int zD, zE, zX;
542 Int zE, zX;
544 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
546 //
547 // Determine common memory needs for:
548 // (1) ASP Algorithms
549 // (2) Encode Algorithms
550 // (3) Logical Output drivers
551 //
552 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
554 zE = -1;
555 for (zX = ENCODE1; zX < ENCODEN; zX++)
556 {
557 if (pP->streamsFromEncodes[zX] == z)
558 {
559 zE = zX;
560 break;
561 }
562 }
564 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
565 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
566 {
567 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
568 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
569 SW_BREAKPOINT;
570 return __LINE__;
571 }
572 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
573 if (pP->fxns->allocPrint)
574 {
575 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
576 }
578 if (zE >= 0)
579 {
580 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
581 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
582 {
583 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
584 SW_BREAKPOINT;
585 return __LINE__;
586 }
587 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
588 if (pP->fxns->allocPrint)
589 {
590 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
591 }
592 }
594 //
595 // Determine common memory needs of Logical IO drivers
596 //
598 if (OUTPUT1 <= z && z < OUTPUTN)
599 {
600 TRACE_TERSE1("%PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
601 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
602 {
603 TRACE_TERSE1("PAF_AST_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
604 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
605 SW_BREAKPOINT;
606 return __LINE__;
607 }
608 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
609 if (pP->fxns->allocPrint)
610 {
611 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
612 }
613 }
614 }
615 {
616 // Changes made to share scratch between zones
617 // Assume maximum 3 zones and scratch common memory is at offset 0;
618 int max=0;
619 for (z=STREAM1; z<STREAMN; z++)
620 {
621 if (max < common[z][0].size)
622 {
623 max = common[z][0].size;
624 }
625 }
626 common[STREAM1][0].size=max;
627 for (z=STREAM1+1; z<STREAMN; z++)
628 {
629 common[z][0].size = 0;
630 }
631 }
633 //
634 // Allocate common memory for:
635 // (1) ASP Algorithms
636 // (2) Encode Algorithms
637 // (3) Logical Output drivers
638 //
639 for (z = STREAM1; z < STREAMN; z++)
640 {
641 //Int zD, zE, zX;
642 Int zE, zX;
644 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
645 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
646 {
647 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
648 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
649 SW_BREAKPOINT;
650 return __LINE__;
651 }
652 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
653 // share zone0 scratch with all zones
654 common[z][0].base = common[0][0].base;
655 if (pP->fxns->commonPrint)
656 {
657 pP->fxns->commonPrint(common[z], &pafAlgConfig);
658 }
660 zE = -1;
661 for (zX = ENCODE1; zX < ENCODEN; zX++)
662 {
663 if (pP->streamsFromEncodes[zX] == z)
664 {
665 zE = zX;
666 break;
667 }
668 }
670 pC->xStr[z].aspChain[0] = NULL;
671 for (g=0; g < GEARS; g++)
672 {
673 PAF_ASP_Chain *chain;
674 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
675 chain = PAF_ASP_chainInit(&pC->xStr[z].aspChainData[g], pP->pChainFxns,
676 HEAP_INTERNAL, as+z, acp, &trace,
677 aspLinkInit[z-STREAM1][g], pC->xStr[z].aspChain[0], common[z], &pafAlgConfig);
678 if (!chain)
679 {
680 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
681 return __LINE__;
682 }
683 else
684 {
685 pC->xStr[z].aspChain[g] = chain;
686 }
687 }
689 if (zE >= 0)
690 {
691 PAF_ASP_Chain *chain;
692 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
693 chain = PAF_ASP_chainInit(&pC->xEnc[zE].encChainData, pP->pChainFxns,
694 HEAP_INTERNAL, as+z, acp, &trace,
695 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
696 if (!chain)
697 {
698 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
699 return __LINE__;
700 }
701 }
703 //
704 // Allocate non-common memories for Logical IO drivers
705 // Since these structures are used at run-time we allocate from external memory
706 if (OUTPUT1 <= z && z < OUTPUTN)
707 {
708 PAF_ASP_Chain *chain;
709 TRACE_TERSE2("PAF_AST_initPhaseMalloc: AS%d: non-common output chain init for %d",
710 as+z, z);
711 chain = PAF_ASP_chainInit (&pC->xOut[z].outChainData, pP->pChainFxns,
712 HEAP_EXTERNAL, as+z, acp, &trace,
713 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
714 if (!chain)
715 {
716 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
717 return __LINE__;
718 }
719 }
720 }
721 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
723 return 0;
724 } //PAF_ASOT_initPhaseCommon
726 // -----------------------------------------------------------------------------
727 // ASOT Initialization Function - Algorithm Keys
728 //
729 // Name: PAF_ASOT_initPhaseAlgKey
730 // Purpose: Audio Stream Output Task Function for initialization of data values
731 // from parameters for Algorithm Keys.
732 // From: audioStream1Task or equivalent
733 // Uses: See code.
734 // States: x
735 // Return: 0.
736 // Trace: Message Log "trace" in Debug Project Configuration reports:
737 // * State information as per parent.
738 //
739 // .............................................................................
740 Int
741 PAF_ASOT_initPhaseAlgKey(
742 const PAF_AST_Params *pP,
743 const PAF_AST_Patchs *pQ,
744 PAF_AST_Config *pC
745 )
746 {
747 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
748 Int z; /* decode/encode counter */
749 Int s; /* key number */
750 PAF_ASP_Link *that;
752 (void)as; // clear compiler warning in case not used with tracing disabled
754 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
756 for (z=ENCODE1; z < ENCODEN; z++)
757 {
758 for (s=0; s < pP->pEncAlgKey->length; s++)
759 {
760 if ((pP->pEncAlgKey->code[s].full != 0) &&
761 (that = PAF_ASP_chainFind(&pC->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
762 {
763 pC->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
764 }
765 /* Cast in interface, for now --Kurt */
766 else
767 {
768 pC->xEnc[z].encAlg[s] = NULL;
769 }
770 }
771 }
773 return 0;
774 } //PAF_ASOT_initPhaseAlgKey
776 // -----------------------------------------------------------------------------
777 // ASOT Initialization Function - I/O Devices
778 //
779 // Name: PAF_ASOT_initPhaseDevice
780 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
781 // From: audioStream1Task or equivalent
782 // Uses: See code.
783 // States: x
784 // Return: 0 on success.
785 // Source code line number on device allocation failure.
786 // Trace: Message Log "trace" in Debug Project Configuration reports:
787 // * State information as per parent.
788 // * Memory allocation errors.
789 //
790 Int
791 PAF_ASOT_initPhaseDevice(
792 const PAF_AST_Params *pP,
793 const PAF_AST_Patchs *pQ,
794 PAF_AST_Config *pC
795 )
796 {
797 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
798 Int z; /* input/output counter */
799 PAF_SIO_IALG_Obj *pObj;
800 PAF_SIO_IALG_Config *pAlgConfig;
801 PAF_IALG_Config pafAlgConfig;
803 (void)as; // clear compiler warning in case not used with tracing disabled
805 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
807 if(pP->fxns->bufMemPrint)
808 {
809 PAF_ALG_setup (&pafAlgConfig,
810 HEAP_ID_INTERNAL, HEAP_INTERNAL,
811 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
812 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
813 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
814 HEAP_CLEAR);
815 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
816 }
818 for (z=OUTPUT1; z < OUTPUTN; z++)
819 {
820 PAF_OutBufConfig *pConfig = &pC->xOut[z].outBufConfig;
822 pObj = (PAF_SIO_IALG_Obj *)pC->xOut[z].outChainData.head->alg;
823 pAlgConfig = &pObj->config;
825 pC->xOut[z].hTxSio = NULL;
826 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
827 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
828 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
829 pConfig->allocation = pAlgConfig->pMemRec[0].size;
830 pConfig->sizeofElement = 3;
831 pConfig->precision = 24;
832 if(pP->fxns->bufMemPrint)
833 {
834 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
835 }
836 }
837 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
839 return 0;
840 } //PAF_ASOT_initPhaseDevice
842 // -----------------------------------------------------------------------------
843 // ASOT Initialization Function Helper - Initialization of Audio Frame
844 //
845 // Name: PAF_ASOT_initFrame0
846 // Purpose: Audio Stream Output Task Function for initialization of the Audio
847 // Frame(s) by memory allocation and loading of data pointers
848 // and values.
849 // From: AST Parameter Function -> decodeInfo
850 // Uses: See code.
851 // States: x
852 // Return: 0 on success.
853 // Source code line number on MEM_calloc failure.
854 // Source code line number on unsupported option.
855 // Trace: Message Log "trace" in Debug Project Configuration reports:
856 // * Memory allocation errors.
857 // * Unsupported option errors.
858 //
860 // MID 314
861 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
862 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
864 Int
865 PAF_ASOT_initFrame0(
866 const PAF_AST_Params *pP,
867 const PAF_AST_Patchs *pQ,
868 PAF_AST_Config *pC,
869 Int z
870 )
871 {
872 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
873 Int ch;
874 //Int aLen;
875 Int aLen_int=0,aLen_ext=0;
876 Int aSize = sizeof(PAF_AudioData);
877 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
878 Int maxFrameLength = pP->maxFramelength;
879 Int zX;
880 PAF_AudioData *aBuf_int=NULL;
881 PAF_AudioData *aBuf_ext=NULL;
882 XDAS_UInt8 *metadataBuf;
883 char i;
884 Error_Block eb;
886 // Initialize error block
887 Error_init(&eb);
889 // Compute maximum framelength (needed for ARC support)
890 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
891 //aLen = numchan[z] * maxFrameLength;
892 for (i=0; i < numchan[z]; i++)
893 {
894 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
895 {
896 aLen_int += maxFrameLength;
897 }
898 else
899 {
900 aLen_ext += maxFrameLength;
901 }
902 }
904 //
905 // Initialize audio frame elements directly
906 //
907 pC->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
908 pC->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
909 /// pC->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
910 pC->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
911 pC->xStr[z].pAudioFrame->data.sample = pC->xStr[z].audioFrameChannelPointers;
912 pC->xStr[z].pAudioFrame->data.samsiz = pC->xStr[z].audioFrameChannelSizes;
913 pC->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
915 //
916 // Allocate memory for and initialize pointers to audio data buffers
917 //
918 // The NUMCHANMASK is used to identify the channels for which data
919 // buffers can be allocated. Using this mask and switch statement
920 // rather than some other construct allows efficient code generation,
921 // providing just the code necessary (with significant savings).
922 //
923 if (pP->fxns->bufMemPrint)
924 {
925 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
926 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
927 }
929 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
931 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
932 {
933 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen_int*aSize, aAlign, &eb)))
934 {
935 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
936 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, aLen_int*aSize);
937 SW_BREAKPOINT;
938 return __LINE__;
939 }
940 }
942 if (aLen_ext*aSize!=0)
943 {
944 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, aLen_ext*aSize, aAlign, &eb)))
945 {
946 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
947 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, aLen_ext*aSize);
948 SW_BREAKPOINT;
949 return __LINE__;
950 }
951 }
953 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, aLen_int*aSize, (IArg)aBuf_int);
954 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, aLen_ext*aSize, (IArg)aBuf_ext);
956 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
957 //if (! (metadataBuf = (XDAS_UInt8 *)MEM_calloc (*(pP->pMetadataBufStatus->pSpace), pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment))) {
958 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
959 {
960 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
961 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
962 SW_BREAKPOINT;
963 return __LINE__;
964 }
966 {
967 Int i;
969 #pragma UNROLL(1)
970 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
971 {
972 pC->xStr[z].audioFrameChannelPointers[i] = NULL;
973 }
974 }
976 // MID 314
977 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
978 {
979 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
980 return __LINE__;
981 }
982 else
983 {
984 Int j = 0;
985 Int k = 0;
986 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
987 for(i=0;i<numchan[z];i++)
988 {
989 char chan = AFChanPtrMap[numchan[z]][i];
990 if(chan != -1)
991 {
992 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
993 {
994 pC->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
995 j++;
996 }
997 else
998 {
999 pC->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1000 k++;
1001 }
1002 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1003 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pC->xStr[z].audioFrameChannelPointers[chan]);
1004 }
1005 }
1006 }
1008 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1009 {
1010 if (pC->xStr[z].audioFrameChannelPointers[ch])
1011 {
1012 pC->xStr[z].origAudioFrameChannelPointers[ch] = pC->xStr[z].audioFrameChannelPointers[ch];
1013 }
1014 }
1016 //
1017 // Initialize meta data elements
1018 //
1019 pC->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1020 pC->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1021 pC->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1022 pC->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1023 pC->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1024 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1025 {
1026 pC->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1027 pC->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1028 pC->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1029 }
1031 //
1032 // Initialize decoder elements directly
1033 //
1035 for (zX = DECODE1; zX < DECODEN; zX++)
1036 {
1037 if (pP->streamsFromDecodes[zX] == z)
1038 {
1039 #ifdef NOAUDIOSHARE
1040 pC->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1041 pC->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1042 #else /* NOAUDIOSHARE */
1043 pC->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1044 pC->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1045 #endif /* NOAUDIOSHARE */
1046 }
1047 }
1049 return 0;
1050 } //PAF_ASOT_initFrame0
1052 // -----------------------------------------------------------------------------
1053 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1054 // AST Decoding Function - Reinitialization of Audio Frame
1055 //
1056 // Name: PAF_ASOT_initFrame1
1057 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1058 // zation of the Audio Frame(s) by loading of data values of a
1059 // time-varying nature.
1060 // From: audioStream1Task or equivalent
1061 // AST Parameter Function -> decodeInfo
1062 // AST Parameter Function -> decodeDecode
1063 // Uses: See code.
1064 // States: x
1065 // Return: 0.
1066 // Trace: None.
1067 //
1068 Int
1069 PAF_ASOT_initFrame1(
1070 const PAF_AST_Params *pP,
1071 const PAF_AST_Patchs *pQ,
1072 PAF_AST_Config *pC,
1073 Int z,
1074 Int apply
1075 )
1076 {
1077 //
1078 // Reinitialize audio frame elements:
1079 //
1080 // Channel Configurations during sys init = Unknown
1081 // " " during info or decode = None
1082 //
1083 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1084 //
1086 if (apply < 0)
1087 {
1088 pC->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1089 pC->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1090 }
1091 else
1092 {
1093 pC->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1094 pC->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1095 }
1097 if (apply < 1)
1098 {
1099 pC->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1100 pC->xStr[z].pAudioFrame->sampleCount = 0;
1101 }
1103 return 0;
1104 } //PAF_AST_initFrame1
1106 // -----------------------------------------------------------------------------
1107 // ASOT Selection Function - Output Device Selection
1108 //
1109 // Name: PAF_ASOT_selectDevices
1110 // Purpose: Audio Stream Output Task Function for selecting the devices used
1111 // for output.
1112 // From: audioStream1Task or equivalent
1113 // Uses: See code.
1114 // States: x
1115 // Return: Error number in standard form (0 on success).
1116 // Trace: Message Log "trace" in Debug Project Configuration reports:
1117 // * State information as per parent.
1118 //
1119 Int
1120 PAF_ASOT_selectDevices(
1121 const PAF_AST_Params *pP,
1122 const PAF_AST_Patchs *pQ,
1123 PAF_AST_Config *pC
1124 )
1125 {
1126 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1127 Int z; /* input/output counter */
1128 Int errno = 0; /* error number */
1129 Int errme; /* error number, local */
1130 Int device;
1132 (void)as; // clear compiler warning in case not used with tracing disabled
1134 // Select output devices
1135 for (z=OUTPUT1; z < OUTPUTN; z++)
1136 {
1137 if ((device = pC->xOut[z].outBufStatus.sioSelect) >= 0)
1138 {
1139 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1141 /* check for valid index into device array */
1142 if (device >= pQ->devout->n)
1143 {
1144 device = 0; /* treat as device None */
1145 }
1147 errme = pP->fxns->deviceSelect(&pC->xOut[z].hTxSio, SIO_OUTPUT,
1148 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1149 if (errme)
1150 {
1151 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1152 if (!errno)
1153 {
1154 errno = ASPERR_DEVOUT + errme;
1155 }
1156 pC->xOut[z].outBufStatus.sioSelect = 0x80;
1157 }
1158 else
1159 {
1160 Int zE;
1162 pC->xOut[z].outBufStatus.sioSelect = device | 0x80;
1163 // register outBufStatus and encodeStatus pointers with output devices
1164 // This enables proper IEC encapsulation.
1165 if (pC->xOut[z].hTxSio)
1166 {
1167 // set max # of output buffers (use override if necessary)
1168 if (pC->xOut[z].outBufStatus.maxNumBufOverride == 0)
1169 {
1170 SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1171 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1172 }
1173 else
1174 {
1175 SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1176 (Arg)pC->xOut[z].outBufStatus.maxNumBufOverride);
1177 }
1179 // register PAF_SIO_IALG object address
1180 SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1181 (Arg)pC->xOut[z].outChainData.head->alg);
1182 SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1183 (Arg)&pC->xOut[z].outBufStatus);
1184 for (zE=ENCODE1; zE < ENCODEN; zE++)
1185 {
1186 if (pP->outputsFromEncodes[zE] == z)
1187 {
1188 SIO_ctrl (pC->xOut[z].hTxSio,
1189 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1190 (Arg)&pC->xEnc[zE].encodeStatus);
1191 break;
1192 }
1193 }
1194 }
1195 }
1196 }
1198 // if device selected and valid then enable stat tracking if
1199 // required and start clocking
1200 if ((pC->xOut[z].outBufStatus.sioSelect < 0) && (pC->xOut[z].hTxSio))
1201 {
1202 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1203 errme = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1204 if (errme)
1205 {
1206 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1207 SIO_idle (pC->xOut[z].hTxSio);
1208 if (!errno)
1209 {
1210 errno = ASPERR_DEVOUT + errme;
1211 }
1212 }
1213 }
1214 }
1216 return errno;
1217 } //PAF_ASOT_selectDevices
1219 // -----------------------------------------------------------------------------
1220 // ASOT Processing Function - Decode Processing
1221 //
1222 // Name: PAF_ASOT_decodeProcessing
1223 // Purpose: Audio Stream Output Task Function for processing audio data.
1224 //
1225 Int
1226 PAF_ASOT_decodeProcessing(
1227 const PAF_AST_Params *pP,
1228 const PAF_AST_Patchs *pQ,
1229 PAF_AST_Config *pC,
1230 Int sourceSelect
1231 )
1232 {
1233 Int z; /* decode counter */
1234 Int errno; /* error number */
1235 Int getVal;
1236 enum { INIT, STREAM, ENCODE, FINAL, QUIT } state;
1237 state = INIT;
1238 errno = 0; /* error number */
1239 Int frame; // (***) FL: formerly -- decoder input frame count
1240 Int block; // decoder output block count / input frame
1241 Int outSioUpdate;
1243 for (;;)
1244 {
1245 // FL: Check if any change in output SIO, e.g. from Output shortcut.
1246 // Changes will break FSM and allow Output reconfiguration.
1247 if (errno = checkOutSio(pP, pC, &outSioUpdate))
1248 {
1249 TRACE_TERSE1("PAF_AST_outputProcessing: checkOutSio returned errno = 0x%04x", errno);
1250 break;
1251 }
1252 else if (outSioUpdate)
1253 {
1254 TRACE_VERBOSE0("PAF_AST_outputProcessing: Change in Output SIO selection");
1255 state = QUIT;
1256 }
1258 // Process commands (encode)
1259 if (getVal = pP->fxns->encodeCommand(pP, pQ, pC))
1260 {
1261 /* ignore */;
1262 }
1264 // Process state (decode)
1265 switch (state)
1266 {
1267 case INIT: // initial state
1268 gAsopInitCnt++;
1269 Log_info0("TaskAsop: state=INIT");
1271 // Reset audio frame pointers to original values
1272 // (may be needed if error occurred).
1273 for (z=STREAM1; z < STREAMN; z++)
1274 {
1275 Int ch;
1276 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1277 {
1278 if (pC->xStr[z].audioFrameChannelPointers[ch])
1279 {
1280 pC->xStr[z].audioFrameChannelPointers[ch] =
1281 pC->xStr[z].origAudioFrameChannelPointers[ch];
1282 }
1283 }
1284 }
1286 // Reset audio frame meta data elements
1287 {
1288 Int i;
1290 for (z=STREAM1; z < STREAMN; z++)
1291 {
1292 pC->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1293 pC->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1294 pC->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1295 pC->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1297 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1298 {
1299 pC->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1300 pC->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1301 }
1302 }
1303 }
1305 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1306 {
1307 TRACE_VERBOSE1("PAF_AST_outputProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1308 break;
1309 }
1311 // (***) FL: setup output (ASP chain reset, ENC reset, setCheckRateX, start output)
1312 // Contained in INFO1 in combined FSM.
1313 // Establish secondary timing
1314 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
1315 {
1316 TRACE_VERBOSE1("PAF_AST_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
1317 break;
1318 }
1320 frame = 0;
1321 block = 0;
1323 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: INIT->STREAM");
1324 state = STREAM;
1325 continue;
1327 case STREAM: // stream state
1328 gAsopStreamCnt++;
1329 Log_info0("TaskAsop: state=STREAM");
1331 if (errno = pP->fxns->decodeStream(pP, pQ, pC, frame, block))
1332 {
1333 TRACE_TERSE1("PAF_AST_outputProcessing: state: STREAM. decodeStream err 0x%x", errno);
1334 break;
1335 }
1337 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: STREAM->ENCODE");
1338 state = ENCODE;
1339 continue;
1341 case ENCODE: // encode state
1342 gAsopEncodeCnt++;
1343 Log_info0("TaskAsop: state=ENCODE");
1345 if (errno = pP->fxns->decodeEncode(pP, pQ, pC, frame, block))
1346 {
1347 TRACE_TERSE1("PAF_AST_outputProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
1348 break;
1349 }
1351 // (***) FL: do we need this?
1352 // AF pointers come from CB read, any resets occur in Decoder AF.
1353 // Reset audio frame pointers to original values
1354 // (may have been adjusted by ARC or the like).
1355 for (z=STREAM1; z < STREAMN; z++)
1356 {
1357 Int ch;
1358 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1359 {
1360 if (pC->xStr[z].audioFrameChannelPointers[ch])
1361 {
1362 pC->xStr[z].audioFrameChannelPointers[ch] =
1363 pC->xStr[z].origAudioFrameChannelPointers[ch];
1364 }
1365 }
1366 }
1368 //
1369 // (***) FL: update output (setCheckRateX)
1370 // Contained in INFO2 in combined FSM.
1371 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
1372 {
1373 TRACE_TERSE1("PAF_AST_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
1374 break;
1375 }
1377 block++;
1378 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: ENCODE->FINAL");
1379 state = FINAL;
1380 continue;
1382 case FINAL:
1383 gAsopFinalCnt++;
1384 Log_info0("TaskAsop: state=FINAL");
1386 //
1387 // (***) FL: this needs to be fixed.
1388 // (1) Only require selected Output to be in this FSM
1389 // => Dec Status checks aren't valid,
1390 // will probably always exit FSM if only Output running
1391 // (2) Checking Dec Status info asych to input events (maybe ok)
1392 //
1393 #if 0
1394 // Check for final frame, and if indicated:
1395 // - Update audio flag to cause output buffer flush rather than
1396 // the default truncate in "complete" processing.
1397 // - Exit state machine to "complete" processing.
1398 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
1399 {
1400 for (z=OUTPUT1; z < OUTPUTN; z++)
1401 {
1402 if ((pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
1403 {
1404 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: FINAL: SOUND -> QUIET");
1405 pC->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
1406 }
1407 }
1408 break;
1409 }
1410 #endif
1412 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: FINAL->STREAM");
1413 state = STREAM;
1414 continue;
1416 case QUIT:
1417 gAsopQuitCnt++;
1418 Log_info0("TaskAsop: state=QUIT");
1420 TRACE_VERBOSE0("PAF_AST_outputProcessing: state: QUIT");
1421 errno = ASPERR_QUIT;
1422 break;
1424 default: // unknown state
1425 // Unknown:
1426 // - Set error number registers.
1427 // - Exit state machine to "complete" processing.
1429 TRACE_TERSE1("PAF_AST_outputProcessing: state: unknown, 0x%x", state);
1430 errno = ASPERR_UNKNOWNSTATE;
1431 break;
1433 } // End of switch (state).
1435 TRACE_VERBOSE0("PAF_AST_outputProcessing: Calling decode complete");
1436 if (pP->fxns->decodeComplete(pP, pQ, pC, NULL, frame, block))
1437 {
1438 /* ignored? */;
1439 }
1441 return errno;
1442 } // End of for (;;)
1444 return errno;
1445 }
1447 // -----------------------------------------------------------------------------
1448 // ASOT Decoding Function - Encode Command Processing
1449 //
1450 // Name: PAF_ASOT_encodeCommand
1451 // Purpose: Decoding Function for processing Encode Commands.
1452 // From: AST Parameter Function -> decodeProcessing
1453 // Uses: See code.
1454 // States: x
1455 // Return: 0.
1456 // Trace: Message Log "trace" in Debug Project Configuration reports:
1457 // * Command execution.
1458 // * SIO control errors.
1459 // * Error number macros.
1460 //
1461 Int
1462 PAF_ASOT_encodeCommand(
1463 const PAF_AST_Params *pP,
1464 const PAF_AST_Patchs *pQ,
1465 PAF_AST_Config *pC
1466 )
1467 {
1468 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1469 Int z; /* encode counter */
1470 Int errno = 0; /* error number */
1471 Int zO, zS;
1474 for (z=ENCODE1; z < ENCODEN; z++)
1475 {
1476 zO = pP->outputsFromEncodes[z];
1477 zS = pP->streamsFromEncodes[z];
1478 if (! (pC->xEnc[z].encodeStatus.command2 & 0x80))
1479 {
1480 switch (pC->xEnc[z].encodeStatus.command2)
1481 {
1482 case 0: // command none - process
1483 pC->xEnc[z].encodeStatus.command2 |= 0x80;
1484 break;
1485 case 1: // mute command
1486 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
1487 if ((pC->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
1488 && pC->xOut[zO].hTxSio
1489 && (errno = SIO_ctrl (pC->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
1490 {
1491 errno = (errno & 0xff) | ASPERR_MUTE;
1492 /* convert to sensical errno */
1493 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
1494 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
1495 }
1496 else
1497 {
1498 pC->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
1499 }
1500 pC->xEnc[z].encodeStatus.command2 |= 0x80;
1501 break;
1502 case 2: // unmute command
1503 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
1504 if ((pC->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
1505 && pC->xOut[zO].hTxSio
1506 && (errno = SIO_ctrl (pC->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
1507 {
1508 errno = (errno & 0xff) | ASPERR_MUTE;
1509 /* convert to sensical errno */
1510 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
1511 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
1512 }
1513 else
1514 {
1515 pC->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
1516 }
1517 pC->xEnc[z].encodeStatus.command2 |= 0x80;
1518 break;
1519 default: // command unknown - ignore
1520 break;
1521 }
1522 }
1523 }
1525 ERRNO_RPRT (TaskAsop, errno);
1527 return 0;
1528 } //PAF_ASOT_encodeCommand
1530 // Purpose: Decoding Function for reinitializing the decoding process.
1531 Int
1532 PAF_ASOT_decodeInit(
1533 const PAF_AST_Params *pP,
1534 const PAF_AST_Patchs *pQ,
1535 PAF_AST_Config *pC,
1536 Int sourceSelect
1537 )
1538 {
1539 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1540 Int z; /* decode/encode counter */
1541 Int errno; /* error number */
1542 Int zO, zS;
1543 PAF_DecodeOpCircBuf *pCb; /* decoder output circular buffer */
1545 for (z=DECODE1; z < DECODEN; z++)
1546 {
1547 // Start decoder output circular buffer reads
1548 pCb = &pC->xDec[z].decOpCb;
1549 errno = cbReadStart(pCb);
1550 if (errno)
1551 {
1552 return errno;
1553 }
1554 }
1556 // TODO: move this to start of this function so that it doesn't affect IO timing
1557 for (z=ENCODE1; z < ENCODEN; z++)
1558 {
1559 zO = pP->outputsFromEncodes[z];
1560 zS = pP->streamsFromEncodes[z];
1561 if (pC->xOut[zO].hTxSio && pC->xEnc[z].encodeStatus.mode)
1562 {
1563 Int select = pC->xEnc[z].encodeStatus.select;
1564 ALG_Handle encAlg = pC->xEnc[z].encAlg[select];
1565 ENC_Handle enc = (ENC_Handle )encAlg;
1566 TRACE_VERBOSE1("AS%d: PAF_AST_decodeInit: initializing encode", as+zS);
1567 if (encAlg->fxns->algActivate)
1568 {
1569 encAlg->fxns->algActivate (encAlg);
1570 }
1571 if (enc->fxns->reset
1572 && (errno = enc->fxns->reset(enc, NULL,
1573 &pC->xEnc[z].encodeControl, &pC->xEnc[z].encodeStatus)))
1574 {
1575 return errno;
1576 }
1577 }
1578 }
1580 return 0;
1581 }
1583 // -----------------------------------------------------------------------------
1584 // ASOT Decoding Function - Info Processing, Initial
1585 //
1586 // Name: PAF_ASOT_decodeInfo1
1587 // Purpose: Decoding Function for processing information in a manner that
1588 // is unique to initial frames of input data.
1589 // From: AST Parameter Function -> decodeProcessing
1590 // Uses: See code.
1591 // States: x
1592 // Return: Error number in standard or SIO form (0 on success).
1593 // Trace: Message Log "trace" in Debug Project Configuration reports:
1594 // * State information as per parent.
1595 //
1596 Int
1597 PAF_ASOT_decodeInfo1(
1598 const PAF_AST_Params *pP,
1599 const PAF_AST_Patchs *pQ,
1600 PAF_AST_Config *pC,
1601 Int frame,
1602 Int block
1603 )
1604 {
1605 Int z; /* decode/encode counter */
1606 Int errno; /* error number */
1608 // run the chain of ASP's on the stream.
1609 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
1610 if (errno = pP->fxns->streamChainFunction(pP, pQ, pC,
1611 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame))
1612 {
1613 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
1614 return errno;
1615 }
1617 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
1618 for (z=ENCODE1; z < ENCODEN; z++)
1619 {
1620 Int zO = pP->outputsFromEncodes[z];
1621 if (pC->xOut[zO].hTxSio && pC->xEnc[z].encodeStatus.mode)
1622 {
1623 Int select = pC->xEnc[z].encodeStatus.select;
1624 ALG_Handle encAlg = pC->xEnc[z].encAlg[select];
1625 ENC_Handle enc = (ENC_Handle )encAlg;
1626 if (enc->fxns->info
1627 && (errno = enc->fxns->info(enc, NULL,
1628 &pC->xEnc[z].encodeControl, &pC->xEnc[z].encodeStatus)))
1629 {
1630 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
1631 return errno;
1632 }
1633 }
1634 }
1636 if (errno = pP->fxns->setCheckRateX(pP, pQ, pC, 0))
1637 {
1638 // ignore if rateX has changed since we haven't, but are about to,
1639 // start the output. If we didn't ignore this case then the state machine
1640 // would restart unnecessarily, e.g. in the case of SRC, resulting in
1641 // added latency.
1642 if (errno != ASPERR_INFO_RATECHANGE)
1643 {
1644 TRACE_TERSE1("PAF_ASIT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
1645 return errno;
1646 }
1647 else
1648 {
1649 TRACE_TERSE0("PAF_ASIT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
1650 }
1651 }
1653 if (errno = pP->fxns->startOutput(pP, pQ, pC))
1654 {
1655 if (errno == 0x105)
1656 {
1657 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
1658 }
1659 else
1660 {
1661 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
1662 }
1663 return errno;
1664 }
1666 return 0;
1667 }
1669 // -----------------------------------------------------------------------------
1670 // ASOT Decoding Function - Info Processing, Subsequent
1671 //
1672 // Name: PAF_ASOT_decodeInfo2
1673 // Purpose: Decoding Function for processing information in a manner that
1674 // is unique to frames of input data other than the initial one.
1675 // From: AST Parameter Function -> decodeProcessing
1676 // Uses: See code.
1677 // States: x
1678 // Return: Error number in standard form (0 on success).
1679 // Trace: None.
1680 //
1681 Int
1682 PAF_ASOT_decodeInfo2(
1683 const PAF_AST_Params *pP,
1684 const PAF_AST_Patchs *pQ,
1685 PAF_AST_Config *pC,
1686 Int frame,
1687 Int block
1688 )
1689 {
1690 Int errno;
1692 errno = pP->fxns->setCheckRateX (pP, pQ, pC, 1);
1693 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
1694 return errno;
1695 } //PAF_ASOT_decodeInfo2
1697 // -----------------------------------------------------------------------------
1698 // ASOT Decoding Function - Stream Processing
1699 //
1700 // Name: PAF_ASOT_decodeStream
1701 // Purpose: Decoding Function for processing of audio frame data by the
1702 // ASP Algorithms.
1703 // From: AST Parameter Function -> decodeProcessing
1704 // Uses: See code.
1705 // States: x
1706 // Return: Error number in standard form (0 on success).
1707 // Trace: Message Log "trace" in Debug Project Configuration reports:
1708 // * State information as per parent/child.
1709 //
1710 Int
1711 PAF_ASOT_decodeStream(
1712 const PAF_AST_Params *pP,
1713 const PAF_AST_Patchs *pQ,
1714 PAF_AST_Config *pC,
1715 Int frame,
1716 Int block
1717 )
1718 {
1719 Int z; /* decode/stream counter */
1720 PAF_DecodeOpCircBuf *pCb;
1721 PAF_AudioFrame *pAfRd;
1722 Int cbErrno;
1723 Int errno;
1725 for (z=DECODE1; z < DECODEN; z++)
1726 {
1727 Int zS = pP->streamsFromDecodes[z];
1729 //
1730 // (***) FL: read circular buffer
1731 //
1732 pCb = &pC->xDec[z].decOpCb;
1733 pAfRd = pC->xStr[zS].pAudioFrame;
1734 cbErrno = cbReadAf(pCb, pAfRd);
1735 if (cbErrno != 0)
1736 {
1737 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
1738 //SW_BREAKPOINT; // temporary//QIN - need to put underflow stats counter here.
1739 }
1740 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
1742 // FL: debug
1743 //cbLog(pCb, 0);
1744 //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
1745 //{
1746 // Log_info0("capAfWrite() error");
1747 //}
1748 }
1750 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
1751 errno = pP->fxns->streamChainFunction(pP, pQ, pC,
1752 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
1753 if (errno)
1754 {
1755 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
1756 return errno;
1757 }
1759 return 0;
1761 } //PAF_ASOT_decodeStream
1763 // -----------------------------------------------------------------------------
1764 // ASOT Decoding Function - Encode Processing
1765 //
1766 // Name: PAF_ASOT_decodeEncode
1767 // Purpose: Decoding Function for processing of audio frame data by the
1768 // Encode Algorithm.
1769 // From: AST Parameter Function -> decodeProcessing
1770 // Uses: See code.
1771 // States: x
1772 // Return: Error number in standard or SIO form (0 on success).
1773 // Trace: Message Log "trace" in Debug Project Configuration reports:
1774 // * State information as per parent.
1775 //
1776 Int
1777 PAF_ASOT_decodeEncode(
1778 const PAF_AST_Params *pP,
1779 const PAF_AST_Patchs *pQ,
1780 PAF_AST_Config *pC,
1781 Int frame,
1782 Int block
1783 )
1784 {
1785 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1786 Int z; /* encode/output counter */
1787 Int errno; /* error number */
1788 Int zX, zE, zS;
1789 UInt32 curTime;
1792 // Await output buffers (but not first time)
1793 for (z=OUTPUT1; z < OUTPUTN; z++)
1794 {
1795 // determine encoder associated with this output
1796 zE = z;
1797 for (zX = ENCODE1; zX < ENCODEN; zX++)
1798 {
1799 if (pP->outputsFromEncodes[zX] == z)
1800 {
1801 zE = zX;
1802 break;
1803 }
1804 }
1805 zS = pP->streamsFromEncodes[zE];
1807 if (pC->xOut[z].hTxSio)
1808 {
1809 // update length (e.g. ARC may have changed)
1810 pC->xOut[z].outBufConfig.lengthofFrame =
1811 pC->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
1812 TRACE_GEN2("AS%d: PAF_AST_outputEncode: processing block %d -- idle", as+zS, block);
1813 errno = SIO_reclaim(pC->xOut[z].hTxSio,(Ptr *) &pC->xOut[z].pOutBuf, NULL);
1814 if (errno < 0)
1815 {
1816 SIO_idle(pC->xOut[z].hTxSio);
1817 TRACE_TERSE2("PAF_AST_outputEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
1818 return -errno; // SIO negates error codes
1819 }
1820 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
1822 //
1823 // Simulate Tx SIO_reclaim() pend
1824 //
1825 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
1826 gTaskAsopCnt++;
1827 curTime = Clock_getTicks();
1828 //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
1829 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
1830 }
1831 else
1832 {
1833 TRACE_VERBOSE2("AS%d: PAF_AST_outputEncode: processing block %d -- idle <ignored>", as+zS, block);
1834 }
1835 }
1837 // Encode data
1838 for (z=ENCODE1; z < ENCODEN; z++)
1839 {
1840 Int zO = pP->outputsFromEncodes[z];
1841 Int zS = pP->streamsFromEncodes[z];
1842 (void)zS; // clear compiler warning in case not used with tracing disabled
1843 if (pC->xOut[zO].hTxSio && pC->xEnc[z].encodeStatus.mode)
1844 {
1845 Int select = pC->xEnc[z].encodeStatus.select;
1846 ALG_Handle encAlg = pC->xEnc[z].encAlg[select];
1847 ENC_Handle enc = (ENC_Handle )encAlg;
1848 if (select != pC->xEnc[z].encodeControl.encActive)
1849 {
1850 pC->xEnc[z].encodeControl.encActive = select;
1851 TRACE_TERSE0("PAF_AST_outputEncode: return error");
1852 return (-1);
1853 }
1854 TRACE_GEN2("AS%d: PAF_AST_outputEncode: processing block %d -- encode", as+zS, block);
1856 // (MID 1933) temp. workaround for PCE2
1857 pC->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1859 /*
1860 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1861 {
1862 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
1863 int *wp;
1864 wp = (int*)pAudioFrame->data.sample[0];
1865 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
1866 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
1867 wp = (int*)pAudioFrame->data.sample[1];
1868 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
1869 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
1870 wp = (int*)pAudioFrame->data.sample[2];
1871 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
1872 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
1873 }
1874 #endif
1875 */
1877 if (enc->fxns->encode)
1878 {
1879 pC->xEnc[z].encodeOutStruct.bypassFlag =
1880 pP->z_pEncodeStatus[z]->encBypass;
1881 if (errno = enc->fxns->encode(enc, NULL,
1882 &pC->xEnc[z].encodeInStruct, &pC->xEnc[z].encodeOutStruct))
1883 {
1884 if (errno != PCEERR_OUTPUT_POINTERNULL)
1885 {
1886 TRACE_TERSE1("PAF_AST_outputEncode: return error %d line %d", errno);
1887 return errno;
1888 }
1889 }
1890 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1891 else
1892 {
1893 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
1894 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
1895 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
1896 }
1897 #endif
1898 */
1899 }
1900 }
1901 else
1902 {
1903 TRACE_VERBOSE2("AS%d: PAF_AST_outputEncode: processing block %d -- encode <ignored>",
1904 as+pP->streamsFromEncodes[z], block);
1905 }
1906 }
1908 // Transmit data
1909 for (z=OUTPUT1; z < OUTPUTN; z++)
1910 {
1911 // determine encoder associated with this output
1912 zE = z;
1913 for (zX = ENCODE1; zX < ENCODEN; zX++)
1914 {
1915 if (pP->outputsFromEncodes[zX] == z)
1916 {
1917 zE = zX;
1918 break;
1919 }
1920 }
1921 zS = pP->streamsFromEncodes[zE];
1923 if (pC->xOut[z].hTxSio)
1924 {
1925 TRACE_GEN2("AS%d: PAF_AST_outputEncode: processing block %d -- output", as+zS, block);
1926 errno = SIO_issue(pC->xOut[z].hTxSio,
1927 &pC->xOut[z].outBufConfig, sizeof (pC->xOut[z].outBufConfig), 0);
1928 if (errno)
1929 {
1930 SIO_idle(pC->xOut[z].hTxSio);
1931 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
1932 {
1933 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
1934 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
1935 }
1936 if (errno > 0)
1937 {
1938 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
1939 return (ASPERR_ISSUE + (z << 4));
1940 }
1941 else if (errno < 0)
1942 {
1943 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
1944 return -errno; // SIO negates error codes
1945 }
1946 }
1947 if (errno > 0)
1948 {
1949 return (ASPERR_ISSUE + (z << 4));
1950 }
1951 else if (errno < 0)
1952 {
1953 return -errno; // SIO negates error codes
1954 }
1955 }
1956 else
1957 {
1958 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- output <ignored>", as+zS, block);
1959 }
1960 }
1962 return 0;
1963 } //PAF_ASOT_decodeEncode
1965 // -----------------------------------------------------------------------------
1966 // ASOT Decoding Function - Stream-Final Processing
1967 //
1968 // Name: PAF_ASOT_decodeComplete
1969 // Purpose: Decoding Function for terminating the decoding process.
1970 // From: AST Parameter Function -> decodeProcessing
1971 // Uses: See code.
1972 // States: x
1973 // Return: 0.
1974 // Trace: Message Log "trace" in Debug Project Configuration reports:
1975 // * State information as per parent.
1976 //
1977 Int
1978 PAF_ASOT_decodeComplete(
1979 const PAF_AST_Params *pP,
1980 const PAF_AST_Patchs *pQ,
1981 PAF_AST_Config *pC,
1982 ALG_Handle decAlg[],
1983 Int frame,
1984 Int block
1985 )
1986 {
1987 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1988 Int z; /* decode/encode counter */
1989 Int errno; /* error number */
1990 PAF_DecodeOpCircBuf *pCb; /* decoder output circular buffer */
1992 (void)as; // clear compiler warning in case not used with tracing disabled
1994 for (z=DECODE1; z < DECODEN; z++)
1995 {
1996 // Stop decoder output circular buffer reads
1997 pCb = &pC->xDec[z].decOpCb;
1998 errno = cbReadStop(pCb);
1999 if (errno)
2000 {
2001 return errno;
2002 }
2003 }
2005 pP->fxns->streamChainFunction(pP, pQ, pC, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2007 for (z=ENCODE1; z < ENCODEN; z++)
2008 {
2009 Int zO = pP->outputsFromEncodes[z];
2010 if (pC->xOut[zO].hTxSio && pC->xEnc[z].encodeStatus.mode)
2011 {
2012 Int select = pC->xEnc[z].encodeStatus.select;
2013 ALG_Handle encAlg = pC->xEnc[z].encAlg[select];
2014 #ifdef PAF_ASP_FINAL
2015 ENC_Handle enc = (ENC_Handle)encAlg;
2016 #endif /* PAF_ASP_FINAL */
2017 TRACE_VERBOSE1("PAF_AST_decodeComplete: AS%d: finalizing encode", as+z);
2018 #ifdef PAF_ASP_FINAL
2019 if (enc->fxns->final)
2020 enc->fxns->final(enc, NULL, &pC->xEnc[z].encodeControl,
2021 &pC->xEnc[z].encodeStatus);
2022 #endif /* PAF_ASP_FINAL */
2023 if (encAlg->fxns->algDeactivate)
2024 {
2025 encAlg->fxns->algDeactivate(encAlg);
2026 }
2027 }
2028 else
2029 {
2030 TRACE_VERBOSE1("PAF_AST_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2031 }
2032 }
2034 // wait for remaining data to be output
2035 pP->fxns->stopOutput(pP, pQ, pC);
2037 return 0;
2038 } //PAF_ASOT_decodeComplete
2040 // -----------------------------------------------------------------------------
2041 // ASOT Decoding Function Helper - SIO Driver Start
2042 //
2043 // Name: PAF_ASOT_startOutput
2044 // Purpose: Decoding Function for initiating output.
2045 // From: AST Parameter Function -> decodeInfo1
2046 // Uses: See code.
2047 // States: x
2048 // Return: Error number in standard or SIO form (0 on success).
2049 // Trace: Message Log "trace" in Debug Project Configuration reports:
2050 // * State information as per parent.
2051 // * SIO control errors.
2052 //
2053 #define DEC_OUTNUMBUF_MAP(X) \
2054 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2056 Int
2057 PAF_ASOT_startOutput(
2058 const PAF_AST_Params *pP,
2059 const PAF_AST_Patchs *pQ,
2060 PAF_AST_Config *pC
2061 )
2062 {
2063 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2064 Int z; /* output counter */
2065 Int errno,nbufs; /* error number */
2066 Int zE, zS, zX;
2067 Int zMD = pC->masterDec;
2068 PAF_SIO_IALG_Obj *pObj;
2069 PAF_SIO_IALG_Config *pAlgConfig;
2072 for (z=OUTPUT1; z < OUTPUTN; z++)
2073 {
2074 if (pC->xOut[z].hTxSio)
2075 {
2076 // determine associated encoder and stream
2077 zE = z;
2078 zS = z;
2079 for (zX = ENCODE1; zX < ENCODEN; zX++)
2080 {
2081 if (pP->outputsFromEncodes[zX] == z)
2082 {
2083 zE = zX;
2084 zS = pP->streamsFromEncodes[zE];
2085 break;
2086 }
2087 }
2089 // Set sample count so that DOB knows how much data to send
2090 pC->xOut[z].outBufConfig.lengthofFrame =
2091 pC->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2093 if (pC->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
2094 {
2095 pObj = (PAF_SIO_IALG_Obj *) pC->xOut[z].outChainData.head->alg;
2096 pAlgConfig = &pObj->config;
2097 memset(pC->xOut[z].outBufConfig.base.pVoid, 0xAA,
2098 pAlgConfig->pMemRec[0].size);
2099 }
2101 // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
2102 // decoder. How should we handle the sourceProgram for multiple decoders?
2103 // Override as needed
2104 nbufs = DEC_OUTNUMBUF_MAP(pC->xDec[zMD].decodeStatus.sourceProgram);
2105 if (pC->xOut[z].outBufStatus.numBufOverride[pC->xDec[zMD].decodeStatus.sourceProgram] > 0)
2106 {
2107 nbufs = pC->xOut[z].outBufStatus.numBufOverride[pC->xDec[zMD].decodeStatus.sourceProgram];
2108 }
2109 SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
2111 if (errno = SIO_issue(pC->xOut[z].hTxSio,
2112 &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0))
2113 {
2114 SIO_idle(pC->xOut[z].hTxSio);
2115 TRACE_TERSE2("PAF_AST_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
2116 return errno;
2117 }
2119 if (!(pC->xOut[z].outBufStatus.audio & 0xf0) &&
2120 (errno = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2121 {
2122 errno = (errno & 0xff) | ASPERR_MUTE;
2123 /* convert to sensical errno */
2124 TRACE_TERSE2("as1-f2: PAF_AST_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
2125 return (errno);
2126 }
2127 else
2128 {
2129 pC->xOut[z].outBufStatus.audio
2130 = (pC->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
2131 }
2133 TRACE_VERBOSE1("PAF_AST_startOutput: AS%d: output started", as+zS);
2134 }
2135 }
2137 return 0;
2138 } //PAF_ASOT_startOutput
2140 // -----------------------------------------------------------------------------
2141 // ASOT Decoding Function Helper - SIO Driver Stop
2142 //
2143 // Name: PAF_ASOT_stopOutput
2144 // Purpose: Decoding Function for terminating output.
2145 // From: AST Parameter Function -> decodeProcessing
2146 // AST Parameter Function -> decodeComplete
2147 // Uses: See code.
2148 // States: x
2149 // Return: Error number in standard or SIO form (0 on success).
2150 // Trace: Message Log "trace" in Debug Project Configuration reports:
2151 // * SIO control errors.
2152 //
2153 Int
2154 PAF_ASOT_stopOutput(
2155 const PAF_AST_Params *pP,
2156 const PAF_AST_Patchs *pQ,
2157 PAF_AST_Config *pC
2158 )
2159 {
2160 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2161 Int z; /* output counter */
2162 Int errno = 0, getVal;
2163 Int zS, zX;
2164 PAF_SIO_IALG_Obj *pObj;
2165 PAF_SIO_IALG_Config *pAlgConfig;
2167 (void)as; // clear compiler warning in case not used with tracing disabled
2169 for (z=OUTPUT1; z < OUTPUTN; z++)
2170 {
2171 if (pC->xOut[z].hTxSio)
2172 {
2173 // determine associated encoder and stream
2174 zS = z;
2175 (void)zS;
2176 for (zX = ENCODE1; zX < ENCODEN; zX++)
2177 {
2178 if (pP->outputsFromEncodes[zX] == z)
2179 {
2180 zS = pP->streamsFromEncodes[zX];
2181 break;
2182 }
2183 }
2185 // Mute output before audio data termination in the usual case,
2186 // where such termination is due to decode error or user command.
2187 // Identification of this as the usual case is provided by the
2188 // "decode processing" state machine.
2189 if (!(pC->xOut[z].outBufStatus.audio & 0xf0) &&
2190 ((pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND) &&
2191 (getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2192 {
2193 if (!errno)
2194 {
2195 errno = (getVal & 0xff) | ASPERR_MUTE;
2196 /* convert to sensical errno */
2197 }
2198 TRACE_VERBOSE1("PAF_ASIT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2199 }
2201 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- begin PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2203 // Terminate audio data output, truncating (ignore) or flushing
2204 // (play out) final samples as per (1) control register set by
2205 // the user and (2) the type of audio data termination:
2207 #if 0
2208 // This form is not used because driver support for truncating
2209 // data is not supported for internal clocks, although it is
2210 // for external clocks.
2211 getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2212 pC->xOut[z].outBufStatus.flush
2213 & (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2214 ? 1 : 0);
2215 /* UNTESTED */
2216 #else
2217 // This form should be used when driver support for truncating
2218 // data is supported for both internal and external clocks.
2219 getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2220 pC->xOut[z].outBufStatus.flush ? 1 :
2221 (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2222 ? 1 : 0);
2223 /* TESTED */
2224 #endif
2226 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- after PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2228 if (!errno)
2229 {
2230 errno = getVal;
2231 }
2233 // Mute output after audio data termination in a special case,
2234 // where such termination is due to processing of a final frame
2235 // or user command. Identification of this as a special case is
2236 // provided by the "decode processing" state machine.
2237 if (!(pC->xOut[z].outBufStatus.audio & 0xf0) &&
2238 ((pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH) &&
2239 (getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2240 {
2241 if (!errno)
2242 {
2243 errno = (getVal & 0xff) | ASPERR_MUTE;
2244 /* convert to sensical errno */
2245 }
2246 TRACE_VERBOSE1("as1-f2: PAF_AST_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2247 }
2249 pC->xOut[z].outBufStatus.audio &= ~0x0f;
2251 // zero output buffers
2252 pObj = (PAF_SIO_IALG_Obj *) pC->xOut[z].outChainData.head->alg;
2253 pAlgConfig = &pObj->config;
2254 memset (pC->xOut[z].outBufConfig.base.pVoid, 0, pAlgConfig->pMemRec[0].size);
2255 } //pC->xOut[z].hTxSio
2256 }//OUTPUT
2258 return errno;
2259 } //PAF_AST_stopOutput
2261 // -----------------------------------------------------------------------------
2262 // ASOT Decoding Function Helper - SIO Driver Change
2263 //
2264 // Name: PAF_ASOT_setCheckRateX
2265 // Purpose: Decoding Function for reinitiating output.
2266 // From: AST Parameter Function -> decodeInfo1
2267 // AST Parameter Function -> decodeInfo2
2268 // Uses: See code.
2269 // States: x
2270 // Return: Error number in standard form (0 on success).
2271 // Trace: None.
2272 //
2274 /* 0: set, 1: check, unused for now. --Kurt */
2275 Int
2276 PAF_ASOT_setCheckRateX(
2277 const PAF_AST_Params *pP,
2278 const PAF_AST_Patchs *pQ,
2279 PAF_AST_Config *pC,
2280 Int check
2281 )
2282 {
2283 float rateX;
2284 PAF_SampleRateHz rateO /* std */, rateI /* inv */;
2285 Int z; /* output counter */
2286 Int zx; /* output re-counter */
2287 Int getVal;
2288 int inputRate, inputCount, outputRate, outputCount;
2289 Int zMD = pC->masterDec;
2290 Int zMI = pP->zone.master;
2291 Int zMS = pC->masterStr;
2292 Int zE, zX;
2295 inputRate = pC->xInp[zMI].inpBufStatus.sampleRateStatus;
2296 inputCount = pC->xDec[zMD].decodeStatus.frameLength;
2297 rateI = pC->xStr[zMS].pAudioFrame->fxns->sampleRateHz
2298 (pC->xStr[zMS].pAudioFrame, inputRate, PAF_SAMPLERATEHZ_INV);
2300 for (z=OUTPUT1; z < OUTPUTN; z++) {
2301 if (pC->xOut[z].hTxSio && (pC->xOut[z].outBufStatus.clock & 0x01)) {
2303 // determine associated encoder
2304 zE = z;
2305 for (zX = ENCODE1; zX < ENCODEN; zX++) {
2306 if (pP->outputsFromEncodes[zX] == z) {
2307 zE = zX;
2308 break;
2309 }
2310 }
2312 outputRate = pC->xEnc[zE].encodeStatus.sampleRate;
2313 outputCount = pC->xEnc[zE].encodeStatus.frameLength;
2314 rateO = pC->xStr[zMS].pAudioFrame->fxns->sampleRateHz
2315 (pC->xStr[zMS].pAudioFrame, outputRate, PAF_SAMPLERATEHZ_STD);
2316 if (rateI > 0 && rateO > 0)
2317 rateX = rateO /* std */ * rateI /* inv */;
2318 else if (inputCount != 0)
2319 rateX = (float )outputCount / inputCount;
2320 else
2321 return ( ASPERR_INFO_RATERATIO );
2323 getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg) &rateX);
2324 if (getVal == DOBERR_RATECHANGE) {
2325 for (zx=OUTPUT1; zx < OUTPUTN; zx++)
2326 if (pC->xOut[zx].hTxSio)
2327 SIO_idle (pC->xOut[zx].hTxSio);
2329 // this forces an exit from the calling state machine which will
2330 // eventually call startOutput which calls setCheckRateX for all outputs
2331 // and so it is ok, in the presence of a rate change on any output, to
2332 // exit this loop /function early.
2333 return ASPERR_INFO_RATECHANGE;
2334 }
2335 else if( getVal != SYS_OK )
2336 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
2337 }
2338 }
2340 return 0;
2341 } //PAF_ASOT_setCheckRateX
2343 // -----------------------------------------------------------------------------
2344 // ASOT Decoding Function Helper - Chain Processing
2345 //
2346 // Name: PAF_ASOT_streamChainFunction
2347 // Purpose: Common Function for processing algorithm chains.
2348 // From: AST Parameter Function -> decodeInfo1
2349 // AST Parameter Function -> decodeStream
2350 // AST Parameter Function -> decodeComplete
2351 // Uses: See code.
2352 // States: x
2353 // Return: Error number in standard form (0 on success).
2354 // Trace: Message Log "trace" in Debug Project Configuration reports:
2355 // * State information as per parent.
2356 //
2357 Int
2358 PAF_ASOT_streamChainFunction(
2359 const PAF_AST_Params *pP,
2360 const PAF_AST_Patchs *pQ,
2361 PAF_AST_Config *pC,
2362 Int iChainFrameFxns,
2363 Int abortOnError,
2364 Int logArg
2365 )
2366 {
2367 Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2368 Int z; /* stream counter */
2369 Int errno; /* error number */
2370 Int dFlag, eFlag, gear;
2371 Int zX;
2372 Int zS;
2374 (void)as; // clear compiler warning in case not used with tracing disabled
2376 for (zS = STREAM1; zS < STREAMN; zS++)
2377 {
2378 z = pP->streamOrder[zS]; // Select stream order from streamOrder parameter - MID 788
2380 // apply stream
2381 // unless the stream is associated with a decoder and it is not running
2382 // or
2383 // unless the stream is associated with an encoder and it is not running
2384 // Also gear control only works for streams with an associated decoder
2385 // if no such association exists then gear 0 (All) is used
2386 dFlag = 1;
2387 gear = 0;
2388 for (zX = DECODE1; zX < DECODEN; zX++) {
2389 if (pP->streamsFromDecodes[zX] == z) {
2390 dFlag = pC->xDec[zX].decodeStatus.mode;
2391 gear = pC->xDec[zX].decodeStatus.aspGearStatus;
2392 break;
2393 }
2394 }
2395 eFlag = 1;
2396 for (zX = ENCODE1; zX < ENCODEN; zX++) {
2397 if (pP->streamsFromEncodes[zX] == z) {
2398 eFlag = pC->xEnc[zX].encodeStatus.mode;
2399 break;
2400 }
2401 }
2403 if (dFlag && eFlag) {
2404 PAF_ASP_Chain *chain = pC->xStr[z].aspChain[gear];
2405 PAF_AudioFrame *frame = pC->xStr[z].pAudioFrame;
2406 Int (*func) (PAF_ASP_Chain *, PAF_AudioFrame *) =
2407 chain->fxns->chainFrameFunction[iChainFrameFxns];
2409 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
2410 ? "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (reset)"
2411 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
2412 ? "AS%d: PAF_AST_streamChainFunction: processing block %d -- audio stream (apply)"
2413 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
2414 ? "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (final)"
2415 : "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (?????)",
2416 as+z, logArg);
2417 errno = (*func) (chain, frame);
2418 TRACE_VERBOSE2("AS%d: PAF_AST_streamChainFunction: errno 0x%x.",
2419 as+z, errno);
2421 if (errno && abortOnError)
2422 return errno;
2423 }
2424 else {
2425 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
2426 ? "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (reset) <ignored>"
2427 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
2428 ? "AS%d: PAF_AST_streamChainFunction: processing block %d -- audio stream (apply) <ignored>"
2429 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
2430 ? "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (final) <ignored>"
2431 : "AS%d: PAF_AST_streamChainFunction: processing frame %d -- audio stream (?????) <ignored>",
2432 as+z, logArg);
2433 }
2435 /*
2436 {
2437 void dp_tracePAF_Data(float *lBuf, float *rBuf, int count);
2438 PAF_AudioFrameData *afd;
2439 float ** afPtr;
2441 afd = &(pC->xStr->pAudioFrame->data);
2442 afPtr = (float**)afd->sample;
2443 dp_tracePAF_Data(afPtr[4], afPtr[5], 256);
2445 }
2446 */
2448 }
2450 return 0;
2451 } //PAF_AST_streamChainFunction
2453 /* FL: Check if at least one output selected */
2454 static Int checkOutSel(
2455 const PAF_AST_Params *pP,
2456 PAF_AST_Config *pC,
2457 Int *pOutSel
2458 )
2459 {
2460 Int outSel;
2461 Int z;
2463 outSel = 0;
2464 for (z=OUTPUT1; z < OUTPUTN; z++)
2465 {
2466 if (pC->xOut[z].hTxSio)
2467 {
2468 outSel = 1;
2469 break;
2470 }
2471 }
2473 *pOutSel = outSel;
2475 return 0;
2476 }
2478 /* FL: Check if at least one output sio changed */
2479 static Int checkOutSio(
2480 const PAF_AST_Params *pP,
2481 PAF_AST_Config *pC,
2482 Int *pOutSioUpdate
2483 )
2484 {
2485 Int outSioUpdate;
2486 Int z;
2488 outSioUpdate = 0;
2489 for (z=OUTPUT1; z < OUTPUTN; z++)
2490 {
2491 if (pC->xOut[z].outBufStatus.sioSelect >= 0)
2492 {
2493 outSioUpdate = 1;
2494 break;
2495 }
2496 }
2498 *pOutSioUpdate = outSioUpdate;
2500 return 0;
2501 }