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 "aspOutInitSync_master.h"
61 #include "audioStreamProc_common.h"
62 #include "audioStreamOutProc.h"
64 #include "pfp/pfp.h"
65 #include "pfp_app.h" /* contains all PFP ID's */
66 Int32 gNumPfpAsot1=0; // debug
68 // FL: debug
69 #include "evmc66x_gpio_dbg.h"
70 #include "dbgCapAf.h"
73 // -----------------------------------------------------------------------------
74 // Debugging Trace Control, local to this file.
75 //
76 #include "logp.h"
78 #define TRACE_TIME(a)
80 // Allow a developer to selectively enable tracing.
81 #define CURRENT_TRACE_MASK 0x07
83 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
84 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
85 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
87 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
88 #undef TRACE_TERSE0
89 #undef TRACE_TERSE1
90 #undef TRACE_TERSE2
91 #undef TRACE_TERSE3
92 #undef TRACE_TERSE4
93 #define TRACE_TERSE0(a)
94 #define TRACE_TERSE1(a,b)
95 #define TRACE_TERSE2(a,b,c)
96 #define TRACE_TERSE3(a,b,c,d)
97 #define TRACE_TERSE4(a,b,c,d,e)
98 #endif
100 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
101 #undef TRACE_GEN0
102 #undef TRACE_GEN1
103 #undef TRACE_GEN2
104 #undef TRACE_GEN3
105 #undef TRACE_GEN4
106 #define TRACE_GEN0(a)
107 #define TRACE_GEN1(a,b)
108 #define TRACE_GEN2(a,b,c)
109 #define TRACE_GEN3(a,b,c,d)
110 #define TRACE_GEN4(a,b,c,d,e)
111 #endif
113 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
114 #undef TRACE_VERBOSE0
115 #undef TRACE_VERBOSE1
116 #undef TRACE_VERBOSE2
117 #undef TRACE_VERBOSE3
118 #undef TRACE_VERBOSE4
119 #define TRACE_VERBOSE0(a)
120 #define TRACE_VERBOSE1(a,b)
121 #define TRACE_VERBOSE2(a,b,c)
122 #define TRACE_VERBOSE3(a,b,c,d)
123 #define TRACE_VERBOSE4(a,b,c,d,e)
124 #endif
126 // .............................................................................
128 //
129 // Audio Stream Definitions
130 //
132 //
133 // Audio Stream Processing Definitions
134 //
135 #define aspLinkInit pQ->i_aspLinkInit
137 //
138 // Encoder Definitions
139 //
140 #define encLinkInit pQ->i_encLinkInit
142 //
143 // Output Definitions
144 //
145 #define outLinkInit pP->i_outLinkInit
147 /* ---------------------------------------------------------------- */
148 /* Parameter macro definitions end here. */
149 /* ---------------------------------------------------------------- */
151 //
152 // Standardized Definitions
153 //
155 #define ENC_Handle PCE_Handle /* works for all: PCE */
157 #define __TASK_NAME__ "TaskAsop"
160 //
161 // Audio Stream Output Task definitions
162 //
164 // status codes
165 // Output FSM
166 #define ASOP_INITSYNC_NOTREADY ( 1 ) // ok, init-sync not ready
167 #define ASOP_SOK ( 0 ) // ok
168 #define ASOP_FORWARD_ERR ( -1 ) // forward (ASIT) error
169 #define ASOP_ENCRESET_ERR ( -2 ) // enc reset error
170 #define ASOP_DECINFO1_ERR ( -3 ) // dec info1 error
171 // Decode Processing
172 #define ASOP_DP_OUT_SIO_UPDATE ( 3 ) // new output selected
173 #define ASOP_DP_CB_DRAINED ( 2 ) // circular buffer drained
174 #define ASOP_DP_SOK ( 0 ) // ok
175 #define ASOP_DP_FORWARD_ERR ( -1 ) // forward (ASIT) error
176 #define ASOP_DP_DECINIT_ERR ( -2 ) // decode init error
177 #define ASOP_DP_DECSTREAM_ERR ( -3 ) // decode stream error
178 #define ASOP_DP_DECENC_ERR ( -4 ) // decode encode error
179 #define ASOP_DP_DECINFO2_ERR ( -5 ) // decode encode error
180 #define ASOP_DP_DECFINALTEST_ERR ( -6 ) // decode final error
184 /* Check if at least one output selected */
185 static Int checkOutSel(
186 const PAF_ASOT_Params *pP,
187 PAF_ASOT_Config *pAsotCfg,
188 Int *pOutSel
189 );
191 /* Check if at least one output sio changed */
192 static Int checkOutSio(
193 const PAF_ASOT_Params *pP,
194 PAF_ASOT_Config *pAsotCfg,
195 Int *pOutSioUpdate
196 );
198 // Initialize Output Processing state function
199 static Int PAF_ASOT_initOutProc(
200 const PAF_ASOT_Params *pP,
201 PAF_AST_Stream *xStr
202 );
204 // Initialize Output Processing state function
205 static Int PAF_ASOT_initSyncDecReset(
206 const PAF_ASOT_Params *pP,
207 const PAF_ASOT_Patchs *pQ,
208 PAF_ASOT_Config *pAsotCfg,
209 PAF_AudioFrame *pDecResetAf
210 );
212 // Purpose: ASOT Function for Output reset
213 static Int PAF_ASOT_outputReset(
214 const PAF_ASOT_Params *pP,
215 const PAF_ASOT_Patchs *pQ,
216 PAF_ASOT_Config *pAsotCfg
217 );
219 // Purpose: Init-Sync Dec Info1 state function.
220 // Performes Dec Info1 Init-Sync.
221 static Int PAF_ASOT_initSyncDecInfo1(
222 const PAF_ASOT_Params *pP,
223 const PAF_ASOT_Patchs *pQ,
224 PAF_ASOT_Config *pAsotCfg,
225 PAF_AudioFrame *pDecInfo1Af
226 );
228 // Purpose: ASOT function for ASP chain reset and ENC info
229 static Int PAF_ASOT_outputInfo1(
230 const PAF_ASOT_Params *pP,
231 const PAF_ASOT_Patchs *pQ,
232 PAF_ASOT_Config *pAsotCfg
233 );
235 // Purpose: Init-Sync Dec Decode1 state function.
236 // Performes Dec Decode1 Init-Sync.
237 static Int PAF_ASOT_initSyncDecDecode1(
238 const PAF_ASOT_Params *pP,
239 const PAF_ASOT_Patchs *pQ,
240 PAF_ASOT_Config *pAsotCfg
241 );
243 // Purpose: Init-Sync Re-Sync state function.
244 // Peformed Init-Sync using stored Dec Reset/Info1 AFs.
245 static Int PAF_ASOT_initSyncResync(
246 const PAF_ASOT_Params *pP,
247 const PAF_ASOT_Patchs *pQ,
248 PAF_ASOT_Config *pAsotCfg,
249 PAF_AudioFrame *pDecResetAf,
250 PAF_AudioFrame *pDecInfo1Af
251 );
253 #if 0
254 // Init-Sync update audio frame
255 static Int initSyncUpdateAf(
256 PAF_AudioFrame *dstAf,
257 PAF_AudioFrame *srcAf
258 );
259 #endif
261 // Reset audio frames
262 static Void resetAfs(
263 const PAF_ASOT_Params *pP,
264 PAF_AST_Stream *xStr
265 );
267 // Reset audio frame pointers to original values
268 static Void resetAfPointers(
269 const PAF_ASOT_Params *pP,
270 PAF_AST_Stream *xStr
271 );
273 // Reset audio frame meta data elements
274 static Void resetAfMetadata(
275 const PAF_ASOT_Params *pP,
276 PAF_AST_Stream *xStr
277 );
280 LINNO_DEFN(TaskAsop); /* Line number macros */
281 ERRNO_DEFN(TaskAsop); /* Error number macros */
283 // ASOT configuration
284 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
285 PAF_ASOT_Config gPAF_ASOT_config = {
286 NULL, // taskHandle
287 NULL, // acp
288 0,0,0, // CB drained flags (size DECODE_MAXN)
289 &gPAF_ASPM_config, // pAspmCfg
290 &gPAF_AST_config // pAstCfg
291 };
293 // Underflow threshold before circular buffer reset and return error to Top-Level FSM
294 #define DEC_OP_CB_RDAF_UND_THR ( 80 ) // FL: arbitrary setting
295 UInt32 gCbReadAfErr =0; // read circular buffer error count, not including underflows
296 UInt32 gDecOpCbRdAfUnd =0; // decoder output circular buffer underflow count
297 UInt32 gMaxDecOpCbRdAfUnd =0; // max (consecutive) decoder output circular buffer underflow count
298 UInt32 gMasterCbResetCnt =0; // master circular buffer reset count
300 // Global debug counters */
301 UInt32 gAsopTxSioReclaimCnt =0;
302 UInt32 gAsopInitOutProcCnt =0;
303 UInt32 gAsopInitSyncDecResetCnt =0;
304 UInt32 gAsopInitSyncDecInfo1Cnt =0;
305 UInt32 gAsopInitSyncDecDecode1Cnt =0;
306 UInt32 gAsopInitSyncResyncCnt =0;
307 UInt32 gAsopOutProcCnt =0;
308 UInt32 gAsopInitCnt =0;
309 UInt32 gAsopStreamCnt =0;
310 UInt32 gAsopEncodeCnt =0;
311 UInt32 gAsopFinalCnt =0;
312 UInt32 gAsopOutSioUpdateCnt =0;
313 UInt32 gAsopQuitCnt =0;
315 /*
316 * ======== taskAsopFxn ========
317 * Audio Stream Output Processing task function
318 */
319 Void taskAsopFxn(
320 // Int betaPrimeValue, // FL: revisit
321 const PAF_ASOT_Params *pP,
322 const PAF_ASOT_Patchs *pQ
323 )
324 {
325 PAF_ASOT_Config *pAsotCfg; /* ASOT configuration pointer */
326 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
327 Int as; /* Audio Stream Number (1, 2, etc.) */
328 Int z; /* input/encode/stream/decode/output counter */
329 Int i; /* phase */
330 Int zMS;
331 Int errno; // error number
332 Int8 procSleep; // whether to sleep: 0: No, 1: Yes
333 Int8 procOutDevSel; // whether to perform output device selection: 0: No, 1:Yes
334 Int outSel; // whether output device selected
335 enum { INIT_OUT_PROC_STATE,
336 INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE,
337 INITSYNC_RESYNC_STATE,
338 OUT_PROC_STATE } state;
339 PAF_AudioFrame decResetAf;
340 PAF_AudioFrame decInfo1Af;
341 Int loopCount = 0; // used to stop trace to see startup behavior.
344 Log_info0("Enter taskAsopFxn()");
346 //
347 // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
348 //
349 if (!pP)
350 {
351 TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
352 LINNO_RPRT(TaskAsop, -1);
353 return;
354 }
356 if (!pQ)
357 {
358 TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
359 LINNO_RPRT(TaskAsop, -1);
360 return;
361 }
363 //
364 // Audio Stream Output Task Configuration (*pAsotCfg):
365 //
366 pAsotCfg = &gPAF_ASOT_config; // initialize pointer to task configuration
367 pAsotCfg->taskHandle = Task_self(); // set task handle
368 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
370 /* Obtain Audio Stream Number (1, 2, etc.) */
371 as = pAstCfg->as;
372 TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
374 //
375 // Initialize message log trace and line number reporting
376 //
377 for (z=STREAM1; z < STREAMN; z++)
378 {
379 TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
380 }
381 LINNO_RPRT(TaskAsop, -1);
383 //
384 // Determine stream index
385 //
386 zMS = pAstCfg->masterStr;
388 // Initialize as per parametrized phases:
389 //
390 // In standard form these are:
391 // - Malloc: Memory Allocation
392 // - Config: Configuration Initialization
393 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
394 // - Common: Common Memory Initialization
395 // - AlgKey: Dec/Enc chain to Array Initialization
396 // - Device: I/O Device Initialization
397 // - Unused: (available)
398 // - Unused: (available)
399 //
400 LINNO_RPRT(TaskAsop, -2);
401 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
402 {
403 Int linno;
404 if (pP->fxns->initPhase[i])
405 {
406 linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
407 if (linno)
408 {
409 LINNO_RPRT(TaskAsop, linno);
410 return;
411 }
412 }
413 else
414 {
415 TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
416 }
417 TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
418 LINNO_RPRT(TaskAsop, -i-3);
419 }
421 //
422 // End of Initialization -- display memory usage report.
423 //
424 if (pP->fxns->memStatusPrint)
425 {
426 pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
427 HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
428 HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
429 }
431 //
432 // Main processing loop
433 //
434 for (z=STREAM1; z < STREAMN; z++)
435 {
436 TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
437 }
439 errno = 0; // init error indicator -- no error
440 procSleep = 1; // init sleep flag -- sleep
441 procOutDevSel = 1; // init device output selection flag -- perform output device selection
442 state = INIT_OUT_PROC_STATE; // init state
443 for (;;)
444 {
445 loopCount++;
446 TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
448 //
449 // Check forward (ASIT) error here, TBD
450 //
452 // any error forces idling of output
453 if (errno)
454 {
455 for (z=OUTPUT1; z < OUTPUTN; z++)
456 {
457 if (pAstCfg->xOut[z].hTxSio)
458 {
459 SIO_idle(pAstCfg->xOut[z].hTxSio);
460 }
461 }
463 TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
464 ERRNO_RPRT(TaskAsop, errno);
465 }
467 if (procSleep == 1)
468 {
469 TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
470 Task_sleep(1);
471 }
473 if (procOutDevSel == 1)
474 {
475 // select output devices
476 TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
477 errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
478 if (errno)
479 {
480 TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
482 procSleep = 1;
483 procOutDevSel = 1;
485 continue;
486 }
488 // if no output selected skip remaining processing
489 errno = checkOutSel(pP, pAsotCfg, &outSel);
490 if (errno < 0)
491 {
492 TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
494 procSleep = 1;
495 procOutDevSel = 1;
497 continue;
498 }
499 else if (!outSel)
500 {
501 TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
503 procSleep = 1;
504 procOutDevSel = 1;
506 continue;
507 }
508 }
510 switch (state)
511 {
512 case INIT_OUT_PROC_STATE:
513 gAsopInitOutProcCnt++;
514 Log_info0("TaskAsop: state=INIT_OUT_PROC_STATE");
516 //
517 // Output Processing initialization.
518 //
519 errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
520 if (errno < 0)
521 {
522 state = INIT_OUT_PROC_STATE;
523 procSleep = 1;
524 procOutDevSel = 1;
525 }
526 else
527 {
528 state = INITSYNC_DEC_RESET_STATE;
529 procSleep = 0;
530 procOutDevSel = 0;
531 }
533 break;
535 case INITSYNC_DEC_RESET_STATE:
536 gAsopInitSyncDecResetCnt++;
537 Log_info0("TaskAsop: state=INITSYNC_DEC_RESET_STATE");
539 //
540 // Dec Reset Init-Sync.
541 //
543 // Perform Dec Reset init-sync.
544 // Latch Dec Reset AF.
545 errno = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, &decResetAf);
546 if (errno < 0)
547 {
548 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
550 // sync error -- start over
551 state = INIT_OUT_PROC_STATE;
552 procSleep = 1;
553 procOutDevSel = 1;
554 }
555 else if (errno == ASOP_INITSYNC_NOTREADY)
556 {
557 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
559 // sync not ready -- try again
560 state = INITSYNC_DEC_RESET_STATE;
561 errno=0; // FL: temp hack
562 procSleep = 1;
563 procOutDevSel = 1;
564 }
565 else // errno==0
566 {
567 Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
569 // sync'd -- move on
570 state = INITSYNC_DEC_INFO1_STATE;
571 procSleep = 0;
572 procOutDevSel = 0;
573 }
575 break;
577 case INITSYNC_DEC_INFO1_STATE:
578 gAsopInitSyncDecInfo1Cnt++;
579 Log_info0("TaskAsop: state=INITSYNC_DEC_INFO1_STATE");
581 //
582 // Dec Info1 Init-Sync.
583 //
585 // Perform Dec Info1 init-sync.
586 // Latch Dec Info1 AF.
587 errno = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af);
588 if (errno < 0)
589 {
590 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
592 // sync error -- start over
593 state = INIT_OUT_PROC_STATE;
594 procSleep = 1;
595 procOutDevSel = 1;
596 }
597 else if (errno == ASOP_INITSYNC_NOTREADY)
598 {
599 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
601 // sync not ready -- try again
602 state = INITSYNC_DEC_INFO1_STATE;
603 errno=0; // FL: temp hack
604 procSleep = 1;
605 procOutDevSel = 0;
606 }
607 else // errno = 0
608 {
609 Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
611 // sync'd -- move on
612 state = INITSYNC_DEC_DECODE1_STATE;
613 procSleep = 0;
614 procOutDevSel = 0;
615 }
617 break;
619 case INITSYNC_DEC_DECODE1_STATE:
620 gAsopInitSyncDecDecode1Cnt++;
621 Log_info0("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE");
623 //
624 // Dec Info1 Init-Sync.
625 //
627 // Perform Dec Info1 init-sync.
628 // Latch Dec Info1 AF.
629 errno = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg);
630 if (errno < 0)
631 {
632 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
634 // sync error -- start over
635 state = INIT_OUT_PROC_STATE;
636 procSleep = 1;
637 procOutDevSel = 1;
638 }
639 else if (errno == ASOP_INITSYNC_NOTREADY)
640 {
641 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
643 // sync not ready -- try again
644 state = INITSYNC_DEC_DECODE1_STATE;
645 errno=0; // FL: temp hack
646 procSleep = 1;
647 procOutDevSel = 0;
648 }
649 else // errno = 0
650 {
651 Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
653 // sync'd -- move on
654 state = OUT_PROC_STATE;
655 procSleep = 0;
656 procOutDevSel = 0;
657 }
659 break;
661 case INITSYNC_RESYNC_STATE:
662 gAsopInitSyncResyncCnt++;
663 Log_info0("TaskAsop: state=INITSYNC_RESYNC_STATE");
665 //
666 // Re-Sync.
667 // Use stored AF info from init-sync.
668 // This is done in case of local error.
669 //
671 // Perform Dec Info1 init-sync.
672 errno = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf,
673 &decInfo1Af);
674 if (errno < 0)
675 {
676 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
678 // sync error -- start over
679 state = INIT_OUT_PROC_STATE;
680 procSleep = 1;
681 procOutDevSel = 1;
682 }
683 else
684 {
685 Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
687 // re-sync'd -- move on
688 state = OUT_PROC_STATE;
689 procSleep = 0;
690 procOutDevSel = 0;
691 }
693 break;
695 case OUT_PROC_STATE:
696 gAsopOutProcCnt++;
697 Log_info0("TaskAsop: state=OUT_PROC_STATE");
699 //
700 // Output Processing.
701 //
703 TRACE_VERBOSE0("TaskAsop: calling decodeProcessing.");
704 errno = pP->fxns->decodeProcessing(pP, pQ, pAsotCfg);
705 if (errno < 0)
706 {
707 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
709 //
710 // Output Processing exit, due to error
711 //
713 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
714 if (errno == ASOP_DP_FORWARD_ERR)
715 {
716 // forward (ASIT) error -- start over
717 state = INIT_OUT_PROC_STATE;
718 procSleep = 1;
719 procOutDevSel = 1;
720 }
721 else
722 {
723 // local (ASOT) error
724 state = INITSYNC_RESYNC_STATE;
725 procSleep = 1;
726 procOutDevSel = 0; // disallow device re-select if local error during output processing
727 }
728 }
729 else if (errno > 0)
730 {
731 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
733 //
734 // Output Processing exit, not due to error
735 //
737 TRACE_TERSE1("TaskAsop: decodeProcessing returns 0x%x, continue", errno);
738 if (errno == ASOP_DP_OUT_SIO_UPDATE)
739 {
740 // skip re-sync
741 // resume output processing after new output selected
742 state = OUT_PROC_STATE;
743 procSleep = 1;
744 procOutDevSel = 1;
745 }
746 }
747 else
748 {
749 Log_info1("TaskAsop: state=OUT_PROC_STATE errno=%d", errno);
751 //
752 // Output Processing exit, normal
753 //
755 TRACE_VERBOSE0("TaskAsop: outputProcessing complete with no error.");
757 // no error returned if CB drained
758 // (i.e. CB drained is normal behavior)
759 state = INIT_OUT_PROC_STATE;
760 procSleep = 1;
761 procOutDevSel = 1;
762 }
764 break;
766 default: // unknown state
767 TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
768 break;
769 }
770 } // End of main processing loop for (;;)
772 //Log_info0("Exit taskAsopFxn()");
773 }
775 // -----------------------------------------------------------------------------
776 // AST Initialization Function - Memory Allocation
777 //
778 // Name: PAF_ASOT_initPhaseMalloc
779 // Purpose: Audio Stream Output Task Function for initialization of data pointers
780 // by allocation of memory.
781 // From: audioStream1Task or equivalent
782 // Uses: See code.
783 // States: x
784 // Return: 0 on success.
785 // Source code line number on MEM_calloc failure.
786 // Trace: Message Log "trace" in Debug Project Configuration reports:
787 // * State information as per parent.
788 // * Memory allocation errors.
789 //
791 Int
792 PAF_ASOT_initPhaseMalloc (
793 const PAF_ASOT_Params *pP,
794 const PAF_ASOT_Patchs *pQ,
795 PAF_ASOT_Config *pAsotCfg
796 )
797 {
798 PAF_AST_Config *pAstCfg;
799 Int as; /* Audio Stream Number (1, 2, etc.) */
800 Int zMS;
801 Error_Block eb;
802 //Int i;
804 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
805 as = pAstCfg->as;
806 zMS = pAstCfg->masterStr;
808 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
810 // Initialize error block
811 Error_init(&eb);
813 /* Stream memory */
814 if (!(pAstCfg->xStr = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMN * sizeof (*pAstCfg->xStr), 4, &eb)))
815 {
816 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
817 SW_BREAKPOINT;
818 return __LINE__;
819 }
820 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xStr) %d bytes from space %d at 0x%x.",
821 STREAMN * sizeof (*pAstCfg->xStr),
822 HEAP_ID_INTERNAL, (IArg)pAstCfg->xStr);
824 {
825 Int z; /* stream counter */
827 PAF_AudioFrame *fBuf;
829 if (!(fBuf = (PAF_AudioFrame *)Memory_calloc((IHeap_Handle)HEAP_INTERNAL, STREAMS * sizeof (*fBuf), 4, &eb)))
830 {
831 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
832 SW_BREAKPOINT;
833 return __LINE__;
834 }
835 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (fBuf) %d bytes from space %d at 0x%x.",
836 STREAMS * sizeof (*fBuf),
837 HEAP_ID_INTERNAL, (IArg)fBuf);
839 for (z=STREAM1; z < STREAMN; z++)
840 {
841 pAstCfg->xStr[z].pAudioFrame = &fBuf[z-STREAM1];
842 TRACE_TERSE2("pAstCfg->xStr[%d].pAudioFrame = 0x%x", z, (IArg)pAstCfg->xStr[z].pAudioFrame);
843 }
844 }
846 /* Encode memory */
847 if (!(pAstCfg->xEnc = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, ENCODEN * sizeof (*pAstCfg->xEnc), 4, &eb)))
848 {
849 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
850 SW_BREAKPOINT;
851 return __LINE__;
852 }
853 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xEnc) %d bytes from space %d at 0x%x.",
854 ENCODEN * sizeof (*pAstCfg->xEnc),
855 HEAP_ID_INTERNAL, (IArg)pAstCfg->xEnc);
857 /* Output memory */
858 if (!(pAstCfg->xOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAstCfg->xOut), 4, &eb)))
859 {
860 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
861 SW_BREAKPOINT;
862 return __LINE__;
863 }
864 TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAstCfg->xOut) %d bytes from space %d at 0x%x.",
865 OUTPUTN * sizeof (*pAstCfg->xOut),
866 HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
868 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
869 return 0;
870 } //PAF_ASOT_initPhaseMalloc
872 // -----------------------------------------------------------------------------
873 // ASOT Initialization Function - Memory Initialization from Configuration
874 //
875 // Name: PAF_ASOT_initPhaseConfig
876 // Purpose: Audio Stream Output Task Function for initialization of data values
877 // from parameters.
878 // From: audioStream1Task or equivalent
879 // Uses: See code.
880 // States: x
881 // Return: 0 on success.
882 // Other as per initFrame0 and initFrame1.
883 // Trace: Message Log "trace" in Debug Project Configuration reports:
884 // * State information as per parent.
885 //
886 Int
887 PAF_ASOT_initPhaseConfig(
888 const PAF_ASOT_Params *pP,
889 const PAF_ASOT_Patchs *pQ,
890 PAF_ASOT_Config *pAsotCfg
891 )
892 {
893 PAF_AST_Config *pAstCfg;
894 Int as; /* Audio Stream Number (1, 2, etc.) */
895 Int z; /* input/encode/stream/decode/output counter */
896 Int zMS;
898 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
899 as = pAstCfg->as;
900 zMS = pAstCfg->masterStr;
902 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
904 //
905 // Unspecified elements have been initialized to zero during alloc
906 //
908 for (z=STREAM1; z < STREAMN; z++)
909 {
910 Int linno;
911 if (linno = pP->fxns->initFrame0(pP, pQ, pAsotCfg, z))
912 {
913 return linno;
914 }
915 if (linno = pP->fxns->initFrame1(pP, pQ, pAsotCfg, z, -1))
916 {
917 return linno;
918 }
919 }
921 for (z=ENCODE1; z < ENCODEN; z++)
922 {
923 Int zO = pP->outputsFromEncodes[z];
924 Int zS = pP->streamsFromEncodes[z];
925 pAstCfg->xEnc[z].encodeControl.size = sizeof(pAstCfg->xEnc[z].encodeControl);
926 pAstCfg->xEnc[z].encodeControl.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
927 pAstCfg->xEnc[z].encodeControl.pVolumeStatus = &pAstCfg->xEnc[z].volumeStatus;
928 pAstCfg->xEnc[z].encodeControl.pOutBufConfig = &pAstCfg->xOut[zO].outBufConfig;
929 pAstCfg->xEnc[z].encodeStatus = *pP->z_pEncodeStatus[z];
930 pAstCfg->xEnc[z].encodeControl.encActive = pAstCfg->xEnc[z].encodeStatus.select;
931 pAstCfg->xEnc[z].volumeStatus = *pP->pVolumeStatus;
932 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame = pAstCfg->xStr[zS].pAudioFrame;
933 }
935 for (z=OUTPUT1; z < OUTPUTN; z++)
936 {
937 pAstCfg->xOut[z].outBufStatus = *pP->pOutBufStatus;
938 }
940 TRACE_TERSE1("PAF_ASOT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
941 return 0;
942 } //PAF_ASOT_initPhaseConfig
944 // -----------------------------------------------------------------------------
945 // ASOT Initialization Function - ACP Algorithm Instantiation
946 //
947 // Name: PAF_ASOT_initPhaseAcpAlg
948 // Purpose: Audio Stream Input Task Function for initialization of ACP by
949 // instantiation of the algorithm.
950 // From: audioStream1Task or equivalent
951 // Uses: See code.
952 // States: x
953 // Return: 0 on success.
954 // Source code line number on ACP Algorithm creation failure.
955 // Trace: Message Log "trace" in Debug Project Configuration reports:
956 // * State information as per parent.
957 // * Memory allocation errors.
958 //
959 Int
960 PAF_ASOT_initPhaseAcpAlg(
961 const PAF_ASOT_Params *pP,
962 const PAF_ASOT_Patchs *pQ,
963 PAF_ASOT_Config *pAsotCfg
964 )
965 {
966 PAF_AST_Config *pAstCfg;
967 Int as; /* Audio Stream Number (1, 2, etc.) */
968 Int z; /* input/encode/stream/decode/output counter */
969 Int betaPrimeOffset;
970 ACP_Handle acp;
971 Int zMS;
972 Int zS, zX;
974 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
975 as = pAstCfg->as;
976 zMS = pAstCfg->masterStr;
978 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
980 ACP_MDS_init();
982 if (!(acp = (ACP_Handle )ACP_MDS_create(NULL)))
983 {
984 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
985 return __LINE__;
986 }
987 pAsotCfg->acp = acp;
989 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
990 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
992 for (z=ENCODE1; z < ENCODEN; z++)
993 {
994 zS = pP->streamsFromEncodes[z];
995 acp->fxns->attach(acp, ACP_SERIES_STD,
996 STD_BETA_ENCODE + betaPrimeOffset * (as-1+zS),
997 (IALG_Status *)&pAstCfg->xEnc[z].encodeStatus);
998 acp->fxns->attach(acp, ACP_SERIES_STD,
999 STD_BETA_VOLUME + betaPrimeOffset * (as-1+zS),
1000 (IALG_Status *)&pAstCfg->xEnc[z].volumeStatus);
1001 /* Ignore errors, not reported. */
1002 }
1004 for (z=OUTPUT1; z < OUTPUTN; z++)
1005 {
1006 zS = z;
1007 for (zX = ENCODE1; zX < ENCODEN; zX++)
1008 {
1009 if (pP->outputsFromEncodes[zX] == z)
1010 {
1011 zS = pP->streamsFromEncodes[zX];
1012 break;
1013 }
1014 }
1015 acp->fxns->attach(acp, ACP_SERIES_STD,
1016 STD_BETA_OB + betaPrimeOffset * (as-1+zS),
1017 (IALG_Status *)&pAstCfg->xOut[z].outBufStatus);
1018 /* Ignore errors, not reported. */
1019 }
1021 TRACE_TERSE1("PAF_ASOT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1023 return 0;
1024 } //PAF_ASOT_initPhaseAcpAlg
1026 // -----------------------------------------------------------------------------
1027 // ASOT Initialization Function - Common Memory
1028 //
1029 // Name: PAF_ASOT_initPhaseCommon
1030 // Purpose: Audio Stream Output Task Function for allocation of common memory.
1031 // From: audioStream1Task or equivalent
1032 // Uses: See code.
1033 // States: x
1034 // Return: 0 on success.
1035 // Source code line number on PAF_ALG_alloc failure.
1036 // Source code line number on PAF_ALG_mallocMemory failure.
1037 // Source code line number on Decode Chain initialization failure.
1038 // Source code line number on ASP Chain initialization failure.
1039 // Source code line number on Encode Chain initialization failure.
1040 // Trace: Message Log "trace" in Debug Project Configuration reports:
1041 // * State information as per parent.
1042 // * Memory allocation errors.
1043 //
1044 Int
1045 PAF_ASOT_initPhaseCommon(
1046 const PAF_ASOT_Params *pP,
1047 const PAF_ASOT_Patchs *pQ,
1048 PAF_ASOT_Config *pAsotCfg
1049 )
1050 {
1051 PAF_AST_Config *pAstCfg;
1052 Int as; /* Audio Stream Number (1, 2, etc.) */
1053 Int z; /* stream counter */
1054 Int g; /* gear */
1055 ACP_Handle acp;
1056 PAF_IALG_Config pafAlgConfig;
1057 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1059 acp = pAsotCfg->acp;
1060 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1061 as = pAstCfg->as;
1063 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: initialization phase - Common Memory");
1065 //
1066 // Determine memory needs and instantiate algorithms across audio streams
1067 //
1068 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_setup.");
1069 PAF_ALG_setup(&pafAlgConfig,
1070 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1071 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1072 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1073 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1074 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1075 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1076 HEAP_CLEAR);
1078 if (pP->fxns->headerPrint)
1079 {
1080 pP->fxns->headerPrint();
1081 }
1083 for (z = STREAM1; z < STREAMN; z++)
1084 {
1085 //Int zD, zE, zX;
1086 Int zE, zX;
1088 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1090 //
1091 // Determine common memory needs for:
1092 // (1) ASP Algorithms
1093 // (2) Encode Algorithms
1094 // (3) Logical Output drivers
1095 //
1096 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1098 zE = -1;
1099 for (zX = ENCODE1; zX < ENCODEN; zX++)
1100 {
1101 if (pP->streamsFromEncodes[zX] == z)
1102 {
1103 zE = zX;
1104 break;
1105 }
1106 }
1108 TRACE_TERSE1("Calling PAF_ALG_ALLOC for stream common[%d].", z);
1109 if (PAF_ALG_ALLOC(aspLinkInit[z-STREAM1][0], common[z]))
1110 {
1111 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1112 TRACE_TERSE2("Failed to alloc %d bytes from space %d ", common[z]->size, common[z]->space);
1113 SW_BREAKPOINT;
1114 return __LINE__;
1115 }
1116 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1117 if (pP->fxns->allocPrint)
1118 {
1119 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(aspLinkInit[z-STREAM1][0]), sizeof (*(aspLinkInit[z-STREAM1][0])), &pafAlgConfig);
1120 }
1122 if (zE >= 0)
1123 {
1124 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC/ for encoder common[%d].", z);
1125 if (PAF_ALG_ALLOC(encLinkInit[zE-ENCODE1], common[z]))
1126 {
1127 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1128 SW_BREAKPOINT;
1129 return __LINE__;
1130 }
1131 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1132 if (pP->fxns->allocPrint)
1133 {
1134 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(encLinkInit[z-ENCODE1]), sizeof (*(encLinkInit[z-ENCODE1])), &pafAlgConfig);
1135 }
1136 }
1138 //
1139 // Determine common memory needs of Logical IO drivers
1140 //
1142 if (OUTPUT1 <= z && z < OUTPUTN)
1143 {
1144 TRACE_TERSE1("PAF_ASOT_initPhaseCommon: calling PAF_ALG_ALLOC outLinkInit common[%d].", z);
1145 if (PAF_ALG_ALLOC(outLinkInit[z-OUTPUT1], common[z]))
1146 {
1147 TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: PAF_ALG_alloc failed", as+z);
1148 TRACE_TERSE2("Failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1149 SW_BREAKPOINT;
1150 return __LINE__;
1151 }
1152 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1153 if (pP->fxns->allocPrint)
1154 {
1155 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(outLinkInit[z-INPUT1]), sizeof (*(outLinkInit[z-INPUT1])), &pafAlgConfig);
1156 }
1157 }
1158 }
1159 {
1160 // Changes made to share scratch between zones
1161 // Assume maximum 3 zones and scratch common memory is at offset 0;
1162 int max=0;
1163 for (z=STREAM1; z<STREAMN; z++)
1164 {
1165 if (max < common[z][0].size)
1166 {
1167 max = common[z][0].size;
1168 }
1169 }
1170 common[STREAM1][0].size=max;
1171 for (z=STREAM1+1; z<STREAMN; z++)
1172 {
1173 common[z][0].size = 0;
1174 }
1175 }
1177 //
1178 // Allocate common memory for:
1179 // (1) ASP Algorithms
1180 // (2) Encode Algorithms
1181 // (3) Logical Output drivers
1182 //
1183 for (z = STREAM1; z < STREAMN; z++)
1184 {
1185 //Int zD, zE, zX;
1186 Int zE, zX;
1188 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1189 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1190 {
1191 TRACE_TERSE1("AS%d: PAF_ALG_mallocMemory failed", as+z);
1192 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1193 SW_BREAKPOINT;
1194 return __LINE__;
1195 }
1196 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1197 // share zone0 scratch with all zones
1198 common[z][0].base = common[0][0].base;
1199 if (pP->fxns->commonPrint)
1200 {
1201 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1202 }
1204 zE = -1;
1205 for (zX = ENCODE1; zX < ENCODEN; zX++)
1206 {
1207 if (pP->streamsFromEncodes[zX] == z)
1208 {
1209 zE = zX;
1210 break;
1211 }
1212 }
1214 pAstCfg->xStr[z].aspChain[0] = NULL;
1215 for (g=0; g < GEARS; g++)
1216 {
1217 PAF_ASP_Chain *chain;
1218 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for ASPs.");
1219 chain = PAF_ASP_chainInit(&pAstCfg->xStr[z].aspChainData[g], pP->pChainFxns,
1220 HEAP_INTERNAL, as+z, acp, &trace,
1221 aspLinkInit[z-STREAM1][g], pAstCfg->xStr[z].aspChain[0], common[z], &pafAlgConfig);
1222 if (!chain)
1223 {
1224 TRACE_TERSE2("AS%d: ASP chain %d initialization failed", as+z, g);
1225 return __LINE__;
1226 }
1227 else
1228 {
1229 pAstCfg->xStr[z].aspChain[g] = chain;
1230 }
1231 }
1233 if (zE >= 0)
1234 {
1235 PAF_ASP_Chain *chain;
1236 TRACE_TERSE0("PAF_ASOT_initPhaseCommon: calling PAF_ASP_chainInit for encode.");
1237 chain = PAF_ASP_chainInit(&pAstCfg->xEnc[zE].encChainData, pP->pChainFxns,
1238 HEAP_INTERNAL, as+z, acp, &trace,
1239 encLinkInit[zE-ENCODE1], NULL, common[z], &pafAlgConfig);
1240 if (!chain)
1241 {
1242 TRACE_TERSE1("AS%d: Encode chain initialization failed", as+z);
1243 return __LINE__;
1244 }
1245 }
1247 //
1248 // Allocate non-common memories for Logical IO drivers
1249 // Since these structures are used at run-time we allocate from external memory
1250 if (OUTPUT1 <= z && z < OUTPUTN)
1251 {
1252 PAF_ASP_Chain *chain;
1253 TRACE_TERSE2("PAF_ASOT_initPhaseMalloc: AS%d: non-common output chain init for %d",
1254 as+z, z);
1255 chain = PAF_ASP_chainInit (&pAstCfg->xOut[z].outChainData, pP->pChainFxns,
1256 HEAP_EXTERNAL, as+z, acp, &trace,
1257 outLinkInit[z-OUTPUT1], NULL, common[z], &pafAlgConfig);
1258 if (!chain)
1259 {
1260 TRACE_TERSE1("AS%d: Output chain initialization failed", as+z);
1261 return __LINE__;
1262 }
1263 }
1264 }
1265 TRACE_TERSE1("AS%d: PAF_ASOT_initPhaseCommon: Returning complete.", as+z);
1267 return 0;
1268 } //PAF_ASOT_initPhaseCommon
1270 // -----------------------------------------------------------------------------
1271 // ASOT Initialization Function - Algorithm Keys
1272 //
1273 // Name: PAF_ASOT_initPhaseAlgKey
1274 // Purpose: Audio Stream Output Task Function for initialization of data values
1275 // from parameters for Algorithm Keys.
1276 // From: audioStream1Task or equivalent
1277 // Uses: See code.
1278 // States: x
1279 // Return: 0.
1280 // Trace: Message Log "trace" in Debug Project Configuration reports:
1281 // * State information as per parent.
1282 //
1283 // .............................................................................
1284 Int
1285 PAF_ASOT_initPhaseAlgKey(
1286 const PAF_ASOT_Params *pP,
1287 const PAF_ASOT_Patchs *pQ,
1288 PAF_ASOT_Config *pAsotCfg
1289 )
1290 {
1291 PAF_AST_Config *pAstCfg;
1292 Int as; /* Audio Stream Number (1, 2, etc.) */
1293 Int z; /* decode/encode counter */
1294 Int s; /* key number */
1295 PAF_ASP_Link *that;
1297 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1298 as = pAstCfg->as;
1299 (void)as; // clear compiler warning in case not used with tracing disabled
1301 TRACE_VERBOSE1("PAF_ASOT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1303 for (z=ENCODE1; z < ENCODEN; z++)
1304 {
1305 for (s=0; s < pP->pEncAlgKey->length; s++)
1306 {
1307 if ((pP->pEncAlgKey->code[s].full != 0) &&
1308 (that = PAF_ASP_chainFind(&pAstCfg->xEnc[z].encChainData, pP->pEncAlgKey->code[s])))
1309 {
1310 pAstCfg->xEnc[z].encAlg[s] = (ALG_Handle )that->alg;
1311 }
1312 /* Cast in interface, for now --Kurt */
1313 else
1314 {
1315 pAstCfg->xEnc[z].encAlg[s] = NULL;
1316 }
1317 }
1318 }
1320 return 0;
1321 } //PAF_ASOT_initPhaseAlgKey
1323 // -----------------------------------------------------------------------------
1324 // ASOT Initialization Function - I/O Devices
1325 //
1326 // Name: PAF_ASOT_initPhaseDevice
1327 // Purpose: Audio Stream Output Task Function for initialization of I/O Devices.
1328 // From: audioStream1Task or equivalent
1329 // Uses: See code.
1330 // States: x
1331 // Return: 0 on success.
1332 // Source code line number on device allocation failure.
1333 // Trace: Message Log "trace" in Debug Project Configuration reports:
1334 // * State information as per parent.
1335 // * Memory allocation errors.
1336 //
1337 Int
1338 PAF_ASOT_initPhaseDevice(
1339 const PAF_ASOT_Params *pP,
1340 const PAF_ASOT_Patchs *pQ,
1341 PAF_ASOT_Config *pAsotCfg
1342 )
1343 {
1344 PAF_AST_Config *pAstCfg;
1345 Int as; /* Audio Stream Number (1, 2, etc.) */
1346 Int z; /* input/output counter */
1347 PAF_SIO_IALG_Obj *pObj;
1348 PAF_SIO_IALG_Config *pAlgConfig;
1349 PAF_IALG_Config pafAlgConfig;
1351 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1352 as = pAstCfg->as;
1353 (void)as; // clear compiler warning in case not used with tracing disabled
1355 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1357 if(pP->fxns->bufMemPrint)
1358 {
1359 PAF_ALG_setup (&pafAlgConfig,
1360 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1361 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1362 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1363 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1364 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1365 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1366 HEAP_CLEAR);
1367 TRACE_TERSE2("PAF_ASOT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1368 }
1370 for (z=OUTPUT1; z < OUTPUTN; z++)
1371 {
1372 PAF_OutBufConfig *pConfig = &pAstCfg->xOut[z].outBufConfig;
1374 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xOut[z].outChainData.head->alg;
1375 pAlgConfig = &pObj->config;
1377 pAstCfg->xOut[z].hTxSio = NULL;
1378 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1379 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1380 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1381 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1382 pConfig->sizeofElement = 3;
1383 pConfig->precision = 24;
1384 if(pP->fxns->bufMemPrint)
1385 {
1386 pP->fxns->bufMemPrint(z,pAlgConfig->pMemRec[0].size,PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space),1);
1387 }
1388 }
1389 TRACE_TERSE1("PAF_ASOT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1391 return 0;
1392 } //PAF_ASOT_initPhaseDevice
1394 // -----------------------------------------------------------------------------
1395 // ASOT Initialization Function Helper - Initialization of Audio Frame
1396 //
1397 // Name: PAF_ASOT_initFrame0
1398 // Purpose: Audio Stream Output Task Function for initialization of the Audio
1399 // Frame(s) by memory allocation and loading of data pointers
1400 // and values.
1401 // From: AST Parameter Function -> decodeInfo
1402 // Uses: See code.
1403 // States: x
1404 // Return: 0 on success.
1405 // Source code line number on MEM_calloc failure.
1406 // Source code line number on unsupported option.
1407 // Trace: Message Log "trace" in Debug Project Configuration reports:
1408 // * Memory allocation errors.
1409 // * Unsupported option errors.
1410 //
1412 // MID 314
1413 extern const char AFChanPtrMap[PAF_MAXNUMCHAN+1][PAF_MAXNUMCHAN];
1414 extern PAF_ChannelConfigurationMaskTable PAF_ASP_stdCCMT_patch;
1416 Int
1417 PAF_ASOT_initFrame0(
1418 const PAF_ASOT_Params *pP,
1419 const PAF_ASOT_Patchs *pQ,
1420 PAF_ASOT_Config *pAsotCfg,
1421 Int z
1422 )
1423 {
1424 PAF_AST_Config *pAstCfg;
1425 Int as; /* Audio Stream Number (1, 2, etc.) */
1426 Int ch;
1427 //Int aLen;
1428 Int aLen_int=0,aLen_ext=0;
1429 Int aSize = sizeof(PAF_AudioData);
1430 Int aAlign = aSize < sizeof (int) ? sizeof (int) : aSize;
1431 Int maxFrameLength = pP->maxFramelength;
1432 Int zX;
1433 PAF_AudioData *aBuf_int=NULL;
1434 PAF_AudioData *aBuf_ext=NULL;
1435 XDAS_UInt8 *metadataBuf;
1436 char i;
1437 Error_Block eb;
1439 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1440 as = pAstCfg->as;
1442 // Initialize error block
1443 Error_init(&eb);
1445 // Compute maximum framelength (needed for ARC support)
1446 maxFrameLength += PA_MODULO - maxFrameLength % PA_MODULO;
1447 //aLen = numchan[z] * maxFrameLength;
1448 for (i=0; i < numchan[z]; i++)
1449 {
1450 if (pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1451 {
1452 aLen_int += maxFrameLength;
1453 }
1454 else
1455 {
1456 aLen_ext += maxFrameLength;
1457 }
1458 }
1460 //
1461 // Initialize audio frame elements directly
1462 //
1463 pAstCfg->xStr[z].pAudioFrame->fxns = pP->pAudioFrameFunctions;
1464 pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN; ///
1465 /// pAstCfg->xStr[z].pAudioFrame->data.nChannels = PAF_MAXNUMCHAN_AF;
1466 pAstCfg->xStr[z].pAudioFrame->data.nSamples = FRAMELENGTH;
1467 pAstCfg->xStr[z].pAudioFrame->data.sample = pAstCfg->xStr[z].audioFrameChannelPointers;
1468 pAstCfg->xStr[z].pAudioFrame->data.samsiz = pAstCfg->xStr[z].audioFrameChannelSizes;
1469 pAstCfg->xStr[z].pAudioFrame->pChannelConfigurationMaskTable = &PAF_ASP_stdCCMT;
1471 //
1472 // Allocate memory for and initialize pointers to audio data buffers
1473 //
1474 // The NUMCHANMASK is used to identify the channels for which data
1475 // buffers can be allocated. Using this mask and switch statement
1476 // rather than some other construct allows efficient code generation,
1477 // providing just the code necessary (with significant savings).
1478 //
1479 if (pP->fxns->bufMemPrint)
1480 {
1481 pP->fxns->bufMemPrint(z, aLen_int*aSize, HEAP_ID_FRMBUF, 2);
1482 pP->fxns->bufMemPrint(z, aLen_ext*aSize, HEAP_ID_EXTERNAL, 2);
1483 }
1485 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for audio buffers", as+z);
1487 if (aLen_int*aSize!=0) // check size != 0, otherwise malloc throws fatal error
1488 {
1489 if (!(aBuf_int = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_FRMBUF, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb))) //Qin: Add start offset
1490 {
1491 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1492 TRACE_TERSE2(" maxFrameLength: %d. aLen_int*aSize: %d", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize);
1493 SW_BREAKPOINT;
1494 return __LINE__;
1495 }
1496 }
1498 if (aLen_ext*aSize!=0)
1499 {
1500 if (!(aBuf_ext = (PAF_AudioData *)Memory_calloc((IHeap_Handle)HEAP_EXTERNAL, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, aAlign, &eb)))//Qin: Add start offset
1501 {
1502 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1503 TRACE_TERSE2(" maxFrameLength: %d. aLen_ext*aSize: %d", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize);
1504 SW_BREAKPOINT;
1505 return __LINE__;
1506 }
1507 }
1509 TRACE_TERSE3(" maxFrameLength: %d. aLen_int*aSize: %d. aBuf_int: 0x%x", maxFrameLength, (aLen_int+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_int);
1510 TRACE_TERSE3(" maxFrameLength: %d. aLen_ext*aSize: %d. aBuf_ext: 0x%x", maxFrameLength, (aLen_ext+(maxFrameLength-FRAMELENGTH))*aSize, (IArg)aBuf_ext);
1512 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc for metadata buffers", as+z);
1513 if (!(metadataBuf = (XDAS_UInt8 *)Memory_calloc((IHeap_Handle)HEAP_MDBUF, pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf, pP->pMetadataBufStatus->alignment, &eb)))
1514 {
1515 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: Memory_calloc failed", as+z);
1516 TRACE_TERSE1(" bufSize*NumBuf: %d", pP->pMetadataBufStatus->bufSize*pP->pMetadataBufStatus->NumBuf);
1517 SW_BREAKPOINT;
1518 return __LINE__;
1519 }
1521 {
1522 Int i;
1524 #pragma UNROLL(1)
1525 for (i=0; i < PAF_MAXNUMCHAN_AF; i++)
1526 {
1527 pAstCfg->xStr[z].audioFrameChannelPointers[i] = NULL;
1528 }
1529 }
1531 // MID 314
1532 if((numchan[z] > PAF_MAXNUMCHAN) || (numchan[z] < 1))
1533 {
1534 TRACE_TERSE1("PAF_ASOT_initFrame0: AS%d: unsupported option", as+z);
1535 return __LINE__;
1536 }
1537 else
1538 {
1539 Int j = 0;
1540 Int k = 0;
1541 TRACE_TERSE1("PAF_ASOT_initFrame0: AFChanPtrMap[%d][i]", numchan[z]);
1542 for(i=0;i<numchan[z];i++)
1543 {
1544 char chan = AFChanPtrMap[numchan[z]][i];
1545 if(chan != -1)
1546 {
1547 if(pP->pAudioFrameBufStatus->space[i] == IALG_SARAM)
1548 {
1549 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_int + maxFrameLength*(j+1) - FRAMELENGTH;
1550 j++;
1551 }
1552 else
1553 {
1554 pAstCfg->xStr[z].audioFrameChannelPointers[chan] = aBuf_ext + maxFrameLength*(k+1) - FRAMELENGTH;
1555 k++;
1556 }
1557 TRACE_TERSE3("PAF_ASOT_initFrame0: chan = %d = AFChanPtrMap[%d][%d].", chan, numchan[z], i);
1558 TRACE_TERSE2("PAF_ASOT_initFrame0: audioFrameChannelPointers[%d]: 0x%x", chan, (IArg)pAstCfg->xStr[z].audioFrameChannelPointers[chan]);
1559 }
1560 }
1561 }
1563 for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
1564 {
1565 if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
1566 {
1567 pAstCfg->xStr[z].origAudioFrameChannelPointers[ch] = pAstCfg->xStr[z].audioFrameChannelPointers[ch];
1568 }
1569 }
1571 //
1572 // Initialize meta data elements
1573 //
1574 pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1575 pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
1576 pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
1577 pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1578 pAstCfg->xStr[z].pAudioFrame->privateMetadataBufSize = pP->pMetadataBufStatus->bufSize;
1579 for(i=0;i<pP->pMetadataBufStatus->NumBuf;i++)
1580 {
1581 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1582 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1583 pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].pMdBuf = metadataBuf + pP->pMetadataBufStatus->bufSize*i;
1584 }
1586 //
1587 // Initialize decoder elements directly
1588 //
1590 for (zX = DECODE1; zX < DECODEN; zX++)
1591 {
1592 if (pP->streamsFromDecodes[zX] == z)
1593 {
1594 #ifdef NOAUDIOSHARE
1595 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = 0;
1596 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = NULL;
1597 #else /* NOAUDIOSHARE */
1598 pAstCfg->xDec[zX].decodeInStruct.audioShare.nSamples = aLen_int;
1599 pAstCfg->xDec[zX].decodeInStruct.audioShare.sample = aBuf_int;
1600 #endif /* NOAUDIOSHARE */
1601 }
1602 }
1604 return 0;
1605 } //PAF_ASOT_initFrame0
1607 // -----------------------------------------------------------------------------
1608 // ASOT Initialization Function Helper - Reinitialization of Audio Frame
1609 // AST Decoding Function - Reinitialization of Audio Frame
1610 //
1611 // Name: PAF_ASOT_initFrame1
1612 // Purpose: Audio Stream Task Function for initialization or reinitiali-
1613 // zation of the Audio Frame(s) by loading of data values of a
1614 // time-varying nature.
1615 // From: audioStream1Task or equivalent
1616 // AST Parameter Function -> decodeInfo
1617 // AST Parameter Function -> decodeDecode
1618 // Uses: See code.
1619 // States: x
1620 // Return: 0.
1621 // Trace: None.
1622 //
1623 Int
1624 PAF_ASOT_initFrame1(
1625 const PAF_ASOT_Params *pP,
1626 const PAF_ASOT_Patchs *pQ,
1627 PAF_ASOT_Config *pAsotCfg,
1628 Int z,
1629 Int apply
1630 )
1631 {
1632 PAF_AST_Config *pAstCfg;
1634 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1636 //
1637 // Reinitialize audio frame elements:
1638 //
1639 // Channel Configurations during sys init = Unknown
1640 // " " during info or decode = None
1641 //
1642 // Sample Rate / Count during sys init, info or decode = Unknown / 0
1643 //
1645 if (apply < 0)
1646 {
1647 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_UNKNOWN;
1648 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_UNKNOWN;
1649 }
1650 else
1651 {
1652 pAstCfg->xStr[z].pAudioFrame->channelConfigurationRequest.legacy = PAF_CC_NONE;
1653 pAstCfg->xStr[z].pAudioFrame->channelConfigurationStream.legacy = PAF_CC_NONE;
1654 }
1656 if (apply < 1)
1657 {
1658 pAstCfg->xStr[z].pAudioFrame->sampleRate = PAF_SAMPLERATE_UNKNOWN;
1659 pAstCfg->xStr[z].pAudioFrame->sampleCount = 0;
1660 }
1662 return 0;
1663 } //PAF_ASOT_initFrame1
1665 // -----------------------------------------------------------------------------
1666 // ASOT Selection Function - Output Device Selection
1667 //
1668 // Name: PAF_ASOT_selectDevices
1669 // Purpose: Audio Stream Output Task Function for selecting the devices used
1670 // for output.
1671 // From: audioStream1Task or equivalent
1672 // Uses: See code.
1673 // States: x
1674 // Return: Error number in standard form (0 on success).
1675 // Trace: Message Log "trace" in Debug Project Configuration reports:
1676 // * State information as per parent.
1677 //
1678 Int
1679 PAF_ASOT_selectDevices(
1680 const PAF_ASOT_Params *pP,
1681 const PAF_ASOT_Patchs *pQ,
1682 PAF_ASOT_Config *pAsotCfg
1683 )
1684 {
1685 PAF_AST_Config *pAstCfg;
1686 Int as; /* Audio Stream Number (1, 2, etc.) */
1687 Int z; /* input/output counter */
1688 Int errno = 0; /* error number */
1689 Int errme; /* error number, local */
1690 Int device;
1692 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1693 as = pAstCfg->as;
1694 (void)as; // clear compiler warning in case not used with tracing disabled
1696 // Select output devices
1697 for (z=OUTPUT1; z < OUTPUTN; z++)
1698 {
1699 if ((device = pAstCfg->xOut[z].outBufStatus.sioSelect) >= 0)
1700 {
1701 TRACE_VERBOSE2("PAF_ASOT_selectDevices: AS%d: output device %d selecting ...", as+z, device);
1703 /* check for valid index into device array */
1704 if (device >= pQ->devout->n)
1705 {
1706 device = 0; /* treat as device None */
1707 }
1709 errme = pP->fxns->deviceSelect(&pAstCfg->xOut[z].hTxSio, SIO_OUTPUT,
1710 HEAP_ID_OUTBUF, (Ptr)pQ->devout->x[device]);
1711 if (errme)
1712 {
1713 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1714 if (!errno)
1715 {
1716 errno = ASPERR_DEVOUT + errme;
1717 }
1718 pAstCfg->xOut[z].outBufStatus.sioSelect = 0x80;
1719 }
1720 else
1721 {
1722 Int zE;
1724 pAstCfg->xOut[z].outBufStatus.sioSelect = device | 0x80;
1725 // register outBufStatus and encodeStatus pointers with output devices
1726 // This enables proper IEC encapsulation.
1727 if (pAstCfg->xOut[z].hTxSio)
1728 {
1729 // set max # of output buffers (use override if necessary)
1730 if (pAstCfg->xOut[z].outBufStatus.maxNumBufOverride == 0)
1731 {
1732 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1733 (Arg)pP->poutNumBufMap[z]->maxNumBuf);
1734 }
1735 else
1736 {
1737 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_MAX_NUMBUF,
1738 (Arg)pAstCfg->xOut[z].outBufStatus.maxNumBufOverride);
1739 }
1741 // register PAF_SIO_IALG object address
1742 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_IALGADDR,
1743 (Arg)pAstCfg->xOut[z].outChainData.head->alg);
1744 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_BUFSTATUSADDR,
1745 (Arg)&pAstCfg->xOut[z].outBufStatus);
1746 for (zE=ENCODE1; zE < ENCODEN; zE++)
1747 {
1748 if (pP->outputsFromEncodes[zE] == z)
1749 {
1750 SIO_ctrl(pAstCfg->xOut[z].hTxSio,
1751 PAF_SIO_CONTROL_SET_ENCSTATUSADDR,
1752 (Arg)&pAstCfg->xEnc[zE].encodeStatus);
1753 break;
1754 }
1755 }
1756 }
1757 }
1758 }
1760 /* No need to start-clocks here, since only selecting the device. */
1761 #if 0
1762 // if device selected and valid then enable stat tracking if
1763 // required and start clocking
1764 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
1765 {
1766 TRACE_VERBOSE0("PAF_ASOT_selectDevices: start SIO clocks");
1767 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
1768 if (errme)
1769 {
1770 TRACE_VERBOSE2("PAF_ASOT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
1771 SIO_idle(pAstCfg->xOut[z].hTxSio);
1772 if (!errno)
1773 {
1774 errno = ASPERR_DEVOUT + errme;
1775 }
1776 }
1777 }
1778 #endif
1779 }
1781 return errno;
1782 } //PAF_ASOT_selectDevices
1785 // -----------------------------------------------------------------------------
1786 // ASOT Processing Function - Decode Processing
1787 //
1788 // Name: PAF_ASOT_decodeProcessing
1789 // Purpose: Audio Stream Output Task Function for processing audio data.
1790 //
1791 Int
1792 PAF_ASOT_decodeProcessing(
1793 const PAF_ASOT_Params *pP,
1794 const PAF_ASOT_Patchs *pQ,
1795 PAF_ASOT_Config *pAsotCfg
1796 )
1797 {
1798 PAF_AST_Config *pAstCfg;
1799 Int errno; /* error number */
1800 Int getVal;
1801 enum { INIT, STREAM, ENCODE, FINAL, QUIT, OUT_SIO_UPDATE } state;
1802 state = INIT;
1803 errno = 0; /* error number */
1804 Int frame; // (***) FL: formerly -- decoder input frame count
1805 Int block; // decoder output block count / input frame
1806 Int outSioUpdate;
1808 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
1810 for (;;)
1811 {
1812 //
1813 // Check forward (ASIT) error here, TBD
1814 //
1817 // Check if any change in output SIO, e.g. from Output shortcut.
1818 // Changes will break FSM and allow Output reconfiguration.
1819 errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
1820 if (errno < 0)
1821 {
1822 TRACE_TERSE1("PAF_ASOT_decodeProcessing: checkOutSio returned errno = 0x%04x", errno);
1823 break;
1824 }
1825 else if (outSioUpdate)
1826 {
1827 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Change in Output SIO selection");
1828 state = OUT_SIO_UPDATE;
1829 }
1831 // Process commands (encode)
1832 getVal = pP->fxns->encodeCommand(pP, pQ, pAsotCfg);
1833 if (getVal)
1834 {
1835 /* ignore */;
1836 }
1838 // Process state (decode)
1839 switch (state)
1840 {
1841 case INIT: // initial state
1842 gAsopInitCnt++;
1843 Log_info0("TaskAsop: state=INIT");
1845 frame = 0;
1846 block = 0;
1848 #if 0 // FL: moved to PAF_ASOT_initOutProc()
1849 // Reset audio frame pointers to original values
1850 // (may be needed if error occurred).
1851 resetAfPointers(pP, pAstCfg->xStr);
1852 // Reset audio frame meta data elements
1853 resetAfMetadata(pP, pAstCfg->xStr);
1854 #endif
1856 errno = pP->fxns->decodeInit(pP, pQ, pAsotCfg);
1857 if (errno)
1858 {
1859 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1860 errno = ASOP_DP_DECINIT_ERR;
1861 break;
1862 }
1864 //
1865 // Setup output: setCheckRateX, start output
1866 //
1867 // Establish secondary timing
1868 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
1869 if (errno)
1870 {
1871 TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x. break after decodeInfo1", errno);
1872 break;
1873 }
1875 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");
1876 state = STREAM;
1877 continue;
1879 case STREAM: // stream state
1880 gAsopStreamCnt++;
1881 Log_info0("TaskAsop: state=STREAM");
1883 errno = pP->fxns->decodeStream(pP, pQ, pAsotCfg, frame, block);
1884 if (errno)
1885 {
1886 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: STREAM. decodeStream err 0x%x", errno);
1887 errno = ASOP_DP_DECSTREAM_ERR;
1888 break;
1889 }
1891 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: STREAM->ENCODE");
1892 state = ENCODE;
1893 continue;
1895 case ENCODE: // encode state
1896 gAsopEncodeCnt++;
1897 Log_info0("TaskAsop: state=ENCODE");
1899 errno = pP->fxns->decodeEncode(pP, pQ, pAsotCfg, frame, block);
1900 if (errno)
1901 {
1902 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: ENCODE. decodeEncode err 0x%x", errno);
1903 errno = ASOP_DP_DECENC_ERR;
1904 break;
1905 }
1907 // Measure cycles in output processing loop.
1908 // Only measures cycles spent in loop.
1909 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS);
1910 gNumPfpAsot1--;
1911 pfpBegin(PFP_ID_ASOT_1, pAsotCfg->taskHandle);
1912 gNumPfpAsot1++;
1914 // (***) FL: do we need this?
1915 // AF pointers come from CB read, any resets occur in Decoder AF.
1916 //
1917 // Reset audio frame pointers to original values
1918 // (may have been adjusted by ARC or the like).
1919 resetAfPointers(pP, pAstCfg->xStr);
1921 // (***) FL: update output (setCheckRateX)
1922 // Contained in INFO2 in combined FSM.
1923 errno = pP->fxns->decodeInfo2(pP, pQ, pAsotCfg, frame, block);
1924 if (errno)
1925 {
1926 TRACE_TERSE1("PAF_ASOT_decodeProcessing: ENCODE break on decodeInfo2. errno 0x%x", errno);
1927 errno = ASOP_DP_DECINFO2_ERR;
1928 break;
1929 }
1931 block++;
1932 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: ENCODE->FINAL");
1933 state = FINAL;
1934 continue;
1936 case FINAL:
1937 gAsopFinalCnt++;
1938 Log_info0("TaskAsop: state=FINAL");
1940 //
1941 // (***) FL: this needs to be fixed.
1942 // (1) Only require selected Output to be in this FSM
1943 // => Dec Status checks aren't valid,
1944 // will probably always exit FSM if only Output running
1945 // (2) Checking Dec Status info asych to input events (maybe ok)
1946 //
1947 // Check for final frame, and if indicated:
1948 // - Update audio flag to cause output buffer flush rather than
1949 // the default truncate in "complete" processing.
1950 // - Exit state machine to "complete" processing.
1951 #if 0
1952 if (pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block))
1953 {
1954 for (z=OUTPUT1; z < OUTPUTN; z++)
1955 {
1956 if ((pAstCfg->xOut[z].outBufStatus.audio & 0x0f) == PAF_OB_AUDIO_SOUND)
1957 {
1958 TRACE_VERBOSE0("PAF_ASOT_outputProcessing: state: FINAL: SOUND -> QUIET");
1959 pAstCfg->xOut[z].outBufStatus.audio++; // SOUND -> QUIET
1960 }
1961 }
1962 break;
1963 }
1964 #endif
1965 errno = pP->fxns->decodeFinalTest(pP, pQ, pAsotCfg, frame, block);
1966 if (errno < 0)
1967 {
1968 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL break. errno 0x%x", errno);
1969 errno = ASOP_DP_DECFINALTEST_ERR;
1970 break;
1971 }
1972 else if (errno == ASOP_DP_CB_DRAINED)
1973 {
1974 // EOS, exit normally
1975 TRACE_TERSE1("PAF_ASOT_decodeProcessing: DECODE FINAL normal exit. errno 0x%x", errno);
1976 errno = ASOP_DP_SOK;
1977 break;
1978 }
1980 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: FINAL->STREAM");
1981 state = STREAM;
1982 continue;
1984 case OUT_SIO_UPDATE:
1985 gAsopOutSioUpdateCnt++;
1986 Log_info0("TaskAsop: state=OUT_SIO_UPDATE");
1988 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: OUT_SIO_UPDATE");
1989 errno = ASOP_DP_OUT_SIO_UPDATE;
1990 break;
1992 case QUIT:
1993 gAsopQuitCnt++;
1994 Log_info0("TaskAsop: state=QUIT");
1996 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: QUIT");
1997 errno = ASPERR_QUIT;
1998 break;
2000 default: // unknown state
2001 // Unknown:
2002 // - Set error number registers.
2003 // - Exit state machine to "complete" processing.
2005 TRACE_TERSE1("PAF_ASOT_decodeProcessing: state: unknown, 0x%x", state);
2006 errno = ASPERR_UNKNOWNSTATE;
2007 break;
2009 } // End of switch (state).
2011 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: Calling decode complete");
2012 if (pP->fxns->decodeComplete(pP, pQ, pAsotCfg, NULL, frame, block))
2013 {
2014 /* ignored? */;
2015 }
2017 //pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2018 //gNumPfpAsot1--;
2020 //return errno;
2021 break;
2022 } // End of for (;;)
2024 pfpEnd(PFP_ID_ASOT_1, PFP_FINISH_MEAS); // PFP end -- outside of PFP for errors, EOS, or Output SIO change
2025 gNumPfpAsot1--;
2027 return errno;
2028 }
2030 // -----------------------------------------------------------------------------
2031 // ASOT Decoding Function - Encode Command Processing
2032 //
2033 // Name: PAF_ASOT_encodeCommand
2034 // Purpose: Decoding Function for processing Encode Commands.
2035 // From: AST Parameter Function -> decodeProcessing
2036 // Uses: See code.
2037 // States: x
2038 // Return: 0.
2039 // Trace: Message Log "trace" in Debug Project Configuration reports:
2040 // * Command execution.
2041 // * SIO control errors.
2042 // * Error number macros.
2043 //
2044 Int
2045 PAF_ASOT_encodeCommand(
2046 const PAF_ASOT_Params *pP,
2047 const PAF_ASOT_Patchs *pQ,
2048 PAF_ASOT_Config *pAsotCfg
2049 )
2050 {
2051 PAF_AST_Config *pAstCfg;
2052 Int as; /* Audio Stream Number (1, 2, etc.) */
2053 Int z; /* encode counter */
2054 Int errno = 0; /* error number */
2055 Int zO, zS;
2058 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2059 as = pAstCfg->as;
2061 for (z=ENCODE1; z < ENCODEN; z++)
2062 {
2063 zO = pP->outputsFromEncodes[z];
2064 zS = pP->streamsFromEncodes[z];
2065 if (! (pAstCfg->xEnc[z].encodeStatus.command2 & 0x80))
2066 {
2067 switch (pAstCfg->xEnc[z].encodeStatus.command2)
2068 {
2069 case 0: // command none - process
2070 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2071 break;
2072 case 1: // mute command
2073 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command mute (0x%02x)", as+zS, 1);
2074 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2075 && pAstCfg->xOut[zO].hTxSio
2076 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_MUTE, 0)))
2077 {
2078 errno = (errno & 0xff) | ASPERR_MUTE;
2079 /* convert to sensical errno */
2080 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (mute)", as+zS);
2081 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2082 }
2083 else
2084 {
2085 pAstCfg->xOut[zO].outBufStatus.audio |= PAF_OB_AUDIO_MUTED;
2086 }
2087 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2088 break;
2089 case 2: // unmute command
2090 TRACE_VERBOSE2("AS%d: PAF_ASOT_encodeCommand: encode command unmute (0x%02x)", as+zS, 2);
2091 if ((pAstCfg->xOut[zO].outBufStatus.audio & 0x0f) != PAF_OB_AUDIO_QUIET
2092 && pAstCfg->xOut[zO].hTxSio
2093 && (errno = SIO_ctrl (pAstCfg->xOut[zO].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2094 {
2095 errno = (errno & 0xff) | ASPERR_MUTE;
2096 /* convert to sensical errno */
2097 TRACE_TERSE1("AS%d: PAF_ASOT_encodeCommand: SIO control failed (unmute)", as+zS);
2098 TRACE_TERSE2("AS%d: PAF_ASOT_encodeCommand: errno = 0x%04x <ignored>", as+zS, errno);
2099 }
2100 else
2101 {
2102 pAstCfg->xOut[zO].outBufStatus.audio &= ~PAF_OB_AUDIO_MUTED;
2103 }
2104 pAstCfg->xEnc[z].encodeStatus.command2 |= 0x80;
2105 break;
2106 default: // command unknown - ignore
2107 break;
2108 }
2109 }
2110 }
2112 ERRNO_RPRT (TaskAsop, errno);
2114 return 0;
2115 } //PAF_ASOT_encodeCommand
2117 //debug -- allow dynamic config
2118 //Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
2120 // Purpose: Decoding Function for reinitializing the decoding process.
2121 Int
2122 PAF_ASOT_decodeInit(
2123 const PAF_ASOT_Params *pP,
2124 const PAF_ASOT_Patchs *pQ,
2125 PAF_ASOT_Config *pAsotCfg
2126 )
2127 {
2128 //PAF_AST_Config *pAstCfg;
2129 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2130 //Int as; /* Audio Stream Number (1, 2, etc.) */
2131 Int z; /* decode/encode counter */
2132 Int errno; /* error number */
2133 //Int zO, zS;
2135 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2136 //as = pAstCfg->as;
2138 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2140 for (z=DECODE1; z < DECODEN; z++)
2141 {
2142 // Initialize decoder output circular buffer for stream reads
2143 //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
2144 errno = cbInitStreamRead(pCbCtl, z);
2145 if (errno)
2146 {
2147 TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
2148 SW_BREAKPOINT; // debug
2149 return errno;
2150 }
2152 // Start decoder output circular buffer reads
2153 errno = cbReadStart(pCbCtl, z);
2154 if (errno)
2155 {
2156 TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
2157 SW_BREAKPOINT; // debug
2158 return errno;
2159 }
2161 gCbReadAfErr=0; // reset read circular buffer error count
2162 gDecOpCbRdAfUnd=0; // reset decoder output circular buffer underflow count
2163 gMaxDecOpCbRdAfUnd=0; // reset max decoder output circular buffer underflow count
2164 gMasterCbResetCnt=0; // reset master circular buffer reset count
2166 // FL: debug, log circular buffer control variables
2167 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
2168 }
2170 #if 0 // moved to PAF_ASOT_outputReset()
2171 // TODO: move this to start of this function so that it doesn't affect IO timing
2172 for (z=ENCODE1; z < ENCODEN; z++)
2173 {
2174 zO = pP->outputsFromEncodes[z];
2175 zS = pP->streamsFromEncodes[z];
2176 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2177 {
2178 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2179 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2180 ENC_Handle enc = (ENC_Handle )encAlg;
2181 TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
2182 if (encAlg->fxns->algActivate)
2183 {
2184 encAlg->fxns->algActivate (encAlg);
2185 }
2186 if (enc->fxns->reset)
2187 {
2188 errno = enc->fxns->reset(enc, NULL,
2189 &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus);
2190 if (errno)
2191 {
2192 return errno;
2193 }
2194 }
2195 }
2196 }
2197 #endif
2199 return 0;
2200 }
2202 // -----------------------------------------------------------------------------
2203 // ASOT Decoding Function - Info Processing, Initial
2204 //
2205 // Name: PAF_ASOT_decodeInfo1
2206 // Purpose: Decoding Function for processing information in a manner that
2207 // is unique to initial frames of input data.
2208 // From: AST Parameter Function -> decodeProcessing
2209 // Uses: See code.
2210 // States: x
2211 // Return: Error number in standard or SIO form (0 on success).
2212 // Trace: Message Log "trace" in Debug Project Configuration reports:
2213 // * State information as per parent.
2214 //
2215 Int
2216 PAF_ASOT_decodeInfo1(
2217 const PAF_ASOT_Params *pP,
2218 const PAF_ASOT_Patchs *pQ,
2219 PAF_ASOT_Config *pAsotCfg,
2220 Int frame,
2221 Int block
2222 )
2223 {
2224 //PAF_AST_Config *pAstCfg;
2225 //Int z; /* decode/encode counter */
2226 Int errno; /* error number */
2228 #if 0 // moved to PAF_ASOT_outputInfo1()
2229 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2231 // run the chain of ASP's on the stream.
2232 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
2233 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2234 PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame);
2235 if (errno)
2236 {
2237 TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
2238 return errno;
2239 }
2241 TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
2242 for (z=ENCODE1; z < ENCODEN; z++)
2243 {
2244 Int zO = pP->outputsFromEncodes[z];
2245 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2246 {
2247 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2248 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2249 ENC_Handle enc = (ENC_Handle )encAlg;
2251 if (enc->fxns->info)
2252 {
2253 errno = enc->fxns->info(enc, NULL,
2254 &pAstCfg->xEnc[z].encodeControl,
2255 &pAstCfg->xEnc[z].encodeStatus);
2256 if (errno)
2257 {
2258 TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
2259 return errno;
2260 }
2261 }
2262 }
2263 }
2264 #endif
2266 errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
2267 if (errno)
2268 {
2269 // ignore if rateX has changed since we haven't, but are about to,
2270 // start the output. If we didn't ignore this case then the state machine
2271 // would restart unnecessarily, e.g. in the case of SRC, resulting in
2272 // added latency.
2273 if (errno != ASPERR_INFO_RATECHANGE)
2274 {
2275 TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
2276 return errno;
2277 }
2278 else
2279 {
2280 TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
2281 }
2282 }
2284 errno = pP->fxns->startOutput(pP, pQ, pAsotCfg);
2285 if (errno)
2286 {
2287 if (errno == 0x105)
2288 {
2289 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
2290 }
2291 else
2292 {
2293 TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
2294 }
2295 return errno;
2296 }
2298 return 0;
2299 }
2301 // -----------------------------------------------------------------------------
2302 // ASOT Decoding Function - Info Processing, Subsequent
2303 //
2304 // Name: PAF_ASOT_decodeInfo2
2305 // Purpose: Decoding Function for processing information in a manner that
2306 // is unique to frames of input data other than the initial one.
2307 // From: AST Parameter Function -> decodeProcessing
2308 // Uses: See code.
2309 // States: x
2310 // Return: Error number in standard form (0 on success).
2311 // Trace: None.
2312 //
2313 Int
2314 PAF_ASOT_decodeInfo2(
2315 const PAF_ASOT_Params *pP,
2316 const PAF_ASOT_Patchs *pQ,
2317 PAF_ASOT_Config *pAsotCfg,
2318 Int frame,
2319 Int block
2320 )
2321 {
2322 //PAF_AST_Config *pAstCfg;
2323 Int errno;
2326 //pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2328 errno = pP->fxns->setCheckRateX (pP, pQ, pAsotCfg, 1);
2329 TRACE_VERBOSE1("PAF_ASOT_decodeInfo2: return 0x%x", errno);
2330 return errno;
2331 } //PAF_ASOT_decodeInfo2
2334 PAF_AST_DecOpCircBufStats gCbStats; // FL: debug
2335 // -----------------------------------------------------------------------------
2336 // ASOT Decoding Function - Stream Processing
2337 //
2338 // Name: PAF_ASOT_decodeStream
2339 // Purpose: Decoding Function for processing of audio frame data by the
2340 // ASP Algorithms.
2341 // From: AST Parameter Function -> decodeProcessing
2342 // Uses: See code.
2343 // States: x
2344 // Return: Error number in standard form (0 on success).
2345 // Trace: Message Log "trace" in Debug Project Configuration reports:
2346 // * State information as per parent/child.
2347 //
2348 Int
2349 PAF_ASOT_decodeStream(
2350 const PAF_ASOT_Params *pP,
2351 const PAF_ASOT_Patchs *pQ,
2352 PAF_ASOT_Config *pAsotCfg,
2353 Int frame,
2354 Int block
2355 )
2356 {
2357 PAF_AST_Config *pAstCfg;
2358 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2359 Int z; /* decode/stream counter */
2360 PAF_AudioFrame *pAfRd;
2361 Int cbErrno;
2362 //PAF_AST_DecOpCircBufStats cbStats; /* circular buffer statistics */
2363 Int errno;
2366 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2368 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2370 for (z=DECODE1; z < DECODEN; z++)
2371 {
2372 Int zS = pP->streamsFromDecodes[z];
2374 //
2375 // Read decoder output circular buffer
2376 //
2377 pAfRd = pAstCfg->xStr[zS].pAudioFrame;
2378 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2379 cbErrno = cbReadAf(pCbCtl, z, pAfRd);
2380 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2381 if ((cbErrno < 0) &&
2382 (cbErrno != ASP_DECOP_CB_AF_READ_UNDERFLOW) &&
2383 (cbErrno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2384 {
2385 gCbReadAfErr++;
2386 TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
2387 //SW_BREAKPOINT; // debug
2388 return cbErrno;
2389 }
2391 // Handle underflows
2392 if ((cbErrno == ASP_DECOP_CB_AF_READ_UNDERFLOW) ||
2393 (cbErrno == ASP_DECOP_CB_PCM_READ_UNDERFLOW))
2394 {
2395 // (***) FL: Need to check behavior of cbReset().
2396 // Need to check behavior on exit/re-entry into Output processing.
2397 gDecOpCbRdAfUnd++; // increment circular buffer underflow count
2398 if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR)
2399 {
2400 // Underflow count above threshold.
2401 // (1) set max underflow count to threshold
2402 // (2) reset underflow count
2403 // (3) reset circular buffer
2405 gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
2406 gDecOpCbRdAfUnd = 0; // reset underflow count
2408 // Reset circular buffer
2409 cbReset(pCbCtl, z);
2410 gMasterCbResetCnt++; // increment master circular buffer reset count
2411 Log_info0("ASOT:cbReset");
2413 return cbErrno;
2414 }
2415 }
2416 else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
2417 {
2418 // No underflow detected.
2419 // update max underflow count,
2420 // reset underflow count
2422 // update max underflow count
2423 if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
2424 {
2425 gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
2426 }
2427 gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
2428 }
2429 //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2430 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2431 Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
2433 #if 0 // (***) FL: shows timing of CB read
2434 // (***) debug // B8
2435 {
2436 static Uint8 toggleState = 0;
2437 if (toggleState == 0)
2438 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2439 else
2440 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2441 toggleState = ~(toggleState);
2442 }
2443 #endif
2445 // FL: debug
2446 // Get circular buffer statistics (debug)
2447 //cbGetStats(pCbCtl, z, &cbStats);
2448 cbGetStats(pCbCtl, z, &gCbStats);
2450 // debug
2451 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
2452 //if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
2453 //{
2454 // Log_info0("capAfWrite() error");
2455 //}
2456 }
2458 TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
2459 errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
2460 PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
2461 if (errno)
2462 {
2463 TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
2464 return errno;
2465 }
2467 return 0;
2469 } //PAF_ASOT_decodeStream
2471 // -----------------------------------------------------------------------------
2472 // ASOT Decoding Function - Encode Processing
2473 //
2474 // Name: PAF_ASOT_decodeEncode
2475 // Purpose: Decoding Function for processing of audio frame data by the
2476 // Encode Algorithm.
2477 // From: AST Parameter Function -> decodeProcessing
2478 // Uses: See code.
2479 // States: x
2480 // Return: Error number in standard or SIO form (0 on success).
2481 // Trace: Message Log "trace" in Debug Project Configuration reports:
2482 // * State information as per parent.
2483 //
2484 Int
2485 PAF_ASOT_decodeEncode(
2486 const PAF_ASOT_Params *pP,
2487 const PAF_ASOT_Patchs *pQ,
2488 PAF_ASOT_Config *pAsotCfg,
2489 Int frame,
2490 Int block
2491 )
2492 {
2493 PAF_AST_Config *pAstCfg;
2494 Int as; /* Audio Stream Number (1, 2, etc.) */
2495 Int z; /* encode/output counter */
2496 Int errno; /* error number */
2497 Int zX, zE, zS;
2498 // debug
2499 //UInt32 curTime;
2501 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2502 as = pAstCfg->as;
2504 // Await output buffers (but not first time)
2505 for (z=OUTPUT1; z < OUTPUTN; z++)
2506 {
2507 // determine encoder associated with this output
2508 zE = z;
2509 for (zX = ENCODE1; zX < ENCODEN; zX++)
2510 {
2511 if (pP->outputsFromEncodes[zX] == z)
2512 {
2513 zE = zX;
2514 break;
2515 }
2516 }
2517 zS = pP->streamsFromEncodes[zE];
2519 if (pAstCfg->xOut[z].hTxSio)
2520 {
2521 // update length (e.g. ARC may have changed)
2522 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2523 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2524 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
2525 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2526 errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
2527 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2528 if (errno < 0)
2529 {
2530 SIO_idle(pAstCfg->xOut[z].hTxSio);
2531 TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
2532 return -errno; // SIO negates error codes
2533 }
2534 // TODO: use pC->xOut[z].pOutBuf in following ->encode call
2536 #if 0 // (***) FL: shows timing of Output Rx SIO reclaim
2537 // (***) debug // B8
2538 {
2539 static Uint8 toggleState = 0;
2540 if (toggleState == 0)
2541 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
2542 else
2543 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2544 toggleState = ~(toggleState);
2545 }
2546 #endif
2548 //
2549 // Simulate Tx SIO_reclaim() pend
2550 //
2551 //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
2552 //curTime = Clock_getTicks();
2553 //System_printf("System time in TaskAsopFxn Tx audio = %lu\n", (ULong)curTime);
2554 //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
2556 gAsopTxSioReclaimCnt++;
2557 }
2558 else
2559 {
2560 TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
2561 }
2562 }
2564 // Encode data
2565 for (z=ENCODE1; z < ENCODEN; z++)
2566 {
2567 Int zO = pP->outputsFromEncodes[z];
2568 Int zS = pP->streamsFromEncodes[z];
2569 (void)zS; // clear compiler warning in case not used with tracing disabled
2570 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2571 {
2572 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2573 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2574 ENC_Handle enc = (ENC_Handle )encAlg;
2575 if (select != pAstCfg->xEnc[z].encodeControl.encActive)
2576 {
2577 pAstCfg->xEnc[z].encodeControl.encActive = select;
2578 TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
2579 return (-1);
2580 }
2581 TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
2583 // (MID 1933) temp. workaround for PCE2
2584 pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
2586 /*
2587 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2588 {
2589 PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
2590 int *wp;
2591 wp = (int*)pAudioFrame->data.sample[0];
2592 TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
2593 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
2594 wp = (int*)pAudioFrame->data.sample[1];
2595 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
2596 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
2597 wp = (int*)pAudioFrame->data.sample[2];
2598 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
2599 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
2600 }
2601 #endif
2602 */
2604 if (enc->fxns->encode)
2605 {
2606 pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
2607 pP->z_pEncodeStatus[z]->encBypass;
2608 errno = enc->fxns->encode(enc, NULL,
2609 &pAstCfg->xEnc[z].encodeInStruct,
2610 &pAstCfg->xEnc[z].encodeOutStruct);
2611 if (errno)
2612 {
2613 if (errno != PCEERR_OUTPUT_POINTERNULL)
2614 {
2615 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
2616 return errno;
2617 }
2618 }
2619 /* #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2620 else
2621 {
2622 int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
2623 TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
2624 TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
2625 }
2626 #endif
2627 */
2628 }
2629 }
2630 else
2631 {
2632 TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
2633 as+pP->streamsFromEncodes[z], block);
2634 }
2635 }
2637 // Transmit data
2638 for (z=OUTPUT1; z < OUTPUTN; z++)
2639 {
2640 // determine encoder associated with this output
2641 zE = z;
2642 for (zX = ENCODE1; zX < ENCODEN; zX++)
2643 {
2644 if (pP->outputsFromEncodes[zX] == z)
2645 {
2646 zE = zX;
2647 break;
2648 }
2649 }
2650 zS = pP->streamsFromEncodes[zE];
2652 if (pAstCfg->xOut[z].hTxSio)
2653 {
2654 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
2655 //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
2656 errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2657 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
2658 //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
2659 if (errno)
2660 {
2661 SIO_idle(pAstCfg->xOut[z].hTxSio);
2662 if (errno == 0x105) // 0x105 == RINGIO_EBUFFULL
2663 {
2664 // statStruct_LogFullRing(STATSTRUCT_AS1_F2);
2665 TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
2666 }
2667 if (errno > 0)
2668 {
2669 TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
2670 return (ASPERR_ISSUE + (z << 4));
2671 }
2672 else if (errno < 0)
2673 {
2674 TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
2675 return -errno; // SIO negates error codes
2676 }
2677 }
2678 if (errno > 0)
2679 {
2680 return (ASPERR_ISSUE + (z << 4));
2681 }
2682 else if (errno < 0)
2683 {
2684 return -errno; // SIO negates error codes
2685 }
2686 }
2687 else
2688 {
2689 TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
2690 }
2691 }
2693 return 0;
2694 } //PAF_ASOT_decodeEncode
2696 // -----------------------------------------------------------------------------
2697 // ASOT Decoding Function - Stream-Final Processing
2698 //
2699 // Name: PAF_ASOT_decodeComplete
2700 // Purpose: Decoding Function for terminating the decoding process.
2701 // From: AST Parameter Function -> decodeProcessing
2702 // Uses: See code.
2703 // States: x
2704 // Return: 0.
2705 // Trace: Message Log "trace" in Debug Project Configuration reports:
2706 // * State information as per parent.
2707 //
2708 Int
2709 PAF_ASOT_decodeComplete(
2710 const PAF_ASOT_Params *pP,
2711 const PAF_ASOT_Patchs *pQ,
2712 PAF_ASOT_Config *pAsotCfg,
2713 ALG_Handle decAlg[],
2714 Int frame,
2715 Int block
2716 )
2717 {
2718 PAF_AST_Config *pAstCfg;
2719 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2720 Int as; /* Audio Stream Number (1, 2, etc.) */
2721 Int z; /* decode/encode counter */
2722 Int errno; /* error number */
2725 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2726 as = pAstCfg->as;
2727 (void)as; // clear compiler warning in case not used with tracing disabled
2729 pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2731 for (z=DECODE1; z < DECODEN; z++)
2732 {
2733 // Stop decoder output circular buffer reads
2734 errno = cbReadStop(pCbCtl, z);
2735 if (errno)
2736 {
2737 TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
2738 SW_BREAKPOINT; // FL: debug
2739 return errno;
2740 }
2741 // FL: debug
2742 cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
2743 }
2745 pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
2747 for (z=ENCODE1; z < ENCODEN; z++)
2748 {
2749 Int zO = pP->outputsFromEncodes[z];
2750 if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
2751 {
2752 Int select = pAstCfg->xEnc[z].encodeStatus.select;
2753 ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
2754 #ifdef PAF_ASP_FINAL
2755 ENC_Handle enc = (ENC_Handle)encAlg;
2756 #endif /* PAF_ASP_FINAL */
2757 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
2758 #ifdef PAF_ASP_FINAL
2759 if (enc->fxns->final)
2760 enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
2761 &pAstCfg->xEnc[z].encodeStatus);
2762 #endif /* PAF_ASP_FINAL */
2763 if (encAlg->fxns->algDeactivate)
2764 {
2765 encAlg->fxns->algDeactivate(encAlg);
2766 }
2767 }
2768 else
2769 {
2770 TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
2771 }
2772 }
2774 // wait for remaining data to be output
2775 pP->fxns->stopOutput(pP, pQ, pAsotCfg);
2777 return 0;
2778 } //PAF_ASOT_decodeComplete
2780 // -----------------------------------------------------------------------------
2781 // ASOT Decoding Function Helper - SIO Driver Start
2782 //
2783 // Name: PAF_ASOT_startOutput
2784 // Purpose: Decoding Function for initiating output.
2785 // From: AST Parameter Function -> decodeInfo1
2786 // Uses: See code.
2787 // States: x
2788 // Return: Error number in standard or SIO form (0 on success).
2789 // Trace: Message Log "trace" in Debug Project Configuration reports:
2790 // * State information as per parent.
2791 // * SIO control errors.
2792 //
2793 #define DEC_OUTNUMBUF_MAP(X) \
2794 pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
2796 Int
2797 PAF_ASOT_startOutput(
2798 const PAF_ASOT_Params *pP,
2799 const PAF_ASOT_Patchs *pQ,
2800 PAF_ASOT_Config *pAsotCfg
2801 )
2802 {
2803 PAF_AST_Config *pAstCfg;
2804 Int as; /* Audio Stream Number (1, 2, etc.) */
2805 Int z; /* output counter */
2806 Int errno,nbufs, errme; /* error number */
2807 Int zE, zS, zX;
2808 Int zMD;
2809 PAF_SIO_IALG_Obj *pObj;
2810 PAF_SIO_IALG_Config *pAlgConfig;
2813 pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
2814 as = pAstCfg->as;
2815 zMD = pAstCfg->masterDec;
2817 for (z=OUTPUT1; z < OUTPUTN; z++)
2818 {
2819 if (pAstCfg->xOut[z].hTxSio)
2820 {
2821 // determine associated encoder and stream
2822 zE = z;
2823 zS = z;
2824 for (zX = ENCODE1; zX < ENCODEN; zX++)
2825 {
2826 if (pP->outputsFromEncodes[zX] == z)
2827 {
2828 zE = zX;
2829 zS = pP->streamsFromEncodes[zE];
2830 break;
2831 }
2832 }
2834 // Need to Revisit: Starting Clocks here seems logical & also manages the McASP without spurious underruns .
2836 #if 1
2837 // if device selected and valid then enable stat tracking if
2838 // required and start clocking
2839 if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
2840 {
2841 TRACE_VERBOSE0("PAF_ASOT_startOutput: start SIO clocks");
2842 errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
2843 if (errno)
2844 {
2845 TRACE_VERBOSE2("PAF_ASOT_startOutput: errme 0x%x, errno 0x%x", errme, errno);
2846 SIO_idle(pAstCfg->xOut[z].hTxSio);
2847 if (!errno)
2848 {
2849 errno = ASPERR_DEVOUT + errme;
2850 }
2851 }
2852 }
2853 #endif
2854 // Set sample count so that DOB knows how much data to send
2855 pAstCfg->xOut[z].outBufConfig.lengthofFrame =
2856 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
2858 if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
2859 {
2860 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
2861 pAlgConfig = &pObj->config;
2862 memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
2863 pAlgConfig->pMemRec[0].size);
2864 }
2866 // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
2867 // decoder. How should we handle the sourceProgram for multiple decoders?
2868 // Override as needed
2869 nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
2870 if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
2871 {
2872 nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
2873 }
2874 SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
2876 if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
2877 &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
2878 {
2879 SIO_idle(pAstCfg->xOut[z].hTxSio);
2880 TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
2881 return errno;
2882 }
2884 if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
2885 (errno = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
2886 {
2887 errno = (errno & 0xff) | ASPERR_MUTE;
2888 /* convert to sensical errno */
2889 TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
2890 return (errno);
2891 }
2892 else
2893 {
2894 pAstCfg->xOut[z].outBufStatus.audio
2895 = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
2896 }
2898 TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
2899 }
2900 }
2902 return 0;
2903 } //PAF_ASOT_startOutput
2905 // -----------------------------------------------------------------------------
2906 // ASOT Decoding Function Helper - SIO Driver Stop
2907 //