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