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