9ff831a028aac8008d8abdabe96bc0035c7f7260
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamOutProc.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamOutProc.c ========
38 */
40 #include <string.h> // for memset
41 #include <xdc/runtime/Log.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Memory.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Task.h>
47 #include "paferr.h"
48 #include <acp_mds.h>
49 #include <pcm.h>
50 #include <pce.h>
51 #include <pafsio_ialg.h>
52 #include <stdasp.h>
53 #include <doberr.h>
54 #include "asperr.h"
56 #include "common.h"
57 #include "aspMsg_common.h"
58 #include "aspMsg_master.h"
59 #include "aspDecOpCircBuf_master.h"
60 #include "audioStreamProc_common.h"
61 #include "audioStreamOutProc.h"
63 #define TRACE_TIME(a)
65 //
66 // Audio Stream Definitions
67 //
69 //
70 // Audio Stream Processing Definitions
71 //
72 #define aspLinkInit pQ->i_aspLinkInit
74 //
75 // Encoder Definitions
76 //
77 #define encLinkInit pQ->i_encLinkInit
79 //
80 // Output Definitions
81 //
82 #define outLinkInit pP->i_outLinkInit
84 /* ---------------------------------------------------------------- */
85 /* Parameter macro definitions end here. */
86 /* ---------------------------------------------------------------- */
88 //
89 // Standardized Definitions
90 //
92 #define ENC_Handle PCE_Handle /* works for all: PCE */
94 #define __TASK_NAME__ "TaskAsop"
97 /* FL: Check if at least one output selected */
98 static Int checkOutSel(
99 const PAF_ASOT_Params *pP,
100 PAF_ASOT_Config *pC,
101 Int *pOutSel
102 );
104 /* FL: Check if at least one output sio changed */
105 static Int checkOutSio(
106 const PAF_ASOT_Params *pP,
107 PAF_ASOT_Config *pC,
108 Int *pOutSioUpdate
109 );
111 LINNO_DEFN(TaskAsop); /* Line number macros */
112 ERRNO_DEFN(TaskAsop); /* Error number macros */
114 // ASOT configuration
115 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
116 PAF_ASOT_Config gPAF_ASOT_config = {
117 NULL, // acp
118 &gPAF_ASPM_config, // pAspmCfg
119 &gPAF_AST_config // pAstCfg
120 };
122 // Global debug counters */
123 UInt32 gTaskAsopCnt=0; // debug
124 UInt32 gAsopInitCnt =0;
125 UInt32 gAsopStreamCnt =0;
126 UInt32 gAsopEncodeCnt =0;
127 UInt32 gAsopFinalCnt =0;
128 UInt32 gAsopQuitCnt =0;
131 /*
132 * ======== taskAsopFxn ========
133 * Audio Stream Output Processing task function
134 */
135 Void taskAsopFxn(
136 // Int betaPrimeValue, // FL: revisit
137 const PAF_ASOT_Params *pP,
138 const PAF_ASOT_Patchs *pQ
139 )
140 {
141 PAF_ASOT_Config *pC; /* Local configuration pointer */
142 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
143 Int as; /* Audio Stream Number (1, 2, etc.) */
144 Int z; /* input/encode/stream/decode/output counter */
145 Int i; /* phase */
146 Int errno; /* error number */
147 Int zMS;
148 Int loopCount = 0; // used to stop trace to see startup behavior.
150 Log_info0("Enter taskAsopFxn()");
152 //
153 // Audio Framework Parameters & Patch (*pP, *pQ)
154 //
155 if (!pP)
156 {
157 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
158 LINNO_RPRT(TaskAsop, -1);
159 return;
160 }
162 if (!pQ)
163 {
164 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
165 LINNO_RPRT(TaskAsop, -1);
166 return;
167 }
169 //
170 // Audio Framework Configuration (*pC):
171 //
172 pC = &gPAF_ASOT_config;
173 pAstCfg = pC->pAstCfg;
175 /* Obtain Audio Stream Number (1, 2, etc.) */
176 as = pAstCfg->as;
177 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
179 //
180 // Initialize message log trace and line number reporting
181 //
182 for (z=STREAM1; z < STREAMN; z++)
183 {
184 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
185 }
186 LINNO_RPRT(TaskAsop, -1);
188 //
189 // Determine stream index
190 //
191 zMS = pAstCfg->masterStr;
193 // Initialize as per parametrized phases:
194 //
195 // In standard form these are:
196 // - Malloc: Memory Allocation
197 // - Config: Configuration Initialization
198 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
199 // - Common: Common Memory Initialization
200 // - AlgKey: Dec/Enc chain to Array Initialization
201 // - Device: I/O Device Initialization
202 // - Unused: (available)
203 // - Unused: (available)
204 //
205 LINNO_RPRT(TaskAsop, -2);
206 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
207 {
208 Int linno;
209 if (pP->fxns->initPhase[i])
210 {
211 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
212 {
213 LINNO_RPRT(TaskAsop, linno);
214 return;
215 }
216 }
217 else
218 {
219 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
220 }
221 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
222 LINNO_RPRT(TaskAsop, -i-3);
223 }
225 //
226 // End of Initialization -- display memory usage report.
227 //
228 if (pP->fxns->memStatusPrint)
229 {
230 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
231 }
233 //
234 // Main processing loop
235 //
236 for (z=STREAM1; z < STREAMN; z++)
237 {
238 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
239 }
241 errno = 0;
242 for (;;)
243 {
244 Int outSel;
246 loopCount++;
247 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
249 // any error forces idling of output
250 if (errno)
251 {
252 for (z=OUTPUT1; z < OUTPUTN; z++)
253 {
254 if (pAstCfg->xOut[z].hTxSio)
255 {
256 SIO_idle(pAstCfg->xOut[z].hTxSio);
257 }
258 }
260 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
261 ERRNO_RPRT(TaskAsop, errno);
262 }
264 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
265 Task_sleep(1);
267 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
268 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
269 {
270 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
271 continue;
272 }
274 // if no output selected skip any remaining processing
275 if (errno = checkOutSel(pP, pC, &outSel))
276 {
277 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
278 continue;
279 }
280 else if (!outSel)
281 {
282 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
283 continue;
284 }
286 TRACE_VERBOSE0("TaskAsop: calling outputProcessing.");
287 errno = pP->fxns->decodeProcessing(pP, pQ, pC, -1);
288 if (errno)
289 {
290 TRACE_TERSE1("TaskAsop: outputProcessing returns 0x%x, continue", errno);
291 }
292 else
293 {
294 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
295 }
296 } // End of main processing loop for (;;)
298 Log_info0("Exit taskAsopFxn()");
299 }
301 // -----------------------------------------------------------------------------
302 // AST Initialization Function - Memory Allocation
303 //
304 // Name: PAF_ASOT_initPhaseMalloc
305 // Purpose: Audio Stream Output Task Function for initialization of data pointers
306 // by allocation of memory.
307 // From: audioStream1Task or equivalent
308 // Uses: See code.
309 // States: x
310 // Return: 0 on success.
311 // Source code line number on MEM_calloc failure.
312 // Trace: Message Log "trace" in Debug Project Configuration reports:
313 // * State information as per parent.
314 // * Memory allocation errors.
315 //
317 Int
318 PAF_ASOT_initPhaseMalloc (
319 const PAF_ASOT_Params *pP,
320 const PAF_ASOT_Patchs *pQ,
321 PAF_ASOT_Config *pC
322 )
323 {
324 PAF_AST_Config *pAstCfg;
325 Int as; /* Audio Stream Number (1, 2, etc.) */
326 Int zMS;
327 Error_Block eb;
328 //Int i;
330 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
331 as = pAstCfg->as;
332 zMS = pAstCfg->masterStr;
334 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
336 // Initialize error block
337 Error_init(&eb);
339 /* Stream memory */
340 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
341 {
342 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
343 SW_BREAKPOINT;
344 return __LINE__;
345 }
346 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
347 STREAMN * sizeof (*pAstCfg->xStr),
348 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
350 {
351 Int z; /* stream counter */
353 PAF_AudioFrame *fBuf;
355 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
356 {
357 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
358 SW_BREAKPOINT;
359 return __LINE__;
360 }
361 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
362 STREAMS * sizeof (*fBuf),
363 HEAP_ID_INTERNAL, (IArg)fBuf);
365 for (z=STREAM1; z < STREAMN; z++)
366 {
367 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
368 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
369 }
370 }
372 /* Encode memory */
373 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
374 {
375 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
376 SW_BREAKPOINT;
377 return __LINE__;
378 }
379 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
380 ENCODEN * sizeof (*pAstCfg->xEnc),
381 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
383 /* Output memory */
384 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
385 {
386 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
387 SW_BREAKPOINT;
388 return __LINE__;
389 }
390 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
391 OUTPUTN * sizeof (*pAstCfg->xOut),
392 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
394 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
395 return 0;
396 } //PAF_ASOT_initPhaseMalloc
398 // -----------------------------------------------------------------------------
399 // ASOT Initialization Function - Memory Initialization from Configuration
400 //
401 // Name: PAF_ASOT_initPhaseConfig
402 // Purpose: Audio Stream Output Task Function for initialization of data values
403 // from parameters.
404 // From: audioStream1Task or equivalent
405 // Uses: See code.
406 // States: x
407 // Return: 0 on success.
408 // Other as per initFrame0 and initFrame1.
409 // Trace: Message Log "trace" in Debug Project Configuration reports:
410 // * State information as per parent.
411 //
412 Int
413 PAF_ASOT_initPhaseConfig(
414 const PAF_ASOT_Params *pP,
415 const PAF_ASOT_Patchs *pQ,
416 PAF_ASOT_Config *pC
417 )
418 {
419 PAF_AST_Config *pAstCfg;
420 Int as; /* Audio Stream Number (1, 2, etc.) */
421 Int z; /* input/encode/stream/decode/output counter */
422 Int zMS;
424 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
425 as = pAstCfg->as;
426 zMS = pAstCfg->masterStr;
428 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
430 //
431 // Unspecified elements have been initialized to zero during alloc
432 //
434 for (z=STREAM1; z < STREAMN; z++)
435 {
436 Int linno;
437 if (linno = pP->fxns->initFrame0(pP, pQ, pC, z))
438 {
439 return linno;
440 }
441 if (linno = pP->fxns->initFrame1(pP, pQ, pC, z, -1))
442 {
443 return linno;
444 }
445 }
447 for (z=ENCODE1; z < ENCODEN; z++)
448 {
449 Int zO = pP->outputsFromEncodes[z];
450 Int zS = pP->streamsFromEncodes[z];
451 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
452 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
453 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
454 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
455 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
456 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
457 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
458 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
459 }
461 for (z=OUTPUT1; z < OUTPUTN; z++)
462 {
463 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
464 }
466 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
467 return 0;
468 } //PAF_ASOT_initPhaseConfig
470 // -----------------------------------------------------------------------------
471 // ASOT Initialization Function - ACP Algorithm Instantiation
472 //
473 // Name: PAF_ASOT_initPhaseAcpAlg
474 // Purpose: Audio Stream Input Task Function for initialization of ACP by
475 // instantiation of the algorithm.
476 // From: audioStream1Task or equivalent
477 // Uses: See code.
478 // States: x
479 // Return: 0 on success.
480 // Source code line number on ACP Algorithm creation failure.
481 // Trace: Message Log "trace" in Debug Project Configuration reports:
482 // * State information as per parent.
483 // * Memory allocation errors.
484 //
485 Int
486 PAF_ASOT_initPhaseAcpAlg(
487 const PAF_ASOT_Params *pP,
488 const PAF_ASOT_Patchs *pQ,
489 PAF_ASOT_Config *pC
490 )
491 {
492 PAF_AST_Config *pAstCfg;
493 Int as; /* Audio Stream Number (1, 2, etc.) */
494 Int z; /* input/encode/stream/decode/output counter */
495 Int betaPrimeOffset;
496 ACP_Handle acp;
497 Int zMS;
498 Int zS, zX;
500 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
501 as = pAstCfg->as;
502 zMS = pAstCfg->masterStr;
504 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
506 ACP_MDS_init();
508 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
509 {
510 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
511 return __LINE__;
512 }
513 pC->acp = acp;
515 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
516 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
518 for (z=ENCODE1; z < ENCODEN; z++)
519 {
520 zS = pP->streamsFromEncodes[z];
521 acp->fxns->attach(acp, ACP_SERIES_STD,
522 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
523 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
524 acp->fxns->attach(acp, ACP_SERIES_STD,
525 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
526 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
527 /* Ignore errors, not reported. */
528 }
530 for (z=OUTPUT1; z < OUTPUTN; z++)
531 {
532 zS = z;
533 for (zX = ENCODE1; zX < ENCODEN; zX++)
534 {
535 if (pP->outputsFromEncodes[zX] == z)
536 {
537 zS = pP->streamsFromEncodes[zX];
538 break;
539 }
540 }
541 acp->fxns->attach(acp, ACP_SERIES_STD,
542 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
543 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
544 /* Ignore errors, not reported. */
545 }
547 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
549 return 0;
550 } //PAF_ASOT_initPhaseAcpAlg
552 // -----------------------------------------------------------------------------
553 // ASOT Initialization Function - Common Memory
554 //
555 // Name: PAF_ASOT_initPhaseCommon
556 // Purpose: Audio Stream Output Task Function for allocation of common memory.
557 // From: audioStream1Task or equivalent
558 // Uses: See code.
559 // States: x
560 // Return: 0 on success.
561 // Source code line number on PAF_ALG_alloc failure.
562 // Source code line number on PAF_ALG_mallocMemory failure.
563 // Source code line number on Decode Chain initialization failure.
564 // Source code line number on ASP Chain initialization failure.
565 // Source code line number on Encode Chain initialization failure.
566 // Trace: Message Log "trace" in Debug Project Configuration reports:
567 // * State information as per parent.
568 // * Memory allocation errors.
569 //
570 Int
571 PAF_ASOT_initPhaseCommon(
572 const PAF_ASOT_Params *pP,
573 const PAF_ASOT_Patchs *pQ,
574 PAF_ASOT_Config *pC
575 )
576 {
577 PAF_AST_Config *pAstCfg;
578 Int as; /* Audio Stream Number (1, 2, etc.) */
579 Int z; /* stream counter */
580 Int g; /* gear */
581 ACP_Handle acp;
582 PAF_IALG_Config pafAlgConfig;
583 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
585 acp = pC->acp;
586 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
587 as = pAstCfg->as;
589 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
591 //
592 // Determine memory needs and instantiate algorithms across audio streams
593 //
594 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
595 PAF_ALG_setup(&pafAlgConfig,
596 HEAP_ID_INTERNAL, HEAP_INTERNAL,
597 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
598 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
599 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
600 HEAP_CLEAR);
602 if (pP->fxns->headerPrint)
603 {
604 pP->fxns->headerPrint();
605 }
607 for (z = STREAM1; z < STREAMN; z++)
608 {
609 //Int zD, zE, zX;
610 Int zE, zX;
612 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
614 //
615 // Determine common memory needs for:
616 // (1) ASP Algorithms
617 // (2) Encode Algorithms
618 // (3) Logical Output drivers
619 //
620 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
622 zE = -1;
623 for (zX = ENCODE1; zX < ENCODEN; zX++)
624 {
625 if (pP->streamsFromEncodes[zX] == z)
626 {
627 zE = zX;
628 break;
629 }
630 }
632 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
633 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
634 {
635 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
636 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
637 SW_BREAKPOINT;
638 return __LINE__;
639 }
640 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
641 if (pP->fxns->allocPrint)
642 {
643 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
644 }
646 if (zE >= 0)
647 {
648 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
649 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
650 {
651 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
652 SW_BREAKPOINT;
653 return __LINE__;
654 }
655 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
656 if (pP->fxns->allocPrint)
657 {
658 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
659 }
660 }
662 //
663 // Determine common memory needs of Logical IO drivers
664 //
666 if (OUTPUT1 <= z && z < OUTPUTN)
667 {
668 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
669 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
670 {
671 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
672 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
673 SW_BREAKPOINT;
674 return __LINE__;
675 }
676 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
677 if (pP->fxns->allocPrint)
678 {
679 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
680 }
681 }
682 }
683 {
684 // Changes made to share scratch between zones
685 // Assume maximum 3 zones and scratch common memory is at offset 0;
686 int max=0;
687 for (z=STREAM1; z<STREAMN; z++)
688 {
689 if (max < common[z][0].size)
690 {
691 max = common[z][0].size;
692 }
693 }
694 common[STREAM1][0].size=max;
695 for (z=STREAM1+1; z<STREAMN; z++)
696 {
697 common[z][0].size = 0;
698 }
699 }
701 //
702 // Allocate common memory for:
703 // (1) ASP Algorithms
704 // (2) Encode Algorithms
705 // (3) Logical Output drivers
706 //
707 for (z = STREAM1; z < STREAMN; z++)
708 {
709 //Int zD, zE, zX;
710 Int zE, zX;
712 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
713 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
714 {
715 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
716 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
717 SW_BREAKPOINT;
718 return __LINE__;
719 }
720 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
721 // share zone0 scratch with all zones
722 common[z][0].base = common[0][0].base;
723 if (pP->fxns->commonPrint)
724 {
725 pP->fxns->commonPrint(common[z], &pafAlgConfig);
726 }
728 zE = -1;
729 for (zX = ENCODE1; zX < ENCODEN; zX++)
730 {
731 if (pP->streamsFromEncodes[zX] == z)
732 {
733 zE = zX;
734 break;
735 }
736 }
738 pAstCfg->xStr[z].aspChain[0] = NULL;
739 for (g=0; g < GEARS; g++)
740 {
741 PAF_ASP_Chain *chain;
742 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
743 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
744 HEAP_INTERNAL, as+z, acp, &trace,
745 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
746 if (!chain)
747 {
748 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
749 return __LINE__;
750 }
751 else
752 {
753 pAstCfg->xStr[z].aspChain[g] = chain;
754 }
755 }
757 if (zE >= 0)
758 {
759 PAF_ASP_Chain *chain;
760 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
761 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
762 HEAP_INTERNAL, as+z, acp, &trace,
763 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
764 if (!chain)
765 {
766 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
767 return __LINE__;
768 }
769 }
771 //
772 // Allocate non-common memories for Logical IO drivers
773 // Since these structures are used at run-time we allocate from external memory
774 if (OUTPUT1 <= z && z < OUTPUTN)
775 {
776 PAF_ASP_Chain *chain;
777 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
778 as+z, z);
779 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
780 HEAP_EXTERNAL, as+z, acp, &trace,
781 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
782 if (!chain)
783 {
784 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
785 return __LINE__;
786 }
787 }
788 }
789 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
791 return 0;
792 } //PAF_ASOT_initPhaseCommon
794 // -----------------------------------------------------------------------------
795 // ASOT Initialization Function - Algorithm Keys
796 //
797 // Name: PAF_ASOT_initPhaseAlgKey
798 // Purpose: Audio Stream Output Task Function for initialization of data values
799 // from parameters for Algorithm Keys.
800 // From: audioStream1Task or equivalent
801 // Uses: See code.
802 // States: x
803 // Return: 0.
804 // Trace: Message Log "trace" in Debug Project Configuration reports:
805 // * State information as per parent.
806 //
807 // .............................................................................
808 Int
809 PAF_ASOT_initPhaseAlgKey(
810 const PAF_ASOT_Params *pP,
811 const PAF_ASOT_Patchs *pQ,
812 PAF_ASOT_Config *pC
813 )
814 {
815 PAF_AST_Config *pAstCfg;
816 Int as; /* Audio Stream Number (1, 2, etc.) */
817 Int z; /* decode/encode counter */
818 Int s; /* key number */
819 PAF_ASP_Link *that;
821 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
822 as = pAstCfg->as;
823 (void)as; // clear compiler warning in case not used with tracing disabled
825 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
827 for (z=ENCODE1; z < ENCODEN; z++)
828 {
829 for (s=0; s < pP->pEncAlgKey->length; s++)
830 {
831 if ((pP->pEncAlgKey->code[s].full != 0) &&
832 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
833 {
834 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
835 }
836 /* Cast in interface, for now --Kurt */
837 else
838 {
839 pAstCfg->xEnc[z].encAlg[s] = NULL;
840 }
841 }
842 }
844 return 0;
845 } //PAF_ASOT_initPhaseAlgKey
847 // -----------------------------------------------------------------------------
848 // ASOT Initialization Function - I/O Devices
849 //
850 // Name: PAF_ASOT_initPhaseDevice
851 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
852 // From: audioStream1Task or equivalent
853 // Uses: See code.
854 // States: x
855 // Return: 0 on success.
856 // Source code line number on device allocation failure.
857 // Trace: Message Log "trace" in Debug Project Configuration reports:
858 // * State information as per parent.
859 // * Memory allocation errors.
860 //
861 Int
862 PAF_ASOT_initPhaseDevice(
863 const PAF_ASOT_Params *pP,
864 const PAF_ASOT_Patchs *pQ,
865 PAF_ASOT_Config *pC
866 )
867 {
868 PAF_AST_Config *pAstCfg;
869 Int as; /* Audio Stream Number (1, 2, etc.) */
870 Int z; /* input/output counter */
871 PAF_SIO_IALG_Obj *pObj;
872 PAF_SIO_IALG_Config *pAlgConfig;
873 PAF_IALG_Config pafAlgConfig;
875 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
876 as = pAstCfg->as;
877 (void)as; // clear compiler warning in case not used with tracing disabled
879 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
881 if(pP->fxns->bufMemPrint)
882 {
883 PAF_ALG_setup (&pafAlgConfig,
884 HEAP_ID_INTERNAL, HEAP_INTERNAL,
885 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
886 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
887 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
888 HEAP_CLEAR);
889 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
890 }
892 for (z=OUTPUT1; z < OUTPUTN; z++)
893 {
894 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
896 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
897 pAlgConfig = &pObj->config;
899 pAstCfg->xOut[z].hTxSio = NULL;
900 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
901 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
902 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
903 pConfig->allocation = pAlgConfig->pMemRec[0].size;
904 pConfig->sizeofElement = 3;
905 pConfig->precision = 24;
906 if(pP->fxns->bufMemPrint)
907 {
908 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
909 }
910 }
911 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
913 return 0;
914 } //PAF_ASOT_initPhaseDevice
916 // -----------------------------------------------------------------------------
917 // ASOT Initialization Function Helper - Initialization of Audio Frame
918 //
919 // Name: PAF_ASOT_initFrame0
920 // Purpose: Audio Stream Output Task Function for initialization of the Audio
921 // Frame(s) by memory allocation and loading of data pointers
922 // and values.
923 // From: AST Parameter Function -> decodeInfo
924 // Uses: See code.
925 // States: x
926 // Return: 0 on success.
927 // Source code line number on MEM_calloc failure.
928 // Source code line number on unsupported option.
929 // Trace: Message Log "trace" in Debug Project Configuration reports:
930 // * Memory allocation errors.
931 // * Unsupported option errors.
932 //
934 // MID 314
935 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
936 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
938 Int
939 PAF_ASOT_initFrame0(
940 const PAF_ASOT_Params *pP,
941 const PAF_ASOT_Patchs *pQ,
942 PAF_ASOT_Config *pC,
943 Int z
944 )
945 {
946 PAF_AST_Config *pAstCfg;
947 Int as; /* Audio Stream Number (1, 2, etc.) */
948 Int ch;
949 //Int aLen;
950 Int aLen_int=0,aLen_ext=0;
951 Int aSize = sizeof(PAF_AudioData);
952 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
953 Int maxFrameLength = pP->maxFramelength;
954 Int zX;
955 PAF_AudioData *aBuf_int=NULL;
956 PAF_AudioData *aBuf_ext=NULL;
957 XDAS_UInt8 *metadataBuf;
958 char i;
959 Error_Block eb;
961 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
962 as = pAstCfg->as;
964 // Initialize error block
965 Error_init(&eb);
967 // Compute maximum framelength (needed for ARC support)
968 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
969 //aLen = numchan[z] * maxFrameLength;
970 for (i=0; i < numchan[z]; i++)
971 {
972 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
973 {
974 aLen_int += maxFrameLength;
975 }
976 else
977 {
978 aLen_ext += maxFrameLength;
979 }
980 }
982 //
983 // Initialize audio frame elements directly
984 //
985 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
986 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
987 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
988 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
989 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
990 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
991 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
993 //
994 // Allocate memory for and initialize pointers to audio data buffers
995 //
996 // The NUMCHANMASK is used to identify the channels for which data
997 // buffers can be allocated. Using this mask and switch statement
998 // rather than some other construct allows efficient code generation,
999 // providing just the code necessary (with significant savings).
1000 //
1001 if (pP->fxns->bufMemPrint)
1002 {
1003 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1004 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1005 }
1007 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1009 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1010 {
1011 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, aLen_int*aSize, aAlign, &eb)))
1012 {
1013 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1014 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, aLen_int*aSize);
1015 SW_BREAKPOINT;
1016 return __LINE__;
1017 }
1018 }
1020 if (aLen_ext*aSize!=0)
1021 {
1022 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, aLen_ext*aSize, aAlign, &eb)))
1023 {
1024 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1025 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, aLen_ext*aSize);
1026 SW_BREAKPOINT;
1027 return __LINE__;
1028 }
1029 }
1031 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, aLen_int*aSize, (IArg)aBuf_int);
1032 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, aLen_ext*aSize, (IArg)aBuf_ext);
1034 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1035 //if (! (metadataBuf = (XDAS_UInt8 *)MEM_calloc (*(pP->pMetadataBufStatus->pSpace), pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment))) {
1036 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1037 {
1038 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1039 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1040 SW_BREAKPOINT;
1041 return __LINE__;
1042 }
1044 {
1045 Int i;
1047 #pragma UNROLL(1)
1048 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1049 {
1050 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1051 }
1052 }
1054 // MID 314
1055 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1056 {
1057 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1058 return __LINE__;
1059 }
1060 else
1061 {
1062 Int j = 0;
1063 Int k = 0;
1064 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1065 for(i=0;i<numchan[z];i++)
1066 {
1067 char chan = AFChanPtrMap[numchan[z]][i];
1068 if(chan != -1)
1069 {
1070 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1071 {
1072 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1073 j++;
1074 }
1075 else
1076 {
1077 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1078 k++;
1079 }
1080 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1081 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1082 }
1083 }
1084 }
1086 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1087 {
1088 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1089 {
1090 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1091 }
1092 }
1094 //
1095 // Initialize meta data elements
1096 //
1097 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1098 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1099 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1100 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1101 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1102 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1103 {
1104 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1105 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1106 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1107 }
1109 //
1110 // Initialize decoder elements directly
1111 //
1113 for (zX = DECODE1; zX < DECODEN; zX++)
1114 {
1115 if (pP->streamsFromDecodes[zX] == z)
1116 {
1117 #ifdef NOAUDIOSHARE
1118 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1119 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1120 #else /* NOAUDIOSHARE */
1121 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1122 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1123 #endif /* NOAUDIOSHARE */
1124 }
1125 }
1127 return 0;
1128 } //PAF_ASOT_initFrame0
1130 // -----------------------------------------------------------------------------
1131 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1132 // AST Decoding Function - Reinitialization of Audio Frame
1133 //
1134 // Name: PAF_ASOT_initFrame1
1135 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1136 // zation of the Audio Frame(s) by loading of data values of a
1137 // time-varying nature.
1138 // From: audioStream1Task or equivalent
1139 // AST Parameter Function -> decodeInfo
1140 // AST Parameter Function -> decodeDecode
1141 // Uses: See code.
1142 // States: x
1143 // Return: 0.
1144 // Trace: None.
1145 //
1146 Int
1147 PAF_ASOT_initFrame1(
1148 const PAF_ASOT_Params *pP,
1149 const PAF_ASOT_Patchs *pQ,
1150 PAF_ASOT_Config *pC,
1151 Int z,
1152 Int apply
1153 )
1154 {
1155 PAF_AST_Config *pAstCfg;
1157 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1159 //
1160 // Reinitialize audio frame elements:
1161 //
1162 // Channel Configurations during sys init = Unknown
1163 // " " during info or decode = None
1164 //
1165 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1166 //
1168 if (apply < 0)
1169 {
1170 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1171 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1172 }
1173 else
1174 {
1175 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1176 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1177 }
1179 if (apply < 1)
1180 {
1181 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1182 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1183 }
1185 return 0;
1186 } //PAF_ASOT_initFrame1
1188 // -----------------------------------------------------------------------------
1189 // ASOT Selection Function - Output Device Selection
1190 //
1191 // Name: PAF_ASOT_selectDevices
1192 // Purpose: Audio Stream Output Task Function for selecting the devices used
1193 // for output.
1194 // From: audioStream1Task or equivalent
1195 // Uses: See code.
1196 // States: x
1197 // Return: Error number in standard form (0 on success).
1198 // Trace: Message Log "trace" in Debug Project Configuration reports:
1199 // * State information as per parent.
1200 //
1201 Int
1202 PAF_ASOT_selectDevices(
1203 const PAF_ASOT_Params *pP,
1204 const PAF_ASOT_Patchs *pQ,
1205 PAF_ASOT_Config *pC
1206 )
1207 {
1208 PAF_AST_Config *pAstCfg;
1209 Int as; /* Audio Stream Number (1, 2, etc.) */
1210 Int z; /* input/output counter */
1211 Int errno = 0; /* error number */
1212 Int errme; /* error number, local */
1213 Int device;
1215 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1216 as = pAstCfg->as;
1217 (void)as; // clear compiler warning in case not used with tracing disabled
1219 // Select output devices
1220 for (z=OUTPUT1; z < OUTPUTN; z++)
1221 {
1222 if ((device = pAstCfg->xOut[z].outBufStatus.sioSelect) >= 0)
1223 {
1224 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1226 /* check for valid index into device array */
1227 if (device >= pQ->devout->n)
1228 {
1229 device = 0; /* treat as device None */
1230 }
1232 errme = pP->fxns->deviceSelect(&pAstCfg->xOut[z].hTxSio, SIO_OUTPUT,
1233 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1234 if (errme)
1235 {
1236 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1237 if (!errno)
1238 {
1239 errno = ASPERR_DEVOUT + errme;
1240 }
1241 pAstCfg->xOut[z].outBufStatus.sioSelect = 0x80;
1242 }
1243 else
1244 {
1245 Int zE;
1247 pAstCfg->xOut[z].outBufStatus.sioSelect = device | 0x80;
1248 // register outBufStatus and encodeStatus pointers with output devices
1249 // This enables proper IEC encapsulation.
1250 if (pAstCfg->xOut[z].hTxSio)
1251 {
1252 // set max # of output buffers (use override if necessary)
1253 if (pAstCfg->xOut[z].outBufStatus.maxNumBufOverride == 0)
1254 {
1255 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1256 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1257 }
1258 else
1259 {
1260 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1261 (Arg)pAstCfg->xOut[z].outBufStatus.maxNumBufOverride);
1262 }
1264 // register PAF_SIO_IALG object address
1265 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1266 (Arg)pAstCfg->xOut[z].outChainData.head->alg);
1267 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1268 (Arg)&pAstCfg->xOut[z].outBufStatus);
1269 for (zE=ENCODE1; zE < ENCODEN; zE++)
1270 {
1271 if (pP->outputsFromEncodes[zE] == z)
1272 {
1273 SIO_ctrl(pAstCfg->xOut[z].hTxSio,
1274 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1275 (Arg)&pAstCfg->xEnc[zE].encodeStatus);
1276 break;
1277 }
1278 }
1279 }
1280 }
1281 }
1283 // if device selected and valid then enable stat tracking if
1284 // required and start clocking
1285 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
1286 {
1287 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1288 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1289 if (errme)
1290 {
1291 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1292 SIO_idle(pAstCfg->xOut[z].hTxSio);
1293 if (!errno)
1294 {
1295 errno = ASPERR_DEVOUT + errme;
1296 }
1297 }
1298 }
1299 }
1301 return errno;
1302 } //PAF_ASOT_selectDevices
1304 // -----------------------------------------------------------------------------
1305 // ASOT Processing Function - Decode Processing
1306 //
1307 // Name: PAF_ASOT_decodeProcessing
1308 // Purpose: Audio Stream Output Task Function for processing audio data.
1309 //
1310 Int
1311 PAF_ASOT_decodeProcessing(
1312 const PAF_ASOT_Params *pP,
1313 const PAF_ASOT_Patchs *pQ,
1314 PAF_ASOT_Config *pC,
1315 Int sourceSelect
1316 )
1317 {
1318 PAF_AST_Config *pAstCfg;
1319 Int z; /* decode counter */
1320 Int errno; /* error number */
1321 Int getVal;
1322 enum { INIT, STREAM, ENCODE, FINAL, QUIT } state;
1323 state = INIT;
1324 errno = 0; /* error number */
1325 Int frame; // (***) FL: formerly -- decoder input frame count
1326 Int block; // decoder output block count / input frame
1327 Int outSioUpdate;
1329 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1331 for (;;)
1332 {
1333 // FL: Check if any change in output SIO, e.g. from Output shortcut.
1334 // Changes will break FSM and allow Output reconfiguration.
1335 if (errno = checkOutSio(pP, pC, &outSioUpdate))
1336 {
1337 TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
1338 break;
1339 }
1340 else if (outSioUpdate)
1341 {
1342 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
1343 state = QUIT;
1344 }
1346 // Process commands (encode)
1347 if (getVal = pP->fxns->encodeCommand(pP, pQ, pC))
1348 {
1349 /* ignore */;
1350 }
1352 // Process state (decode)
1353 switch (state)
1354 {
1355 case INIT: // initial state
1356 gAsopInitCnt++;
1357 Log_info0("TaskAsop: state=INIT");
1359 // Reset audio frame pointers to original values
1360 // (may be needed if error occurred).
1361 for (z=STREAM1; z < STREAMN; z++)
1362 {
1363 Int ch;
1364 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1365 {
1366 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1367 {
1368 pAstCfg->xStr[z].audioFrameChannelPointers[ch] =
1369 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch];
1370 }
1371 }
1372 }
1374 // Reset audio frame meta data elements
1375 {
1376 Int i;
1378 for (z=STREAM1; z < STREAMN; z++)
1379 {
1380 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1381 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1382 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1383 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1385 for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
1386 {
1387 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1388 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1389 }
1390 }
1391 }
1393 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1394 {
1395 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1396 break;
1397 }
1399 // (***) FL: setup output (ASP chain reset, ENC reset, setCheckRateX, start output)
1400 // Contained in INFO1 in combined FSM.
1401 // Establish secondary timing
1402 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
1403 {
1404 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
1405 break;
1406 }
1408 frame = 0;
1409 block = 0;
1411 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");
1412 state = STREAM;
1413 continue;
1415 case STREAM: // stream state
1416 gAsopStreamCnt++;
1417 Log_info0("TaskAsop: state=STREAM");
1419 if (errno = pP->fxns->decodeStream(pP, pQ, pC, frame, block))
1420 {
1421 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM. decodeStream err 0x%x", errno);
1422 break;
1423 }
1425 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: STREAM->ENCODE");
1426 state = ENCODE;
1427 continue;
1429 case ENCODE: // encode state
1430 gAsopEncodeCnt++;
1431 Log_info0("TaskAsop: state=ENCODE");
1433 if (errno = pP->fxns->decodeEncode(pP, pQ, pC, frame, block))
1434 {
1435 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
1436 break;
1437 }
1439 // (***) FL: do we need this?
1440 // AF pointers come from CB read, any resets occur in Decoder AF.
1441 // Reset audio frame pointers to original values
1442 // (may have been adjusted by ARC or the like).
1443 for (z=STREAM1; z < STREAMN; z++)
1444 {
1445 Int ch;
1446 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1447 {
1448 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1449 {
1450 pAstCfg->xStr[z].audioFrameChannelPointers[ch] =
1451 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch];
1452 }
1453 }
1454 }
1456 //
1457 // (***) FL: update output (setCheckRateX)
1458 // Contained in INFO2 in combined FSM.
1459 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
1460 {
1461 TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
1462 break;
1463 }
1465 block++;
1466 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: ENCODE->FINAL");
1467 state = FINAL;
1468 continue;
1470 case FINAL:
1471 gAsopFinalCnt++;
1472 Log_info0("TaskAsop: state=FINAL");
1474 //
1475 // (***) FL: this needs to be fixed.
1476 // (1) Only require selected Output to be in this FSM
1477 // => Dec Status checks aren't valid,
1478 // will probably always exit FSM if only Output running
1479 // (2) Checking Dec Status info asych to input events (maybe ok)
1480 //
1481 #if 0
1482 // Check for final frame, and if indicated:
1483 // - Update audio flag to cause output buffer flush rather than
1484 // the default truncate in "complete" processing.
1485 // - Exit state machine to "complete" processing.
1486 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
1487 {
1488 for (z=OUTPUT1; z < OUTPUTN; z++)
1489 {
1490 if ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
1491 {
1492 TRACE_VERBOSE0("PAF_ASOT_outputProcessing: state: FINAL: SOUND -> QUIET");
1493 pAstCfg->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
1494 }
1495 }
1496 break;
1497 }
1498 #endif
1500 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
1501 state = STREAM;
1502 continue;
1504 case QUIT:
1505 gAsopQuitCnt++;
1506 Log_info0("TaskAsop: state=QUIT");
1508 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: QUIT");
1509 errno = ASPERR_QUIT;
1510 break;
1512 default: // unknown state
1513 // Unknown:
1514 // - Set error number registers.
1515 // - Exit state machine to "complete" processing.
1517 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: unknown, 0x%x", state);
1518 errno = ASPERR_UNKNOWNSTATE;
1519 break;
1521 } // End of switch (state).
1523 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Calling decode complete");
1524 if (pP->fxns->decodeComplete(pP, pQ, pC, NULL, frame, block))
1525 {
1526 /* ignored? */;
1527 }
1529 return errno;
1530 } // End of for (;;)
1532 return errno;
1533 }
1535 // -----------------------------------------------------------------------------
1536 // ASOT Decoding Function - Encode Command Processing
1537 //
1538 // Name: PAF_ASOT_encodeCommand
1539 // Purpose: Decoding Function for processing Encode Commands.
1540 // From: AST Parameter Function -> decodeProcessing
1541 // Uses: See code.
1542 // States: x
1543 // Return: 0.
1544 // Trace: Message Log "trace" in Debug Project Configuration reports:
1545 // * Command execution.
1546 // * SIO control errors.
1547 // * Error number macros.
1548 //
1549 Int
1550 PAF_ASOT_encodeCommand(
1551 const PAF_ASOT_Params *pP,
1552 const PAF_ASOT_Patchs *pQ,
1553 PAF_ASOT_Config *pC
1554 )
1555 {
1556 PAF_AST_Config *pAstCfg;
1557 Int as; /* Audio Stream Number (1, 2, etc.) */
1558 Int z; /* encode counter */
1559 Int errno = 0; /* error number */
1560 Int zO, zS;
1563 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1564 as = pAstCfg->as;
1566 for (z=ENCODE1; z < ENCODEN; z++)
1567 {
1568 zO = pP->outputsFromEncodes[z];
1569 zS = pP->streamsFromEncodes[z];
1570 if (! (pAstCfg->xEnc[z].encodeStatus.command2 & 0x80))
1571 {
1572 switch (pAstCfg->xEnc[z].encodeStatus.command2)
1573 {
1574 case 0: // command none - process
1575 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
1576 break;
1577 case 1: // mute command
1578 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
1579 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
1580 && pAstCfg->xOut[zO].hTxSio
1581 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
1582 {
1583 errno = (errno & 0xff) | ASPERR_MUTE;
1584 /* convert to sensical errno */
1585 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
1586 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
1587 }
1588 else
1589 {
1590 pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
1591 }
1592 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
1593 break;
1594 case 2: // unmute command
1595 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
1596 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
1597 && pAstCfg->xOut[zO].hTxSio
1598 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
1599 {
1600 errno = (errno & 0xff) | ASPERR_MUTE;
1601 /* convert to sensical errno */
1602 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
1603 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
1604 }
1605 else
1606 {
1607 pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
1608 }
1609 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
1610 break;
1611 default: // command unknown - ignore
1612 break;
1613 }
1614 }
1615 }
1617 ERRNO_RPRT (TaskAsop, errno);
1619 return 0;
1620 } //PAF_ASOT_encodeCommand
1622 // Purpose: Decoding Function for reinitializing the decoding process.
1623 Int
1624 PAF_ASOT_decodeInit(
1625 const PAF_ASOT_Params *pP,
1626 const PAF_ASOT_Patchs *pQ,
1627 PAF_ASOT_Config *pC,
1628 Int sourceSelect
1629 )
1630 {
1631 PAF_AST_Config *pAstCfg;
1632 Int as; /* Audio Stream Number (1, 2, etc.) */
1633 Int z; /* decode/encode counter */
1634 Int errno; /* error number */
1635 Int zO, zS;
1636 PAF_AST_DecOpCircBuf *pCb; /* decoder output circular buffer */
1639 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1640 as = pAstCfg->as;
1642 for (z=DECODE1; z < DECODEN; z++)
1643 {
1644 // Start decoder output circular buffer reads
1645 pCb = &pAstCfg->xDecOpCb[z];
1646 errno = cbReadStart(pCb);
1647 if (errno)
1648 {
1649 TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
1650 SW_BREAKPOINT; // FL: debug
1651 return errno;
1652 }
1653 // FL: debug
1654 cbLog(pCb, 1, "PAF_ASOT_decodeInit:cbReadStart");
1655 }
1657 // TODO: move this to start of this function so that it doesn't affect IO timing
1658 for (z=ENCODE1; z < ENCODEN; z++)
1659 {
1660 zO = pP->outputsFromEncodes[z];
1661 zS = pP->streamsFromEncodes[z];
1662 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
1663 {
1664 Int select = pAstCfg->xEnc[z].encodeStatus.select;
1665 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
1666 ENC_Handle enc = (ENC_Handle )encAlg;
1667 TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
1668 if (encAlg->fxns->algActivate)
1669 {
1670 encAlg->fxns->algActivate (encAlg);
1671 }
1672 if (enc->fxns->reset
1673 && (errno = enc->fxns->reset(enc, NULL,
1674 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
1675 {
1676 return errno;
1677 }
1678 }
1679 }
1681 return 0;
1682 }
1684 // -----------------------------------------------------------------------------
1685 // ASOT Decoding Function - Info Processing, Initial
1686 //
1687 // Name: PAF_ASOT_decodeInfo1
1688 // Purpose: Decoding Function for processing information in a manner that
1689 // is unique to initial frames of input data.
1690 // From: AST Parameter Function -> decodeProcessing
1691 // Uses: See code.
1692 // States: x
1693 // Return: Error number in standard or SIO form (0 on success).
1694 // Trace: Message Log "trace" in Debug Project Configuration reports:
1695 // * State information as per parent.
1696 //
1697 Int
1698 PAF_ASOT_decodeInfo1(
1699 const PAF_ASOT_Params *pP,
1700 const PAF_ASOT_Patchs *pQ,
1701 PAF_ASOT_Config *pC,
1702 Int frame,
1703 Int block
1704 )
1705 {
1706 PAF_AST_Config *pAstCfg;
1707 Int z; /* decode/encode counter */
1708 Int errno; /* error number */
1710 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1712 // run the chain of ASP's on the stream.
1713 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
1714 if (errno = pP->fxns->streamChainFunction(pP, pQ, pC,
1715 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame))
1716 {
1717 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
1718 return errno;
1719 }
1721 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
1722 for (z=ENCODE1; z < ENCODEN; z++)
1723 {
1724 Int zO = pP->outputsFromEncodes[z];
1725 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
1726 {
1727 Int select = pAstCfg->xEnc[z].encodeStatus.select;
1728 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
1729 ENC_Handle enc = (ENC_Handle )encAlg;
1730 if (enc->fxns->info
1731 && (errno = enc->fxns->info(enc, NULL,
1732 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
1733 {
1734 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
1735 return errno;
1736 }
1737 }
1738 }
1740 if (errno = pP->fxns->setCheckRateX(pP, pQ, pC, 0))
1741 {
1742 // ignore if rateX has changed since we haven't, but are about to,
1743 // start the output. If we didn't ignore this case then the state machine
1744 // would restart unnecessarily, e.g. in the case of SRC, resulting in
1745 // added latency.
1746 if (errno != ASPERR_INFO_RATECHANGE)
1747 {
1748 TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
1749 return errno;
1750 }
1751 else
1752 {
1753 TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
1754 }
1755 }
1757 if (errno = pP->fxns->startOutput(pP, pQ, pC))
1758 {
1759 if (errno == 0x105)
1760 {
1761 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
1762 }
1763 else
1764 {
1765 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
1766 }
1767 return errno;
1768 }
1770 return 0;
1771 }
1773 // -----------------------------------------------------------------------------
1774 // ASOT Decoding Function - Info Processing, Subsequent
1775 //
1776 // Name: PAF_ASOT_decodeInfo2
1777 // Purpose: Decoding Function for processing information in a manner that
1778 // is unique to frames of input data other than the initial one.
1779 // From: AST Parameter Function -> decodeProcessing
1780 // Uses: See code.
1781 // States: x
1782 // Return: Error number in standard form (0 on success).
1783 // Trace: None.
1784 //
1785 Int
1786 PAF_ASOT_decodeInfo2(
1787 const PAF_ASOT_Params *pP,
1788 const PAF_ASOT_Patchs *pQ,
1789 PAF_ASOT_Config *pC,
1790 Int frame,
1791 Int block
1792 )
1793 {
1794 //PAF_AST_Config *pAstCfg;
1795 Int errno;
1798 //pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1800 errno = pP->fxns->setCheckRateX (pP, pQ, pC, 1);
1801 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
1802 return errno;
1803 } //PAF_ASOT_decodeInfo2
1805 // -----------------------------------------------------------------------------
1806 // ASOT Decoding Function - Stream Processing
1807 //
1808 // Name: PAF_ASOT_decodeStream
1809 // Purpose: Decoding Function for processing of audio frame data by the
1810 // ASP Algorithms.
1811 // From: AST Parameter Function -> decodeProcessing
1812 // Uses: See code.
1813 // States: x
1814 // Return: Error number in standard form (0 on success).
1815 // Trace: Message Log "trace" in Debug Project Configuration reports:
1816 // * State information as per parent/child.
1817 //
1818 Int
1819 PAF_ASOT_decodeStream(
1820 const PAF_ASOT_Params *pP,
1821 const PAF_ASOT_Patchs *pQ,
1822 PAF_ASOT_Config *pC,
1823 Int frame,
1824 Int block
1825 )
1826 {
1827 PAF_AST_Config *pAstCfg;
1828 Int z; /* decode/stream counter */
1829 PAF_AST_DecOpCircBuf *pCb; /* decoder output circular buffer */
1830 PAF_AudioFrame *pAfRd;
1831 Int cbErrno;
1832 Int errno;
1835 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1837 for (z=DECODE1; z < DECODEN; z++)
1838 {
1839 Int zS = pP->streamsFromDecodes[z];
1841 //
1842 // (***) FL: read circular buffer
1843 //
1844 pCb = &pAstCfg->xDecOpCb[z];
1845 pAfRd = pAstCfg->xStr[zS].pAudioFrame;
1846 cbErrno = cbReadAf(pCb, pAfRd);
1847 if (cbErrno != 0)
1848 {
1849 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
1850 //SW_BREAKPOINT; // FL: debug
1851 //return cbErrno; // (***) FL: ignoring read failures??
1852 }
1853 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
1855 // FL: debug
1856 cbLog(pCb, 1, "PAF_ASOT_decodeStream:cbReadAf");
1857 //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
1858 //{
1859 // Log_info0("capAfWrite() error");
1860 //}
1861 }
1863 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
1864 errno = pP->fxns->streamChainFunction(pP, pQ, pC,
1865 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
1866 if (errno)
1867 {
1868 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
1869 return errno;
1870 }
1872 return 0;
1874 } //PAF_ASOT_decodeStream
1876 // -----------------------------------------------------------------------------
1877 // ASOT Decoding Function - Encode Processing
1878 //
1879 // Name: PAF_ASOT_decodeEncode
1880 // Purpose: Decoding Function for processing of audio frame data by the
1881 // Encode Algorithm.
1882 // From: AST Parameter Function -> decodeProcessing
1883 // Uses: See code.
1884 // States: x
1885 // Return: Error number in standard or SIO form (0 on success).
1886 // Trace: Message Log "trace" in Debug Project Configuration reports:
1887 // * State information as per parent.
1888 //
1889 Int
1890 PAF_ASOT_decodeEncode(
1891 const PAF_ASOT_Params *pP,
1892 const PAF_ASOT_Patchs *pQ,
1893 PAF_ASOT_Config *pC,
1894 Int frame,
1895 Int block
1896 )
1897 {
1898 PAF_AST_Config *pAstCfg;
1899 Int as; /* Audio Stream Number (1, 2, etc.) */
1900 Int z; /* encode/output counter */
1901 Int errno; /* error number */
1902 Int zX, zE, zS;
1903 UInt32 curTime;
1905 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1906 as = pAstCfg->as;
1908 // Await output buffers (but not first time)
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 (pAstCfg->xOut[z].hTxSio)
1924 {
1925 // update length (e.g. ARC may have changed)
1926 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
1927 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
1928 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
1929 errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
1930 if (errno < 0)
1931 {
1932 SIO_idle(pAstCfg->xOut[z].hTxSio);
1933 TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
1934 return -errno; // SIO negates error codes
1935 }
1936 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
1938 //
1939 // Simulate Tx SIO_reclaim() pend
1940 //
1941 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
1942 gTaskAsopCnt++;
1943 curTime = Clock_getTicks();
1944 //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
1945 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
1946 }
1947 else
1948 {
1949 TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
1950 }
1951 }
1953 // Encode data
1954 for (z=ENCODE1; z < ENCODEN; z++)
1955 {
1956 Int zO = pP->outputsFromEncodes[z];
1957 Int zS = pP->streamsFromEncodes[z];
1958 (void)zS; // clear compiler warning in case not used with tracing disabled
1959 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
1960 {
1961 Int select = pAstCfg->xEnc[z].encodeStatus.select;
1962 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
1963 ENC_Handle enc = (ENC_Handle )encAlg;
1964 if (select != pAstCfg->xEnc[z].encodeControl.encActive)
1965 {
1966 pAstCfg->xEnc[z].encodeControl.encActive = select;
1967 TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
1968 return (-1);
1969 }
1970 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
1972 // (MID 1933) temp. workaround for PCE2
1973 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
1975 /*
1976 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1977 {
1978 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
1979 int *wp;
1980 wp = (int*)pAudioFrame->data.sample[0];
1981 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
1982 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
1983 wp = (int*)pAudioFrame->data.sample[1];
1984 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
1985 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
1986 wp = (int*)pAudioFrame->data.sample[2];
1987 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
1988 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
1989 }
1990 #endif
1991 */
1993 if (enc->fxns->encode)
1994 {
1995 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
1996 pP->z_pEncodeStatus[z]->encBypass;
1997 if (errno = enc->fxns->encode(enc, NULL,
1998 &pAstCfg->xEnc[z].encodeInStruct, &pAstCfg->xEnc[z].encodeOutStruct))
1999 {
2000 if (errno != PCEERR_OUTPUT_POINTERNULL)
2001 {
2002 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
2003 return errno;
2004 }
2005 }
2006 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2007 else
2008 {
2009 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
2010 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
2011 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
2012 }
2013 #endif
2014 */
2015 }
2016 }
2017 else
2018 {
2019 TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
2020 as+pP->streamsFromEncodes[z], block);
2021 }
2022 }
2024 // Transmit data
2025 for (z=OUTPUT1; z < OUTPUTN; z++)
2026 {
2027 // determine encoder associated with this output
2028 zE = z;
2029 for (zX = ENCODE1; zX < ENCODEN; zX++)
2030 {
2031 if (pP->outputsFromEncodes[zX] == z)
2032 {
2033 zE = zX;
2034 break;
2035 }
2036 }
2037 zS = pP->streamsFromEncodes[zE];
2039 if (pAstCfg->xOut[z].hTxSio)
2040 {
2041 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
2042 errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2043 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
2044 if (errno)
2045 {
2046 SIO_idle(pAstCfg->xOut[z].hTxSio);
2047 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
2048 {
2049 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
2050 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
2051 }
2052 if (errno > 0)
2053 {
2054 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
2055 return (ASPERR_ISSUE + (z << 4));
2056 }
2057 else if (errno < 0)
2058 {
2059 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
2060 return -errno; // SIO negates error codes
2061 }
2062 }
2063 if (errno > 0)
2064 {
2065 return (ASPERR_ISSUE + (z << 4));
2066 }
2067 else if (errno < 0)
2068 {
2069 return -errno; // SIO negates error codes
2070 }
2071 }
2072 else
2073 {
2074 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
2075 }
2076 }
2078 return 0;
2079 } //PAF_ASOT_decodeEncode
2081 // -----------------------------------------------------------------------------
2082 // ASOT Decoding Function - Stream-Final Processing
2083 //
2084 // Name: PAF_ASOT_decodeComplete
2085 // Purpose: Decoding Function for terminating the decoding process.
2086 // From: AST Parameter Function -> decodeProcessing
2087 // Uses: See code.
2088 // States: x
2089 // Return: 0.
2090 // Trace: Message Log "trace" in Debug Project Configuration reports:
2091 // * State information as per parent.
2092 //
2093 Int
2094 PAF_ASOT_decodeComplete(
2095 const PAF_ASOT_Params *pP,
2096 const PAF_ASOT_Patchs *pQ,
2097 PAF_ASOT_Config *pC,
2098 ALG_Handle decAlg[],
2099 Int frame,
2100 Int block
2101 )
2102 {
2103 PAF_AST_Config *pAstCfg;
2104 Int as; /* Audio Stream Number (1, 2, etc.) */
2105 Int z; /* decode/encode counter */
2106 Int errno; /* error number */
2107 PAF_AST_DecOpCircBuf *pCb; /* decoder output circular buffer */
2110 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2111 as = pAstCfg->as;
2112 (void)as; // clear compiler warning in case not used with tracing disabled
2114 for (z=DECODE1; z < DECODEN; z++)
2115 {
2116 // Stop decoder output circular buffer reads
2117 pCb = &pAstCfg->xDecOpCb[z];
2118 errno = cbReadStop(pCb);
2119 if (errno)
2120 {
2121 TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
2122 SW_BREAKPOINT; // FL: debug
2123 return errno;
2124 }
2125 // FL: debug
2126 cbLog(pCb, 1, "PAF_ASOT_decodeComplete:cbReadStop");
2127 }
2129 pP->fxns->streamChainFunction(pP, pQ, pC, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2131 for (z=ENCODE1; z < ENCODEN; z++)
2132 {
2133 Int zO = pP->outputsFromEncodes[z];
2134 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2135 {
2136 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2137 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2138 #ifdef PAF_ASP_FINAL
2139 ENC_Handle enc = (ENC_Handle)encAlg;
2140 #endif /* PAF_ASP_FINAL */
2141 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
2142 #ifdef PAF_ASP_FINAL
2143 if (enc->fxns->final)
2144 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
2145 &pAstCfg->xEnc[z].encodeStatus);
2146 #endif /* PAF_ASP_FINAL */
2147 if (encAlg->fxns->algDeactivate)
2148 {
2149 encAlg->fxns->algDeactivate(encAlg);
2150 }
2151 }
2152 else
2153 {
2154 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2155 }
2156 }
2158 // wait for remaining data to be output
2159 pP->fxns->stopOutput(pP, pQ, pC);
2161 return 0;
2162 } //PAF_ASOT_decodeComplete
2164 // -----------------------------------------------------------------------------
2165 // ASOT Decoding Function Helper - SIO Driver Start
2166 //
2167 // Name: PAF_ASOT_startOutput
2168 // Purpose: Decoding Function for initiating output.
2169 // From: AST Parameter Function -> decodeInfo1
2170 // Uses: See code.
2171 // States: x
2172 // Return: Error number in standard or SIO form (0 on success).
2173 // Trace: Message Log "trace" in Debug Project Configuration reports:
2174 // * State information as per parent.
2175 // * SIO control errors.
2176 //
2177 #define DEC_OUTNUMBUF_MAP(X) \
2178 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2180 Int
2181 PAF_ASOT_startOutput(
2182 const PAF_ASOT_Params *pP,
2183 const PAF_ASOT_Patchs *pQ,
2184 PAF_ASOT_Config *pC
2185 )
2186 {
2187 PAF_AST_Config *pAstCfg;
2188 Int as; /* Audio Stream Number (1, 2, etc.) */
2189 Int z; /* output counter */
2190 Int errno,nbufs; /* error number */
2191 Int zE, zS, zX;
2192 Int zMD;
2193 PAF_SIO_IALG_Obj *pObj;
2194 PAF_SIO_IALG_Config *pAlgConfig;
2197 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2198 as = pAstCfg->as;
2199 zMD = pAstCfg->masterDec;
2201 for (z=OUTPUT1; z < OUTPUTN; z++)
2202 {
2203 if (pAstCfg->xOut[z].hTxSio)
2204 {
2205 // determine associated encoder and stream
2206 zE = z;
2207 zS = z;
2208 for (zX = ENCODE1; zX < ENCODEN; zX++)
2209 {
2210 if (pP->outputsFromEncodes[zX] == z)
2211 {
2212 zE = zX;
2213 zS = pP->streamsFromEncodes[zE];
2214 break;
2215 }
2216 }
2218 // Set sample count so that DOB knows how much data to send
2219 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2220 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2222 if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
2223 {
2224 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
2225 pAlgConfig = &pObj->config;
2226 memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
2227 pAlgConfig->pMemRec[0].size);
2228 }
2230 // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
2231 // decoder. How should we handle the sourceProgram for multiple decoders?
2232 // Override as needed
2233 nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
2234 if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
2235 {
2236 nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
2237 }
2238 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
2240 if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2241 &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
2242 {
2243 SIO_idle(pAstCfg->xOut[z].hTxSio);
2244 TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
2245 return errno;
2246 }
2248 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2249 (errno = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2250 {
2251 errno = (errno & 0xff) | ASPERR_MUTE;
2252 /* convert to sensical errno */
2253 TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
2254 return (errno);
2255 }
2256 else
2257 {
2258 pAstCfg->xOut[z].outBufStatus.audio
2259 = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
2260 }
2262 TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
2263 }
2264 }
2266 return 0;
2267 } //PAF_ASOT_startOutput
2269 // -----------------------------------------------------------------------------
2270 // ASOT Decoding Function Helper - SIO Driver Stop
2271 //
2272 // Name: PAF_ASOT_stopOutput
2273 // Purpose: Decoding Function for terminating output.
2274 // From: AST Parameter Function -> decodeProcessing
2275 // AST Parameter Function -> decodeComplete
2276 // Uses: See code.
2277 // States: x
2278 // Return: Error number in standard or SIO form (0 on success).
2279 // Trace: Message Log "trace" in Debug Project Configuration reports:
2280 // * SIO control errors.
2281 //
2282 Int
2283 PAF_ASOT_stopOutput(
2284 const PAF_ASOT_Params *pP,
2285 const PAF_ASOT_Patchs *pQ,
2286 PAF_ASOT_Config *pC
2287 )
2288 {
2289 PAF_AST_Config *pAstCfg;
2290 Int as; /* Audio Stream Number (1, 2, etc.) */
2291 Int z; /* output counter */
2292 Int errno = 0, getVal;
2293 Int zS, zX;
2294 PAF_SIO_IALG_Obj *pObj;
2295 PAF_SIO_IALG_Config *pAlgConfig;
2297 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2298 as = pAstCfg->as;
2299 (void)as; // clear compiler warning in case not used with tracing disabled
2301 for (z=OUTPUT1; z < OUTPUTN; z++)
2302 {
2303 if (pAstCfg->xOut[z].hTxSio)
2304 {
2305 // determine associated encoder and stream
2306 zS = z;
2307 (void)zS;
2308 for (zX = ENCODE1; zX < ENCODEN; zX++)
2309 {
2310 if (pP->outputsFromEncodes[zX] == z)
2311 {
2312 zS = pP->streamsFromEncodes[zX];
2313 break;
2314 }
2315 }
2317 // Mute output before audio data termination in the usual case,
2318 // where such termination is due to decode error or user command.
2319 // Identification of this as the usual case is provided by the
2320 // "decode processing" state machine.
2321 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2322 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND) &&
2323 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2324 {
2325 if (!errno)
2326 {
2327 errno = (getVal & 0xff) | ASPERR_MUTE;
2328 /* convert to sensical errno */
2329 }
2330 TRACE_VERBOSE1("PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2331 }
2333 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- begin PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2335 // Terminate audio data output, truncating (ignore) or flushing
2336 // (play out) final samples as per (1) control register set by
2337 // the user and (2) the type of audio data termination:
2339 #if 0
2340 // This form is not used because driver support for truncating
2341 // data is not supported for internal clocks, although it is
2342 // for external clocks.
2343 getVal = SIO_ctrl(pC->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2344 pC->xOut[z].outBufStatus.flush
2345 & (pC->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2346 ? 1 : 0);
2347 /* UNTESTED */
2348 #else
2349 // This form should be used when driver support for truncating
2350 // data is supported for both internal and external clocks.
2351 getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_IDLE,
2352 pAstCfg->xOut[z].outBufStatus.flush ? 1 :
2353 (pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH
2354 ? 1 : 0);
2355 /* TESTED */
2356 #endif
2358 TRACE_TIME((&TIME_MOD, "... + %d = %d (stopOutput -- after PAF_SIO_CONTROL_IDLE)", dtime(), TSK_time()));
2360 if (!errno)
2361 {
2362 errno = getVal;
2363 }
2365 // Mute output after audio data termination in a special case,
2366 // where such termination is due to processing of a final frame
2367 // or user command. Identification of this as a special case is
2368 // provided by the "decode processing" state machine.
2369 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2370 ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_FLUSH) &&
2371 (getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2372 {
2373 if (!errno)
2374 {
2375 errno = (getVal & 0xff) | ASPERR_MUTE;
2376 /* convert to sensical errno */
2377 }
2378 TRACE_VERBOSE1("as1-f2: PAF_ASOT_stopOutput: AS%d: SIO control failed (mute)", as+zS);
2379 }
2381 pAstCfg->xOut[z].outBufStatus.audio &= ~0x0f;
2383 // zero output buffers
2384 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
2385 pAlgConfig = &pObj->config;
2386 memset (pAstCfg->xOut[z].outBufConfig.base.pVoid, 0, pAlgConfig->pMemRec[0].size);
2387 } //pAstCfg->xOut[z].hTxSio
2388 }//OUTPUT
2390 return errno;
2391 } //PAF_ASOT_stopOutput
2393 // -----------------------------------------------------------------------------
2394 // ASOT Decoding Function Helper - SIO Driver Change
2395 //
2396 // Name: PAF_ASOT_setCheckRateX
2397 // Purpose: Decoding Function for reinitiating output.
2398 // From: AST Parameter Function -> decodeInfo1
2399 // AST Parameter Function -> decodeInfo2
2400 // Uses: See code.
2401 // States: x
2402 // Return: Error number in standard form (0 on success).
2403 // Trace: None.
2404 //
2406 /* 0: set, 1: check, unused for now. --Kurt */
2407 Int
2408 PAF_ASOT_setCheckRateX(
2409 const PAF_ASOT_Params *pP,
2410 const PAF_ASOT_Patchs *pQ,
2411 PAF_ASOT_Config *pC,
2412 Int check
2413 )
2414 {
2415 PAF_AST_Config *pAstCfg;
2416 float rateX;
2417 PAF_SampleRateHz rateO /* std */, rateI /* inv */;
2418 Int z; /* output counter */
2419 Int zx; /* output re-counter */
2420 Int getVal;
2421 int inputRate, inputCount, outputRate, outputCount;
2422 Int zMD;
2423 Int zMI;
2424 Int zMS;
2425 Int zE, zX;
2427 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2428 zMD = pAstCfg->masterDec;
2429 zMS = pAstCfg->masterStr;
2430 zMI = pP->zone.master;
2432 inputRate = pAstCfg->xInp[zMI].inpBufStatus.sampleRateStatus;
2433 inputCount = pAstCfg->xDec[zMD].decodeStatus.frameLength;
2434 rateI = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
2435 (pAstCfg->xStr[zMS].pAudioFrame, inputRate, PAF_SAMPLERATEHZ_INV);
2437 for (z=OUTPUT1; z < OUTPUTN; z++) {
2438 if (pAstCfg->xOut[z].hTxSio && (pAstCfg->xOut[z].outBufStatus.clock & 0x01)) {
2440 // determine associated encoder
2441 zE = z;
2442 for (zX = ENCODE1; zX < ENCODEN; zX++) {
2443 if (pP->outputsFromEncodes[zX] == z) {
2444 zE = zX;
2445 break;
2446 }
2447 }
2449 outputRate = pAstCfg->xEnc[zE].encodeStatus.sampleRate;
2450 outputCount = pAstCfg->xEnc[zE].encodeStatus.frameLength;
2451 rateO = pAstCfg->xStr[zMS].pAudioFrame->fxns->sampleRateHz
2452 (pAstCfg->xStr[zMS].pAudioFrame, outputRate, PAF_SAMPLERATEHZ_STD);
2453 if (rateI > 0 && rateO > 0)
2454 rateX = rateO /* std */ * rateI /* inv */;
2455 else if (inputCount != 0)
2456 rateX = (float )outputCount / inputCount;
2457 else
2458 return ( ASPERR_INFO_RATERATIO );
2460 getVal = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg) &rateX);
2461 if (getVal == DOBERR_RATECHANGE) {
2462 for (zx=OUTPUT1; zx < OUTPUTN; zx++)
2463 if (pAstCfg->xOut[zx].hTxSio)
2464 SIO_idle (pAstCfg->xOut[zx].hTxSio);
2466 // this forces an exit from the calling state machine which will
2467 // eventually call startOutput which calls setCheckRateX for all outputs
2468 // and so it is ok, in the presence of a rate change on any output, to
2469 // exit this loop /function early.
2470 return ASPERR_INFO_RATECHANGE;
2471 }
2472 else if( getVal != SYS_OK )
2473 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
2474 }
2475 }
2477 return 0;
2478 } //PAF_ASOT_setCheckRateX
2480 // -----------------------------------------------------------------------------
2481 // ASOT Decoding Function Helper - Chain Processing
2482 //
2483 // Name: PAF_ASOT_streamChainFunction
2484 // Purpose: Common Function for processing algorithm chains.
2485 // From: AST Parameter Function -> decodeInfo1
2486 // AST Parameter Function -> decodeStream
2487 // AST Parameter Function -> decodeComplete
2488 // Uses: See code.
2489 // States: x
2490 // Return: Error number in standard form (0 on success).
2491 // Trace: Message Log "trace" in Debug Project Configuration reports:
2492 // * State information as per parent.
2493 //
2494 Int
2495 PAF_ASOT_streamChainFunction(
2496 const PAF_ASOT_Params *pP,
2497 const PAF_ASOT_Patchs *pQ,
2498 PAF_ASOT_Config *pC,
2499 Int iChainFrameFxns,
2500 Int abortOnError,
2501 Int logArg
2502 )
2503 {
2504 PAF_AST_Config *pAstCfg;
2505 Int as; /* Audio Stream Number (1, 2, etc.) */
2506 Int z; /* stream counter */
2507 Int errno; /* error number */
2508 Int dFlag, eFlag, gear;
2509 Int zX;
2510 Int zS;
2512 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2513 as = pAstCfg->as;
2514 (void)as; // clear compiler warning in case not used with tracing disabled
2516 for (zS = STREAM1; zS < STREAMN; zS++)
2517 {
2518 z = pP->streamOrder[zS]; // Select stream order from streamOrder parameter - MID 788
2520 // apply stream
2521 // unless the stream is associated with a decoder and it is not running
2522 // or
2523 // unless the stream is associated with an encoder and it is not running
2524 // Also gear control only works for streams with an associated decoder
2525 // if no such association exists then gear 0 (All) is used
2526 dFlag = 1;
2527 gear = 0;
2528 for (zX = DECODE1; zX < DECODEN; zX++) {
2529 if (pP->streamsFromDecodes[zX] == z) {
2530 dFlag = pAstCfg->xDec[zX].decodeStatus.mode;
2531 gear = pAstCfg->xDec[zX].decodeStatus.aspGearStatus;
2532 break;
2533 }
2534 }
2535 eFlag = 1;
2536 for (zX = ENCODE1; zX < ENCODEN; zX++) {
2537 if (pP->streamsFromEncodes[zX] == z) {
2538 eFlag = pAstCfg->xEnc[zX].encodeStatus.mode;
2539 break;
2540 }
2541 }
2543 if (dFlag && eFlag) {
2544 PAF_ASP_Chain *chain = pAstCfg->xStr[z].aspChain[gear];
2545 PAF_AudioFrame *frame = pAstCfg->xStr[z].pAudioFrame;
2546 Int (*func) (PAF_ASP_Chain *, PAF_AudioFrame *) =
2547 chain->fxns->chainFrameFunction[iChainFrameFxns];
2549 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
2550 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset)"
2551 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
2552 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply)"
2553 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
2554 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final)"
2555 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????)",
2556 as+z, logArg);
2557 errno = (*func) (chain, frame);
2558 TRACE_VERBOSE2("PAF_ASOT_streamChainFunction: AS%d: errno 0x%x.",
2559 as+z, errno);
2561 if (errno && abortOnError)
2562 return errno;
2563 }
2564 else {
2565 TRACE_GEN2(iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_RESET
2566 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (reset) <ignored>"
2567 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_APPLY
2568 ? "PAF_ASOT_streamChainFunction: AS%d: processing block %d -- audio stream (apply) <ignored>"
2569 : iChainFrameFxns == PAF_ASP_CHAINFRAMEFXNS_FINAL
2570 ? "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (final) <ignored>"
2571 : "PAF_ASOT_streamChainFunction: AS%d: processing frame %d -- audio stream (?????) <ignored>",
2572 as+z, logArg);
2573 }
2575 /*
2576 {
2577 void dp_tracePAF_Data(float *lBuf, float *rBuf, int count);
2578 PAF_AudioFrameData *afd;
2579 float ** afPtr;
2581 afd = &(pC->xStr->pAudioFrame->data);
2582 afPtr = (float**)afd->sample;
2583 dp_tracePAF_Data(afPtr[4], afPtr[5], 256);
2585 }
2586 */
2588 }
2590 return 0;
2591 } //PAF_ASOT_streamChainFunction
2593 /* FL: Check if at least one output selected */
2594 static Int checkOutSel(
2595 const PAF_ASOT_Params *pP,
2596 PAF_ASOT_Config *pC,
2597 Int *pOutSel
2598 )
2599 {
2600 PAF_AST_Config *pAstCfg;
2601 Int outSel;
2602 Int z;
2604 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2606 outSel = 0;
2607 for (z=OUTPUT1; z < OUTPUTN; z++)
2608 {
2609 if (pAstCfg->xOut[z].hTxSio)
2610 {
2611 outSel = 1;
2612 break;
2613 }
2614 }
2616 *pOutSel = outSel;
2618 return 0;
2619 }
2621 /* FL: Check if at least one output sio changed */
2622 static Int checkOutSio(
2623 const PAF_ASOT_Params *pP,
2624 PAF_ASOT_Config *pC,
2625 Int *pOutSioUpdate
2626 )
2627 {
2628 PAF_AST_Config *pAstCfg;
2629 Int outSioUpdate;
2630 Int z;
2632 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2634 outSioUpdate = 0;
2635 for (z=OUTPUT1; z < OUTPUTN; z++)
2636 {
2637 if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
2638 {
2639 outSioUpdate = 1;
2640 break;
2641 }
2642 }
2644 *pOutSioUpdate = outSioUpdate;
2646 return 0;
2647 }