]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProc.c
Update ASOT tracing
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProc.c
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  *  ======== audioStreamInpProc.c ========
38  */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "aspOutInitSync_master.h"
65 #include "audioStreamProc_common.h"
66 #include "audioStreamProc_master.h"
67 #include "audioStreamInpProc.h"
68 #include "statusOp_common.h"
70 #include "pfp/pfp.h"
71 #include "pfp_app.h"        /* contains all PFP ID's */
72 Int32 gNumPfpAsit1=0; // debug
73 Int32 gNumPfpAsit2=0;
77 // FL: debug
78 #include "dbgCapAf.h"
81 // -----------------------------------------------------------------------------
82 // Debugging Trace Control, local to this file.
83 // 
84 #include "logp.h"
86 #define TRACE_ARC(a)
88 // allows you to set a different trace module in pa.cfg
89 #define TR_MOD  trace
91 // Allow a developer to selectively enable tracing.
92 #define CURRENT_TRACE_MASK      0x27
94 #define TRACE_MASK_TERSE        0x01   // only flag errors and show init
95 #define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
96 #define TRACE_MASK_VERBOSE      0x04   // trace full operation
97 #define TRACE_MASK_DATA         0x08   // Show data
98 #define TRACE_MASK_TIME         0x10   // Timing related traces
99 #define TRACE_MASK_MSG          0x20   // Message related traces
101 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
102     #undef  TRACE_TERSE0
103     #undef  TRACE_TERSE1
104     #undef  TRACE_TERSE2
105     #undef  TRACE_TERSE3
106     #undef  TRACE_TERSE4
107     #define TRACE_TERSE0(a)
108     #define TRACE_TERSE1(a,b)
109     #define TRACE_TERSE2(a,b,c)
110     #define TRACE_TERSE3(a,b,c,d)
111     #define TRACE_TERSE4(a,b,c,d,e)
112 #endif
114 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
115     #undef  TRACE_GEN0
116     #undef  TRACE_GEN1
117     #undef  TRACE_GEN2
118     #undef  TRACE_GEN3
119     #undef  TRACE_GEN4
120     #define TRACE_GEN0(a)
121     #define TRACE_GEN1(a,b)
122     #define TRACE_GEN2(a,b,c)
123     #define TRACE_GEN3(a,b,c,d)
124     #define TRACE_GEN4(a,b,c,d,e)
125 #endif
127 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
128     // consolidate list of processing strings, indexed by PAF_SOURCE
129     static char *procName[] =
130     {
131         "", //PAF_SOURCE_UNKNOWN
132         "", //PAF_SOURCE_NONE
133         "AS%d: Pass processing ...",   //PAF_SOURCE_PASS
134         "AS%d: SNG processing ...",    //PAF_SOURCE_SNG
135         "AS%d: Auto processing ...",   //PAF_SOURCE_AUTO
136         "AS%d: Auto processing ...",   //PAF_SOURCE_BITSTREAM
137         "AS%d: DTS processing ...",    //PAF_SOURCE_DTSALL
138         "AS%d: PCM processing ...",    //PAF_SOURCE_PCMAUTO
139         "AS%d: PCM processing ...",    //PAF_SOURCE_PCM
140         "AS%d: PCN processing ...",    //PAF_SOURCE_PC8
141         "AS%d: AC3 processing ...",    //PAF_SOURCE_AC3
142         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS
143         "AS%d: AAC processing ...",    //PAF_SOURCE_AAC
144         "AS%d: MPG processing ...",    //PAF_SOURCE_MPEG
145         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS12
146         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS13
147         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS14
148         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS16
149         "AS%d: WMP processing ...",    //PAF_SOURCE_WMA9PRO
150         "AS%d: MP3 processing ...",    //PAF_SOURCE_MP3
151         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD1
152         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD2
153         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD3
154         "AS%d: DDP processing ...",    //PAF_SOURCE_DDP
155         "AS%d: DTSHD processing ...",  //PAF_SOURCE_DTSHD
156         "AS%d: THD processing ...",    //PAF_SOURCE_THD
157         "AS%d: DXP processing ...",    //PAF_SOURCE_DXP
158         "AS%d: WMA processing ...",    //PAF_SOURCE_WMA
159     };
161 #else
162     #undef  TRACE_VERBOSE0
163     #undef  TRACE_VERBOSE1
164     #undef  TRACE_VERBOSE2
165     #undef  TRACE_VERBOSE3
166     #undef  TRACE_VERBOSE4
167     #define TRACE_VERBOSE0(a)
168     #define TRACE_VERBOSE1(a,b)
169     #define TRACE_VERBOSE2(a,b,c)
170     #define TRACE_VERBOSE3(a,b,c,d)
171     #define TRACE_VERBOSE4(a,b,c,d,e)
172 #endif
174 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
175     #define TRACE_DATA(a) LOG_printf a
176 #else
177     #define TRACE_DATA(a)
178 #endif
180 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
181     #define TRACE_TIME(a) LOG_printf a
182     #define TIME_MOD  trace // this could be different
183     static Int dtime()
184     {
185          static Int old_time = 0;
186          Int time = TSK_time();
187          Int delta_time = time - old_time;
188          old_time = time;
189          return( delta_time);
190     }
192     static char *stateName[11] =
193     {
194          "INIT",
195          "INFO1",
196          "AGAIN",
197          "INFO2",
198          "CONT",
199          "TIME",
200          "DECODE",
201          "STREAM",
202          "ENCODE",
203          "FINAL",
204          "QUIT"
205     };
207 #else
208     #define TRACE_TIME(a)
209 #endif
211 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
212     #undef  TRACE_MSG0
213     #undef  TRACE_MSG1
214     #undef  TRACE_MSG2
215     #undef  TRACE_MSG3
216     #undef  TRACE_MSG4
217     #define TRACE_MSG0(a)
218     #define TRACE_MSG1(a,b)
219     #define TRACE_MSG2(a,b,c)
220     #define TRACE_MSG3(a,b,c,d)
221     #define TRACE_MSG4(a,b,c,d,e)
222 #endif
223     
225 // .............................................................................
227 #include <pafsio.h>
228 #include "paferr.h"
230 #include <acp_mds.h>
232 #include <pcm.h>
234 #include <pce.h>
236 #include <doberr.h>
238 #include <diberr.h>
240 #include <stdasp.h>
242 #include "as0.h"
243 #include "asperr.h"
245 #include "audioStreamProc_params.h"
246 #include "audioStreamProc_patchs.h"
247 #include "audioStreamProc_config.h"
248 #include "audioStreamInpProc.h"
251 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
252 #ifdef _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
253 //
254 // Performing PCM high-sampling rate + SRC + CAR benchmarking
255 //
257 #define PROFILER
258 #endif
260 #ifdef PROFILER
261 extern UInt32 start_profiling;
262 #endif
264 extern UInt32 gAspProfileEnable;
266 //
267 // Audio Stream Definitions
268 //
270 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
271 #define MINFRAMELENGTH 24
272 #define PA_MODULO       8   // also defined independently in ARC2 code, and may be hard coded other places.
275 //
276 // Decoder Definitions
277 //
278 //#define decLinkInit pQ->i_decLinkInit
280 //
281 // Audio Stream Processing Definitions
282 //
283 //#define aspLinkInit pQ->i_aspLinkInit
285 //
286 // Encoder Definitions
287 //
288 #define encLinkInit pQ->i_encLinkInit
290 //
291 // Input, Output Definitions
292 //
293 #define inpLinkInit pP->i_inpLinkInit
294 //#define outLinkInit pP->i_outLinkInit
296 /* ---------------------------------------------------------------- */
297 /*              Parameter macro definitions end here.               */
298 /* ---------------------------------------------------------------- */
300 //
301 // Standardized Definitions
302 //
304 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
305 //#define ENC_Handle PCE_Handle /* works for all: PCE */
307 #define __TASK_NAME__  "TaskAsip"
310 //
311 // Audio Stream Input Task definitions
312 //
314 #define ASIP_FRAMELEN_SS_DEFAULT    ( 256 )
315 // FL: pP->frameLength
316 //#define ASIP_FRAMELEN_SS_PCM        ( FRAMELENGTH )
317 // FL: (***) hard-coded
318 #define ASIP_FRAMELEN_SS_DDP_AC3    ( 1536 )
319 // FL: (***) hard-coded
320 #define ASIP_FRAMELEN_SS_THD        ( 1536 )        //QIN FIX ME
322 // Compute decoder frame length based on selected source
323 static Int getFrameLengthSourceSel(
324     const PAF_ASIT_Params *pP, 
325     Int8 sourceSelect
326 );
328 LINNO_DEFN(TaskAsip); /* Line number macros */
329 ERRNO_DEFN(TaskAsip); /* Error number macros */
331 // ASIT configuration
332 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
333 PAF_ASIT_Config gPAF_ASIT_config = {
334     NULL,               // taskHandle
335     NULL,               // acp
336     &gPAF_ASPM_config,  // pAspmCfg, shared ASIT/ASOT configuration
337     &gPAF_AST_config    // pAstCfg, shared ASIT/ASOT/ASDT configuration
338 };
340 // Global debug counters */
341 UInt32 gTaskAsipCnt             =0;
342 UInt32 gAsipInitCnt             =0;
343 UInt32 gAsipInfo1Cnt            =0;
344 UInt32 gAsipInfo2Cnt            =0;
345 UInt32 gAsipDecodeCnt           =0;
346 UInt32 gAsipDecodeErrCnt        =0;
347 UInt32 gAsipFinalCnt            =0;
348 UInt32 gAsipQuitCnt             =0;
349 UInt32 gAsipInfo1_PrimaryErrCnt =0;
350 UInt32 gAsipInfo1_ErrCnt        =0;
351 UInt32 gAsipInfo2_PrimaryErrCnt =0;
352 UInt32 gAsipInfo2_ErrCnt        =0;
353 UInt32 gCapIbReset_cnt          =0;
354 UInt32 gCapIb_cnt               =0;
355 // debug
356 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count (returned from ARM to DSP)
357                                    
359 #include "dbgDib.h" // debug
361 extern struct {
362     Int size;
363     IALG_Status *pStatus[512];
364 } IACP_STD_BETA_TABLE;
366 // FL: debug
367 #include "evmc66x_gpio_dbg.h"
369 /*
370  *  ======== taskAsipFxn ========
371  *  Audio Stream Input Processing task function
372  */
373 Void taskAsipFxn(
374 //    Int betaPrimeValue, // FL: revisit
375     const PAF_ASIT_Params *pP,
376     const PAF_ASIT_Patchs *pQ
379     PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
380     PAF_AST_Config *pAstCfg;        /* AST Common (shared) configuration pointer */
381     Int as;                         /* Audio Stream Number (1, 2, etc.) */
382     Int z;                          /* input/encode/stream/decode/output counter */
383     Int i;                          /* phase */
384     Int errno;                      /* error number */
385     Int zMD, zMI, zMS, zX;
386     Int loopCount = 0;  // used to stop trace to see startup behavior.        
387     UInt32 curTime;
388     Int size;
389     // Messaging
390     ASP_Msg *pAspMsg;              
391     Int status;
392     Int8 tempVar8;
393     char asipMsgBuf[ASP_MSG_BUF_LEN];
395     Log_info0("Enter taskAsipFxn()");
397     //
398     // Audio Stream Input Task Parameters & Patch (*pP, *pQ)
399     //
400     if (!pP) 
401     {
402         TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
403         LINNO_RPRT(TaskAsip, -1);
404         return;
405     }
407     if (!pQ)
408     {
409         TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
410         LINNO_RPRT(TaskAsip, -1);
411         return;
412     }    
413     
414     //
415     // Audio Stream Input Task Configuration (*pAsitCfg):
416     //
417     pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
418     pAsitCfg->taskHandle = Task_self(); // set task handle
419     pAstCfg = pAsitCfg->pAstCfg;        // get pointer to AST common (shared) configuration
421     /* Set Audio Stream Number (1, 2, etc.) */
422     as = gBetaPrimeValue + 1;
423     pAstCfg->as = as;    
424     TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
426     //
427     // Initialize message log trace and line number reporting
428     //
429     for (z=STREAM1; z < STREAMN; z++)
430     {
431         TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
432     }
433     LINNO_RPRT(TaskAsip, -1);
434     
435     //
436     // Determine decoder and stream indices associated with the master input
437     //
438     zMI = pP->zone.master;
439     pAstCfg->masterDec = zMI;
440     pAstCfg->masterStr = zMI;
441     for (zX = DECODE1; zX < DECODEN; zX++)
442     {
443         if (pP->inputsFromDecodes[zX] == zMI)
444         {
445             pAstCfg->masterDec = zX;
446             pAstCfg->masterStr = pP->streamsFromDecodes[zX];
447             break;
448         }
449     }
450     zMD = pAstCfg->masterDec;
451     zMS = pAstCfg->masterStr;
453     // Initialize as per parametrized phases:
454     //
455     //   In standard form these are:
456     //      - Malloc: Memory Allocation
457     //      - Config: Configuration Initialization
458     //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
459     //      - Common: Common Memory Initialization
460     //      - AlgKey: Dec/Enc chain to Array Initialization
461     //      - Device: I/O Device Initialization
462     //      - DecOpCircBuf: Decoder Output Circular Buffer
463     //      - Unused: (available)
464     //
465     LINNO_RPRT(TaskAsip, -2);
466     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
467     {
468         Int linno;
469         if (pP->fxns->initPhase[i])
470         {
471             linno = pP->fxns->initPhase[i](pP, pQ, pAsitCfg);
472             if (linno) 
473             {
474                 LINNO_RPRT(TaskAsip, linno);
475                 return;
476             }
477         }
478         else 
479         {
480             TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
481         }
482         TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
483         LINNO_RPRT(TaskAsip, -i-3);
484     }
486     //
487     // End of Initialization -- display memory usage report.
488     //
489     if (pP->fxns->memStatusPrint)
490     {
491         pP->fxns->memStatusPrint("ASIT MEMSTAT REPORT",
492             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
493             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
494     }
495     
496     // (***) FL: revisit
497     // write back AST shared configuration
498     Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
499     Cache_wait();
501     // (***) FL: revisit
502     // write back Dec configuration
503     Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
504     Cache_wait();
506     // (***) FL: revisit
507     // write back entire beta table
508     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
509     Cache_wait();
510     
511     // FL: send start initialization message to slave
512     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
513     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
514     pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
515     pAspMsg->procId = hAspMsgMaster->masterProcId;
516     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
517     pAspMsg->expectResp = TRUE;
518     TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
519     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
520     if (status != MessageQ_S_SUCCESS)
521     {
522         SW_BREAKPOINT;
523     }
524     // wait for initialization complete message from slave
525     do {
526         //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
527         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
528     } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
529     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
530         (pAspMsg->cmd != ASP_MASTER_START_DONE) || 
531         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
532     {
533         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
534         SW_BREAKPOINT;
535     }
536     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
537     TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
538     status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
539     if (status != MessageQ_S_SUCCESS)
540     {
541         SW_BREAKPOINT;
542     }
544     // (***) FL: revisit
545     // invalidate Status structure addresses for Beta Units initialized on Slave
546     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
547     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
548     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
549     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
550     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
551     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
552     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
553     Cache_wait();
554     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
555     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
556     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
557     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
558     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
559     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
560     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
561     
562     // (***) FL: revisit
563     // invalidate Status structures for Beta Units initialized on Slave
564     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
565     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
566     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
567     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
568     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
569     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
570     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
571     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
572     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
573     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
574     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
575     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
576     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
577     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
578     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
579     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
580     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
581     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
582     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
583     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
584     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
585     Cache_wait();
586     
587 #ifdef NON_CACHE_STATUS
588     // Get the shared status structure GateMP handles. Initialized at slave.
589     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
590     {
591         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
592     }
593     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
594     {
595         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
596     }
597     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
598     {
599         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
600     }
601     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
602     {
603         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
604     }
605 #endif
607     // (***) FL: revisit
608     // invalidate Dec configuration
609     Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
610     Cache_wait();
611     
612     //
613     // Main processing loop
614     //   
615     for (z=STREAM1; z < STREAMN; z++)
616     {
617         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
618     }
620     TRACE_TERSE0("TaskAsip: Entering Main Loop.");
621     
622     errno = 0;
623     for (;;)
624     {
625         Int sourceSelect;
626         XDAS_Int8 sourceProgram;
628         loopCount++;
630 #if 0   // enable and tune to see startup behavior.
631         // this is an alternative to fixed/circular setting in pa.cfg.
632         // If you are searching for a memory allocation failure, disable on first round.
633         // All allocation has already happened.
634         // This is the outer loop.  This loop count goes up when the stream resets.
635         // If the stream is running without problems, this does not increment.
636         // If the stream is repeatedly resetting, this loop count will go up rapidly.
637         if (loopCount > 10)  // see traces for a few of the passes through the main loop.
638         {
639              TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
640              LOG_disable(&TR_MOD);  // stop tracing
641         }
642 #endif
644         TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
645         TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
646         
647         // since not decoding indicate such
648         pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
650         // any error forces idling of input
651         if (errno) 
652         {
653             for (z=INPUT1; z < INPUTN; z++)
654             {
655                 if (pAstCfg->xInp[z].hRxSio)
656                 {
657                     SIO_idle(pAstCfg->xInp[z].hRxSio);
658                 }
659             }
660         
661             TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
662             ERRNO_RPRT(TaskAsip, errno);
663         }
664         
665         // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
666         // up to allow lower priority tasks to run. This may seem odd to be at the top
667         // of the state machine but provides for a cleaner flow even though the very
668         // first time we enter we do a sleep which is non-intuitive.
669         TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
670         TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
671         Task_sleep(1);
673         TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
674         errno = pP->fxns->selectDevices(pP, pQ, pAsitCfg);
675         if (errno)
676         {
677             TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
678             continue;
679         }
681         // if no master input selected then we don't know what may be at the input
682         // so set to unknown and skip any remaining processing
683         if (!pAstCfg->xInp[zMI].hRxSio)
684         {
685             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
686                                (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
688             TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
689             continue;
690         }
691         
692         // if here then we have a valid input so query its status
693         errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig);
694         if (errno)
695         {
696             TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
697             continue;
698         }
700         // If master decoder is not enabled, or the input is unlocked, then do nothing
701         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode), 
702                                      GATEMP_INDEX_DEC);
703         if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
704         {
705             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
706             continue;
707         }
708         
709         // If no source selected then do nothing
710         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
711                                      GATEMP_INDEX_DEC);
712         if (tempVar8 == PAF_SOURCE_NONE)
713         {
714             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
715                                (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
716             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
717             continue;
718         }
720         // If we want pass processing then proceed directly
721         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
722                                      GATEMP_INDEX_DEC);
723         if (tempVar8 == PAF_SOURCE_PASS)
724         {
725             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
726             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
727                                (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
729             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_PASS);
730             if (pP->fxns->passProcessing)
731             {
732                 errno = pP->fxns->passProcessing(pP, pQ, pAsitCfg, NULL);                
733             }
734             else 
735             {
736                 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
737                 errno = ASPERR_PASS;
738             }
739             TRACE_VERBOSE0("TaskAsip: continue");
740             continue;
741         }
743         // .....................................................................
744         // At this point we have an enabled input and want to decode something.
745         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
746         // when no decoder is selected there are no calls to IB
747         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
748         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
749                                      GATEMP_INDEX_DEC);
750         pfpBegin(PFP_ID_ASIT_1, pAsitCfg->taskHandle);  // PFP begin
751         gNumPfpAsit1++;
752         // (***) FL: re-visit, hard-coded to use FRAMELENGTH (pP->frameLength) inside function
753         errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, tempVar8, NULL);
754         pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);         // PFP end
755         gNumPfpAsit1--;
757         if (errno)
758         {
759             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
760             continue;
761         }
762         
763         // query for input type
764         errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram);
765         if (errno)
766         {
767             TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
768             errno = ASPERR_AUTO_PROGRAM;
769             continue;
770         }
772         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
773                            sourceProgram, GATEMP_INDEX_DEC);
775         // if input is unclassifiable then do nothing
776         if (sourceProgram == PAF_SOURCE_UNKNOWN)
777         {
778             TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
779             continue;
780         }
782         // now that we have some input classification, and possibly an outstanding
783         // input frame, we determine whether or not to call decodeProcessing and with
784         // what decAlg.
785         sourceSelect = PAF_SOURCE_NONE;
786         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
787                                      GATEMP_INDEX_DEC);
788         switch (tempVar8)
789         {
790             // If autodetecting, decoding everything, and input is something
791             // (i.e. bitstream or PCM) then decode.
792             case PAF_SOURCE_AUTO:
793                 if (sourceProgram >= PAF_SOURCE_PCM)
794                 {
795                     sourceSelect = sourceProgram;                    
796                 }
797                 break;
799             // If autodetecting, decoding only PCM, and input is PCM then decode.
800             case PAF_SOURCE_PCMAUTO:
801                 if (sourceProgram == PAF_SOURCE_PCM)
802                 {
803                     sourceSelect = sourceProgram;                    
804                 }
805                 break;
807             // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
808             case PAF_SOURCE_BITSTREAM:
809                 if (sourceProgram >= PAF_SOURCE_AC3)
810                 {
811                     sourceSelect = sourceProgram;                    
812                 }
813                 break;
815             // If autodetecting, decoding only DTS, and input is DTS then decode.
816             case PAF_SOURCE_DTSALL:
817                 switch (sourceProgram) 
818                 {
819                     case PAF_SOURCE_DTS11:
820                     case PAF_SOURCE_DTS12:
821                     case PAF_SOURCE_DTS13:
822                     case PAF_SOURCE_DTS14:
823                     case PAF_SOURCE_DTS16:
824                     case PAF_SOURCE_DTSHD:
825                         sourceSelect = sourceProgram;
826                         break;
827                 }
828                 break;
830             // All others, e.g., force modes, fall through to here.
831             // If user made specific selection then program must match select.
832             // (NB: this compare relies on ordering of PAF_SOURCE)
833             default:
834                 sourceSelect = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
835                                                               GATEMP_INDEX_DEC);
836                 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
837                 {
838                     if (sourceProgram != sourceSelect)
839                     {
840                         sourceSelect = PAF_SOURCE_NONE;                        
841                     }
842                 }
843                 break;
844         }
846         // if we didn't find any matches then skip
847         if (sourceSelect == PAF_SOURCE_NONE)
848         {
849             TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
850             continue;
851         }
853         // FL: debug, reset IB capture buffer
854         capIbReset();
855         gCapIbReset_cnt++;
856         Log_info0("capIbReset()");
858         // FL: send source select message to slave
859         *(Int32 *)&asipMsgBuf[0] = sourceSelect;
860         if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
861                       asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
862         {
863             TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
864             SW_BREAKPOINT;
865         }
866         
867         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
868         // iff we are in this top level state machine and specifically not in decodeProcessing
869         pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
870         
871         TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
873         // Reduce priority level since autodetection complete
874         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)-1);
875         
876         gAspProfileEnable=1; // enable ASP profiling
877         
878         TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
879         errno = pP->fxns->decodeProcessing(pP, pQ, pAsitCfg, sourceSelect);
880         if (errno) 
881         {
882             TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
883         }
884         else
885         {
886             TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
887         }        
889         gAspProfileEnable=0; // disable ASP profiling
890         
891         // Increase priority level since decoding complete
892         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
894         // FL: send dec exit message to slave
895         if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
896             != ASP_MSG_NO_ERR)
897         {
898             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
899             SW_BREAKPOINT;                
900         }
902     } // End of main processing loop for (;;)
903     
904     //Log_info0("Exit taskAsipFxn()");
907 // -----------------------------------------------------------------------------
908 // ASIT Initialization Function - Memory Allocation
909 //
910 //   Name:      PAF_ASIT_initPhaseMalloc
911 //   Purpose:   Audio Stream Input Task Function for initialization of data pointers
912 //              by allocation of memory.
913 //   From:      audioStream1Task or equivalent
914 //   Uses:      See code.
915 //   States:    x
916 //   Return:    0 on success.
917 //              Source code line number on MEM_calloc failure.
918 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
919 //              * State information as per parent.
920 //              * Memory allocation errors.
921 //
922 Int
923 PAF_ASIT_initPhaseMalloc(
924     const PAF_ASIT_Params *pP, 
925     const PAF_ASIT_Patchs *pQ, 
926     PAF_ASIT_Config *pAsitCfg
929     PAF_AST_Config *pAstCfg;
930     Int as;                    /* Audio Stream Number (1, 2, etc.) */
931     Int zMS;
932     Error_Block    eb;
933         IHeap_Handle   decHeapHandle;
935     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
936     as = pAstCfg->as;
937     zMS = pAstCfg->masterStr;
938     
939     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
941     // Initialize error block
942     Error_init(&eb); 
944     /* Input memory */
945     if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
946         INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
947     {
948         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
949         SW_BREAKPOINT;
950         return __LINE__;
951     }
952     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xInp) %d bytes from space %d at 0x%x.",
953         INPUTN * sizeof (*pAstCfg->xInp),
954         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
956     /* Decode memory */
957 #ifdef NON_CACHE_STATUS
958     decHeapHandle = (IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM;
959 #else 
960     decHeapHandle = (IHeap_Handle)HEAP_INTERNAL1_SHM;
961 #endif
962     if (!(pAstCfg->xDec = Memory_calloc(decHeapHandle,
963         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
964     {
965         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
966         SW_BREAKPOINT;
967         return __LINE__;
968     }
970     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xDec) %d bytes from space %d at 0x%x.",
971         DECODEN * sizeof (*pAstCfg->xDec),
972         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
973                 
974     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
975     return 0;
976 } //PAF_ASIT_initPhaseMalloc
978 // -----------------------------------------------------------------------------
979 // ASIT Initialization Function - Memory Initialization from Configuration
980 //
981 //   Name:      PAF_ASIT_initPhaseConfig
982 //   Purpose:   Audio Stream Task Function for initialization of data values
983 //              from parameters.
984 //   From:      audioStream1Task or equivalent
985 //   Uses:      See code.
986 //   States:    x
987 //   Return:    0 on success.
988 //              Other as per initFrame0 and initFrame1.
989 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
990 //              * State information as per parent.
991 //
992 Int
993 PAF_ASIT_initPhaseConfig(
994     const PAF_ASIT_Params *pP, 
995     const PAF_ASIT_Patchs *pQ, 
996     PAF_ASIT_Config *pAsitCfg
999     PAF_AST_Config *pAstCfg;
1000     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1001     Int z;                     /* input/encode/stream/decode/output counter */
1002     Int zMS;
1004     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1005     as = pAstCfg->as;
1006     zMS = pAstCfg->masterStr;
1007     
1008     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1010     //
1011     // Unspecified elements have been initialized to zero during alloc
1012     //
1013     
1014     for (z=INPUT1; z < INPUTN; z++) 
1015     {
1016         pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1017         pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1018     }
1020     for (z=DECODE1; z < DECODEN; z++) 
1021     {
1022         Int zI = pP->inputsFromDecodes[z];
1023         pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1024         pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1025         //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1026     }
1028     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1029     return 0;
1030 } //PAF_ASIT_initPhaseConfig
1032 // -----------------------------------------------------------------------------
1033 // ASIT Initialization Function - ACP Algorithm Instantiation
1034 //
1035 //   Name:      PAF_ASIT_initPhaseAcpAlg
1036 //   Purpose:   Audio Stream Input Task Function for initialization of ACP by
1037 //              instantiation of the algorithm.
1038 //   From:      audioStream1Task or equivalent
1039 //   Uses:      See code.
1040 //   States:    x
1041 //   Return:    0 on success.
1042 //              Source code line number on ACP Algorithm creation failure.
1043 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1044 //              * State information as per parent.
1045 //              * Memory allocation errors.
1046 //
1047 Int
1048 PAF_ASIT_initPhaseAcpAlg(
1049     const PAF_ASIT_Params *pP, 
1050     const PAF_ASIT_Patchs *pQ, 
1051     PAF_ASIT_Config *pAsitCfg
1054     PAF_AST_Config *pAstCfg;
1055     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1056     Int z;                  /* input/encode/stream/decode/output counter */
1057     Int betaPrimeOffset;
1058     ACP_Handle acp;
1059     Int zMS;
1060     Int zS, zX;
1062     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1063     as = pAstCfg->as;
1064     zMS = pAstCfg->masterStr;
1065     
1066     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1068     ACP_MDS_init();
1070     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1071     {
1072         TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1073         return __LINE__;
1074     }
1075     pAsitCfg->acp = acp;
1077     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1078         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1080     for (z=INPUT1; z < INPUTN; z++) 
1081     {
1082         zS = z;
1083         for (zX = DECODE1; zX < DECODEN; zX++) 
1084         {
1085             if (pP->inputsFromDecodes[zX] == z) 
1086             {
1087                 zS = pP->streamsFromDecodes[zX];
1088                 break;
1089             }
1090         }
1091         acp->fxns->attach(acp, ACP_SERIES_STD,
1092             STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1093             (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1094         /* Ignore errors, not reported. */
1095     }
1097     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1099     return 0;
1100 } //PAF_ASIT_initPhaseAcpAlg
1102 // -----------------------------------------------------------------------------
1103 // ASIT Initialization Function - Common Memory
1104 //
1105 //   Name:      PAF_ASIT_initPhaseCommon
1106 //   Purpose:   Audio Stream Input Task Function for allocation of common memory.
1107 //   From:      audioStream1Task or equivalent
1108 //   Uses:      See code.
1109 //   States:    x
1110 //   Return:    0 on success.
1111 //              Source code line number on PAF_ALG_alloc failure.
1112 //              Source code line number on PAF_ALG_mallocMemory failure.
1113 //              Source code line number on Decode Chain initialization failure.
1114 //              Source code line number on ASP Chain initialization failure.
1115 //              Source code line number on Encode Chain initialization failure.
1116 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1117 //              * State information as per parent.
1118 //              * Memory allocation errors.
1119 //
1120 Int
1121 PAF_ASIT_initPhaseCommon(
1122     const PAF_ASIT_Params *pP, 
1123     const PAF_ASIT_Patchs *pQ, 
1124     PAF_ASIT_Config *pAsitCfg
1127     PAF_AST_Config *pAstCfg;
1128     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1129     Int z;                      /* stream counter */
1130     ACP_Handle acp;
1131     PAF_IALG_Config pafAlgConfig;
1132     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1133    
1134     acp = pAsitCfg->acp;
1135     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1136     as = pAstCfg->as;
1137     
1138     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1140     //
1141     // Determine memory needs and instantiate algorithms across audio streams
1142     //
1143     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1144     PAF_ALG_setup(&pafAlgConfig, 
1145         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1146         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1147         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1148         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1149         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1150         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1151         HEAP_CLEAR);
1153     if (pP->fxns->headerPrint)
1154     {
1155         pP->fxns->headerPrint();        
1156     }
1158     for (z = STREAM1; z < STREAMN; z++) 
1159     {
1160         TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1162         //
1163         // Determine common memory for:
1164         //  (1) Logical Input drivers
1165         //
1166         // Decode Algorithms common memory determined in ASP Slave.
1167         //
1168         PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1170         //
1171         // Determine common memory needs of Logical Input driver
1172         //
1174         // really need to loop over all inputs for this stream using the tables
1175         // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1176         // patch, and not needed for FS11, since there is only one input.
1177         if (INPUT1 <= z && z < INPUTN) 
1178         {
1179             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1180             if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1181             {
1182                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1183                 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1184                 SW_BREAKPOINT;
1185                 return __LINE__;
1186             }
1187             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1188             if (pP->fxns->allocPrint)
1189             {
1190                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1191             }
1192         }
1193     }
1194     {
1195         // Changes made to share scratch between zones
1196         // Assume maximum 3 zones and scratch common memory is at offset 0;
1197         int max=0;
1198         for (z=STREAM1; z<STREAMN; z++)
1199         {
1200             if (max < common[z][0].size)
1201             {
1202                 max = common[z][0].size;
1203             }
1204         }
1205         common[STREAM1][0].size=max;
1206         for (z=STREAM1+1; z<STREAMN; z++)
1207         {
1208             common[z][0].size = 0;            
1209         }
1210     }
1211         
1212     //
1213     // Allocate common memory for:
1214     //  (1) Logical Input drivers
1215     //
1216     for (z = STREAM1; z < STREAMN; z++) 
1217     {
1218         TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1219         if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
1220         {
1221             TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1222             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1223             SW_BREAKPOINT;
1224             return __LINE__;
1225         }
1226         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1227         // share zone0 scratch with all zones 
1228         common[z][0].base = common[0][0].base;
1229         if (pP->fxns->commonPrint)
1230         {
1231             pP->fxns->commonPrint(common[z], &pafAlgConfig);
1232         }
1234         //
1235         // Allocate non-common memories for Logical IO drivers
1236         //    Since these structures are used at run-time we allocate from external memory
1237         if (INPUT1 <= z && z < INPUTN) 
1238         {
1239             PAF_ASP_Chain *chain;
1240             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1241                            as+z, z);
1242             chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1243                         HEAP_EXTERNAL, as+z, acp, &trace,
1244                         inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1245             if (!chain) 
1246             {
1247                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1248                 return __LINE__;
1249             }
1250         }
1251     }
1252     TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1254     return 0;
1255 } //PAF_ASIT_initPhaseCommon
1257 // (***) FL: candidate for removal
1258 // -----------------------------------------------------------------------------
1259 // ASIT Initialization Function - Algorithm Keys
1260 //
1261 //   Name:      PAF_ASIT_initPhaseAlgKey
1262 //   Purpose:   Audio Stream Input Task Function for initialization of data values
1263 //              from parameters for Algorithm Keys.
1264 //   From:      audioStream1Task or equivalent
1265 //   Uses:      See code.
1266 //   States:    x
1267 //   Return:    0.
1268 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1269 //              * State information as per parent.
1270 //
1271 // .............................................................................
1272 Int
1273 PAF_ASIT_initPhaseAlgKey(
1274     const PAF_ASIT_Params *pP, 
1275     const PAF_ASIT_Patchs *pQ, 
1276     PAF_ASIT_Config *pAsitCfg
1279     PAF_AST_Config *pAstCfg;
1280     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1282     
1283     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1284     as = pAstCfg->as;
1285     (void)as;  // clear compiler warning in case not used with tracing disabled
1287     TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1289 #if 0 // FL: slave    
1290     for (z=DECODE1; z < DECODEN; z++) 
1291     {
1292         for (s=0; s < pP->pDecAlgKey->length; s++) 
1293         {
1294             if ((pP->pDecAlgKey->code[s].full != 0) &&
1295                 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s]))) 
1296             {
1297                 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1298                 /* Cast in interface, for now --Kurt */
1299             }
1300             else
1301             {
1302                 pC->xDec[z].decAlg[s] = NULL;
1303             }
1304         }
1305     }
1306 #endif
1308     return 0;
1309 } //PAF_ASIT_initPhaseAlgKey
1311 // -----------------------------------------------------------------------------
1312 // ASIT Initialization Function - I/O Devices
1313 //
1314 //   Name:      PAF_ASIT_initPhaseDevice
1315 //   Purpose:   Audio Stream Input Task Function for initialization of I/O Devices.
1316 //   From:      audioStream1Task or equivalent
1317 //   Uses:      See code.
1318 //   States:    x
1319 //   Return:    0 on success.
1320 //              Source code line number on device allocation failure.
1321 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1322 //              * State information as per parent.
1323 //              * Memory allocation errors.
1324 //
1325 Int
1326 PAF_ASIT_initPhaseDevice(
1327     const PAF_ASIT_Params *pP, 
1328     const PAF_ASIT_Patchs *pQ, 
1329     PAF_ASIT_Config *pAsitCfg
1332     PAF_AST_Config *pAstCfg;
1333     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1334     Int z;                              /* input/output counter */
1335     PAF_SIO_IALG_Obj    *pObj;
1336     PAF_SIO_IALG_Config *pAlgConfig;
1337     PAF_IALG_Config pafAlgConfig;
1340     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1341     as = pAstCfg->as;
1342     (void)as; // clear compiler warning in case not used with tracing disabled
1344     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1346     if (pP->fxns->bufMemPrint)
1347     {
1348         PAF_ALG_setup (&pafAlgConfig, 
1349             HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1350             HEAP_ID_INTERNAL1,              HEAP_INTERNAL1,
1351             HEAP_ID_EXTERNAL,               HEAP_EXTERNAL,
1352             HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM,
1353             HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM,
1354             HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1355             HEAP_CLEAR);
1356         TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1357     }
1359     for (z=INPUT1; z < INPUTN; z++) 
1360     {
1361         PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1363         pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1364         pAlgConfig = &pObj->config;
1366         pAstCfg->xInp[z].hRxSio = NULL;
1368         pConfig->base.pVoid       = pAlgConfig->pMemRec[0].base;
1369         pConfig->pntr.pVoid       = pAlgConfig->pMemRec[0].base;
1370         pConfig->head.pVoid       = pAlgConfig->pMemRec[0].base;
1371         pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1372         pConfig->allocation       = pAlgConfig->pMemRec[0].size;
1373         pConfig->sizeofElement    = 2;
1374         pConfig->precision        = 16;
1376         if (pP->fxns->bufMemPrint)
1377         {
1378             pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1379         }
1380     }
1382     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1384     return 0;
1385 } //PAF_ASIT_initPhaseDevice
1387 // (***) FL: move to ASOT
1388 // -----------------------------------------------------------------------------
1389 // ASIT Initialization Function - Decoder Output Circular Buffer
1390 //
1391 //   Name:      PAF_ASIT_initPhaseDecOpCircBuf
1392 //   Purpose:   Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1393 //   From:      audioStream1Task or equivalent
1394 //   Uses:      See code.
1395 //   States:    x
1396 //   Return:    0 on success.
1397 //              Source code line number on device allocation failure.
1398 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1399 //              * State information as per parent.
1400 //              * Memory allocation errors.
1401 //
1402 Int
1403 PAF_ASIT_initPhaseDecOpCircBuf(
1404     const PAF_ASIT_Params *pP, 
1405     const PAF_ASIT_Patchs *pQ, 
1406     PAF_ASIT_Config *pAsitCfg
1409     PAF_AST_Config *pAstCfg;
1410     PAF_AST_DecOpCircBuf *pCb;          /* Decoder output circular buffer */
1411     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1412     Int zMS;
1413     Int z;                              /* decode counter */
1414     Int errno;                          /* error number */
1415     Error_Block    eb;
1416     Int i;
1417     ACP_Handle acp;
1418     Int betaPrimeOffset;
1419     Int zS;
1421     // FL: (***)revisit
1422     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1423     as = pAstCfg->as;
1424     zMS = pAstCfg->masterStr;
1426     // Decode output circular buffer memory
1427     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1428         DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1429     {
1430         TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1431         SW_BREAKPOINT;
1432         return __LINE__;
1433     }
1435     TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pAsitCfg->xDecOpCb) %d bytes from space %d at 0x%x.",
1436         DECODEN * sizeof (*pAstCfg->xDecOpCb),
1437         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1439     for (z=DECODE1; z < DECODEN; z++)
1440     {
1441         pCb = &pAstCfg->xDecOpCb[z];
1442         
1443         // allocate audio frame circular buffer
1444         if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1445         {
1446             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1447             SW_BREAKPOINT;
1448         }
1449         // allocate audio frame PCM sample pointer array
1450         for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1451         {
1452             if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioData *), 4, &eb)))
1453             {
1454                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1455                 SW_BREAKPOINT;
1456             }
1457             if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioSize), 4, &eb)))
1458             {
1459                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1460                 SW_BREAKPOINT;
1461             }                
1462         }
1463         // allocate PCM sample buffer
1464         if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1465         {
1466             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1467             SW_BREAKPOINT;
1468         }
1469         pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1470         // allocate Metadata buffers
1471         if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1472         {
1473             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1474             SW_BREAKPOINT;
1475         }
1476         pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1478         #ifdef CB_RW_OP_CAP_PP // debug
1479         // allocate debug buffer
1480         if (!(pCb->cb_samples_op = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt32), 4, &eb)))
1481         {
1482             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1483             SW_BREAKPOINT;
1484         }
1486         // allocate debug buffer
1487         if (!(pCb->cb_op_owner = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1488         {
1489             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1490             SW_BREAKPOINT;
1491         }
1493         // allocate debug buffer
1494         if (!(pCb->cb_afRdIdx = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1495         {
1496             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1497             SW_BREAKPOINT;
1498         }
1500         // allocate debug buffer
1501         if (!(pCb->cb_afWrtIdx = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1502         {
1503             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1504             SW_BREAKPOINT;
1505         }
1507         // allocate debug buffer
1508         if (!(pCb->cb_numAfCb = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, CB_OP_COUNT_MAX * sizeof(UInt8), 4, &eb)))
1509         {
1510             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1511             SW_BREAKPOINT;
1512         }
1513         #endif
1514     }
1516     for (z = DECODE1; z < DECODEN; z++)
1517     {
1518         //
1519         // Initialize decoder output circular
1520         //
1521         
1522         // Initialize status
1523         pAstCfg->xDecOpCb[z].cbStatus = *pP->z_pDecOpCircBufStatus[z];
1524         
1525         // Default initialization
1526         errno = cbInit(pCb);
1527         if (errno)
1528         {
1529             SW_BREAKPOINT; // FL: debug
1530             return errno;
1531         }
1532     }
1533     
1534     // Get ASIT ACP handle
1535     acp = pAsitCfg->acp;
1536     if (!acp)
1537     {
1538         TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: ACP algorithm instance creation  failed", as+zMS);
1539         return __LINE__;
1540     }
1541     
1542     // Get Beta Prime offset
1543     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1544         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1545             
1546     for (z = DECODE1; z < DECODEN; z++)
1547     {
1548         // ACP attach CB
1549         zS = pP->streamsFromDecodes[z];
1550         acp->fxns->attach(acp, ACP_SERIES_STD,
1551             STD_BETA_DECOPCB + betaPrimeOffset * (as-1+zS),
1552             (IALG_Status *)&pAstCfg->xDecOpCb[z].cbStatus);        
1553     }
1554             
1555     return 0;
1556 } //PAF_ASIT_initPhaseDecOpCircBuf
1559 // -----------------------------------------------------------------------------
1560 // ASIT Initialization Function - Output Init-Sync
1561 //
1562 //   Name:      PAF_ASIT_initPhaseOutIS
1563 //   Purpose:   Audio Stream Input Task Function for initialization of Output Init-Sync.
1564 //
1565 Int
1566 PAF_ASIT_initPhaseOutIS(
1567     const PAF_ASIT_Params *pP, 
1568     const PAF_ASIT_Patchs *pQ, 
1569     PAF_ASIT_Config *pAsitCfg
1572     PAF_AST_Config *pAstCfg;
1573     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1574     Int z;                              /* decode counter */
1575     PAF_AST_OutInitSyncInfo *pOutISI;
1576     Error_Block    eb;
1577     Int i;
1580     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1581     as = pAstCfg->as;
1582     
1583     /* Output Init-Sync memory */
1584     if (!(pAstCfg->xOutIsi = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM, 
1585         DECODEN * sizeof (*pAstCfg->xOutIsi), 4, &eb)))
1586     {
1587         TRACE_TERSE1("PAF_ASIT_initPhaseOutIS: AS%d: Memory_calloc failed", as);
1588         SW_BREAKPOINT;
1589         return __LINE__;
1590     }
1592     // Reset all decoder stage flags
1593     for (z=DECODE1; z < DECODEN; z++)
1594     {
1595         // Get address of Output Init-Sync Info
1596         pOutISI = &pAstCfg->xOutIsi[z];
1597         for (i = 0; i < ASP_OUTIS_NUM_DEC_STAGES; i++)
1598         {
1599             // Reset flag value
1600             pOutISI->decStageOutInitSyncInfo[i].decFlag = 0;
1601         }
1602     }    
1603     
1604     return 0;
1605 } // PAF_ASIT_initPhaseOutIS
1608 #if 0
1609 // -----------------------------------------------------------------------------
1610 // AST Processing Function - Pass-Through Processing
1611 //
1612 //   Name:      PAF_AST_passProcessing
1613 //   Purpose:   Audio Stream Task Function for processing audio data as a
1614 //              pass-through from the input driver to the output driver
1615 //              for development and testing.
1616 //   From:      audioStream1Task or equivalent
1617 //   Uses:      See code.
1618 //   States:    x
1619 //   Return:    Error number in standard form (0 on success).
1620 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1621 //              * State information on initialization.
1622 //              * State information on processing.
1623 //
1625 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1626 /* Pass Processing is often omitted from builds to save memory, */
1627 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1629 Int
1630 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1632     Int z;                              /* input/output counter */
1633     Int errno = 0;                      /* error number */
1634     Int getVal;
1635     Int rxNumChan, txNumChan;
1636     Int first;
1637     Int zMD = pC->masterDec;
1638     Int zMI = pP->zone.master;
1641 #ifndef __TI_EABI__
1642     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1643 #endif    
1645     TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1647     //
1648     // Determine that receive/transmit channels are compatible
1649     //
1651     // Can handle handle only master input
1652     for (z=INPUT1; z < INPUTN; z++) {
1653         if (z != zMI && pC->xInp[z].hRxSio)
1654             return (ASPERR_PASS + 0x01);
1655     }
1657     /* Number of receive/transmit channels */
1659     if (! pC->xInp[zMI].hRxSio)
1660         return (ASPERR_PASS + 0x11);
1661     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1662         return (ASPERR_PASS + 0x12);
1663     if (rxNumChan > NUM_TX_CHAN(zMI))
1664         return (ASPERR_PASS + 0x13);
1666     for (z=OUTPUT1; z < OUTPUTN; z++) {
1667         if (! pC->xOut[zMI].hTxSio)
1668             return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1669         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1670             return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1671         if (txNumChan > NUM_TX_CHAN(zMI))
1672             return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1673     }
1675     //
1676     // Set up receive/transmit
1677     //
1679     SIO_idle (pC->xInp[zMI].hRxSio);
1680     for (z=OUTPUT1; z < OUTPUTN; z++) {
1681         if(SIO_idle (pC->xOut[z].hTxSio))
1682             return ASPERR_IDLE;
1683     }
1685     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1686         return (ASPERR_PASS + 0x14);
1688     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1689         return (ASPERR_PASS + 0x15);
1691     for (z=OUTPUT1; z < OUTPUTN; z++)
1692         pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1694     if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1695         return ASPERR_PASS + 0x16;
1697     if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1698         return ASPERR_PASS + 0x17;
1700     //
1701     // Receive and transmit the data in single-frame buffers
1702     //
1704     first = 1;
1705     while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1706         PAF_OutBufConfig *pOutBuf;
1707         PAF_InpBufConfig *pInpBuf;
1709         if (first) {
1710             first = 0;
1712             TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1714             for (z=OUTPUT1; z < OUTPUTN; z++) {
1715                 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1716                 if (getVal > 0) {
1717                     errno = ASPERR_ISSUE;
1718                     break;
1719                 }
1720                 else if (getVal < 0) {
1721                     errno = -getVal;
1722                     break;
1723                 }
1725                 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1726                     return (getVal & 0xff) | ASPERR_MUTE;
1727             }
1728             if (errno)
1729                 break;
1731         }
1733         getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1734         if (getVal > 0) {
1735             errno = ASPERR_ISSUE;
1736             break;
1737         }
1739         TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1741         getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1742         if (getVal < 0) {
1743             errno = -getVal;
1744             break;
1745         }
1747         for (z=OUTPUT1; z < OUTPUTN; z++) {
1748             getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1749             if (getVal < 0) {
1750                 errno = -getVal;
1751                 break;
1752             }
1753         }
1754         if( errno )
1755             break;
1757         TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1759         if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1760             break;
1762         for (z=OUTPUT1; z < OUTPUTN; z++) {
1763             getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1764             if (getVal > 0) {
1765                 errno = ASPERR_ISSUE;
1766                 break;
1767             }
1768             else if (getVal < 0) {
1769                 errno = -getVal;
1770                 break;
1771             }
1772         }
1773         if( errno )
1774             break;
1775     }
1777     //
1778     // Close down receive/transmit
1779     //
1781     TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1783     for (z=OUTPUT1; z < OUTPUTN; z++) {
1784         if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1785             if (! errno)
1786                 errno = (getVal & 0xff) | ASPERR_MUTE;
1787             /* convert to sensical errno */
1788         }
1789     }
1791     SIO_idle (pC->xInp[zMI].hRxSio);
1792     for (z=OUTPUT1; z < OUTPUTN; z++)
1793         SIO_idle (pC->xOut[z].hTxSio);
1795     return errno;
1797 } //PAF_AST_passProcessing
1798 #endif // #if 0
1800 #if 0
1801 // -----------------------------------------------------------------------------
1802 // AST Processing Function Helper - Pass-Through Processing Patch Point
1803 //
1804 //   Name:      PAF_AST_passProcessingCopy
1805 //   Purpose:   Pass-Through Processing Function for copying audio data
1806 //              from the input buffer to the output buffer.
1807 //   From:      AST Parameter Function -> passProcessing
1808 //   Uses:      See code.
1809 //   States:    x
1810 //   Return:    Error number in standard form (0 on success).
1811 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1812 //              x
1813 //
1815 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1816 /* Pass Processing is often omitted from builds to save memory, */
1817 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1819 Int
1820 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1822     Int z;                              /* output counter */
1823     Int errno;                          /* error number */
1824     Int i;
1825     Int rxNumChan, txNumChan;
1826     Int zMI = pP->zone.master;
1829     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1831     // Copy data from input channels to output channels one of two ways:
1833     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1834         return (ASPERR_PASS + 0x12);
1836     for (z=OUTPUT1; z < OUTPUTN; z++) {
1837         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1838             return (ASPERR_PASS + 0x22);
1840         if( txNumChan <= rxNumChan ) {
1842             // Copy one to one, ignoring later rx channels as needed.
1844             for( i=0; i < txNumChan; i++ ) {
1845                 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1846                 if( errno )
1847                     return errno;
1848             }
1849         }
1850         else {
1852             // Copy one to many, repeating earlier rx channels as needed.
1854             Int from, to;
1856             from = 0;
1857             to   = 0;
1858             while( to < txNumChan ) {
1859                 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1860                 if( errno )
1861                     return errno;
1863                 from++;
1864                 to++;
1865                 if( from == rxNumChan )
1866                     from = 0;
1867             }
1868         }
1869     }
1871     return 0;
1872 } //PAF_AST_passProcessingCopy
1873 #endif // #if 0
1875 // -----------------------------------------------------------------------------
1876 // ASIT Processing Function - Auto Processing
1877 //
1878 //   Name:      PAF_ASIT_autoProcessing
1879 //   Purpose:   Audio Stream Input Task Function for processing audio data to
1880 //              determine the input type without output.
1881 //   From:      audioStream1Task or equivalent
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 on initialization.
1887 //
1889 #define DECSIOMAP(X)                                                \
1890     pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1892 Int
1893 PAF_ASIT_autoProcessing(
1894     const PAF_ASIT_Params *pP, 
1895     const PAF_ASIT_Patchs *pQ, 
1896     PAF_ASIT_Config *pAsitCfg, 
1897     Int inputTypeSelect, 
1898     ALG_Handle pcmAlgMaster
1901     PAF_AST_Config *pAstCfg;
1902     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1903     Int errno = 0;          /* error number */
1904     Int nbytes;
1905     Int frameLength;
1906     Int zMD;
1907     Int zMI;
1908     Int zMS;
1909     
1910     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1911     as = pAstCfg->as;
1912     zMD = pAstCfg->masterDec;
1913     zMS = pAstCfg->masterStr;    
1914     zMI = pP->zone.master;    
1915     
1916     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1918     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1919                          PAF_SIO_CONTROL_SET_SOURCESELECT,
1920                          DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1921     {
1922         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1923         return errno;
1924     }
1925     //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1926     //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
1927     frameLength = FRAMELENGTH; // (***) FL: fix PCM frameLength
1928     
1929     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1930                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1931     {
1932         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1933             errno, ASPERR_AUTO_LENGTH);
1934         return ASPERR_AUTO_LENGTH;
1935     }
1937     if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1938                           &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1939                           PAF_SIO_REQUEST_SYNC))
1940     {
1941         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1942             errno, ASPERR_ISSUE);
1943         return ASPERR_ISSUE;
1944     }
1946     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1948     // all of the sync scan work is done in this call. If the error returned
1949     // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1950     // error so we mask it off.
1951     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1952     if (nbytes == -DIBERR_SYNC)
1953     {
1954 #if 0 // (***) FL: shows timing of autosync restart
1955         // (***) debug // B5
1956         {
1957             static Uint8 toggleState = 0;
1958             if (toggleState == 0)
1959                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1960             else
1961                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1962             toggleState = ~(toggleState);
1963         }
1964 #endif                
1965         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1966         return nbytes;
1967     }
1968     if (nbytes != sizeof(PAF_InpBufConfig))
1969     {
1970         TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1971             nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1972         return ASPERR_RECLAIM;
1973     }
1974     if (errno)
1975     {
1976         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1977     }
1978     return errno;
1979 } //PAF_ASIT_autoProcessing
1981 UInt32 gProbe1Err=0;
1982 UInt32 gProbe2Err=0;
1983 UInt32 gMajorAuMissed=0;
1985 // -----------------------------------------------------------------------------
1986 // ASIT Processing Function - Decode Processing
1987 //
1988 //   Name:      PAF_ASIT_decodeProcessing
1989 //   Purpose:   Audio Stream Input Task Function for processing audio data.
1990 //   From:      audioStream1Task or equivalent
1991 //   Uses:      See code.
1992 //   States:    x
1993 //   Return:    Error number in standard form (0 on success).
1994 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1995 //              * State information on initialization (via children).
1996 //              * State information on processing (via children).
1997 //              * Decode warnings.
1998 //
1999 // When "writeDECModeContinuous" is used for zMI input/decode:
2000 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
2001 // (a) if "writeDECCommandRestart" is used
2002 //    (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
2003 // (b) if "writeDECSourceSelectNone" is used
2004 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
2005 // (c) if an error occurs in
2006 //     INIT
2007 //     CONT ("subsequent block state", which "Establish[es] secondary timing")
2008 //         -> PAF_AST_decodeCont(): "Await slave inputs"
2009 //     STREAM (errno |= PAF_COMPONENT_ASP)
2010 //     ENCODE (errno |= PAF_COMPONENT_ENCODE)
2011 // [ the latter errors lead to "switch_break:"
2012 //         -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
2013 //
2014 // [ Notably, in FINAL ("frame-finalization state")
2015 //         -> PAF_AST_decodeFinalTest() is *not* called,
2016 //   and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
2017 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
2018 //
2019 // States in which error can't occur:
2020 //     AGAIN ("subsequent initial state")
2021 //
2022 // States in which (some) errors must be handled:
2023 //     INFO1 ("first frame state")
2024 //         -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
2025 //            -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
2026 //               ?*? but what about ASPERR_RESYNC from same call ?*?
2027 //            -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
2028 //            -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
2029 //         -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
2030 //            - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
2031 //            - enc->fxns->info()
2032 //            - pP->fxns->setCheckRateX()
2033 //            - pP->fxns->startOutput()
2034 //            - "Start slave inputs if necessary"
2035 //     INFO2 ("subsequent frame state")
2036 //         -> PAF_AST_decodeInfo(): (see above)
2037 //         -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
2038 //            - pP->fxns->setCheckRateX()
2039 //     TIME ("timing state")
2040 //         -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
2041 //         -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
2042 //         -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
2043 //            (*OK* don't try to recover from this*)
2044 //         -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
2045 //         -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
2046 //            possibly in PAF_AST_decodeProcessing() itself **
2047 //     DECODE ("decode state")
2048 //         -> PAF_AST_decodeDecode(): pass on error from
2049 //            - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2050 //            - dec->fxns->reset()
2051 //            - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2052 //         -> *DONE* must catch error from (zMI) dec->fxns->decode()
2053 //         -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2054 Int
2055 PAF_ASIT_decodeProcessing(
2056     const PAF_ASIT_Params *pP, 
2057     const PAF_ASIT_Patchs *pQ, 
2058     PAF_ASIT_Config *pAsitCfg, 
2059     Int sourceSelect
2062     PAF_AST_Config *pAstCfg;
2063     //Int as = pAsitCfg->as;              /* Audio Stream Number (1, 2, etc.) */
2064     Int z;                              /* decode counter */
2065     Int errno;                          /* error number */
2066     Int getVal;
2067     enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2068     ALG_Handle alg[DECODEN_MAX];
2069     Int zMD;
2070     Int zMS;
2071     Int size;
2072     //PAF_InpBufConfig *pIpBufConfig;
2073     Int frame; // decoder input frame count
2074     Int block; // (***) FL: formerly  -- decoder output block count / input frame
2075     Int8 tempVar8, temp2Var8;
2076     
2077     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2078     zMD = pAstCfg->masterDec;
2079     zMS = pAstCfg->masterStr;
2080         
2081     for (z=DECODE1; z < DECODEN; z++)
2082     {
2083         alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];        
2084     }
2085     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2087     //
2088     // Receive and process the data in single-frame buffers
2089     //
2091     state = INIT;
2092     errno = 0; /* error number */
2094     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
2095                                  GATEMP_INDEX_DEC);
2096     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2098     for (;;) 
2099     {
2100         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
2101                                      GATEMP_INDEX_DEC);
2102         if (tempVar8 == PAF_SOURCE_NONE)
2103         {
2104             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2105             state = QUIT;
2106         }
2108         // Process commands (decode)
2109         getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
2110         if (getVal) 
2111         {
2112             if (state != INIT)   // no need to restart/abort if not yet started
2113             {
2114                 if (getVal == ASPERR_QUIT)
2115                 {
2116                     state = QUIT;
2117                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2118                 }
2119                 else if (getVal == ASPERR_ABORT)
2120                 {
2121                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2122                     
2123                     // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2124                     pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2125                     gNumPfpAsit2--;
2126                     
2127                     return getVal;
2128                 }
2129                 else
2130                 {
2131                     /* ignore */;
2132                 }
2133             }
2134             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2135         }
2137         TRACE_TIME((&TIME_MOD,         "... + %d = %d ->", dtime(), TSK_time()));
2138         TRACE_TIME((&TIME_MOD,         "                 state = %s", stateName[state]));
2140         // Process state (decode)
2141         switch (state) 
2142         {
2143             case INIT: // initial state
2144                 gAsipInitCnt++;
2145                 Log_info0("TaskAsip: state=INIT");               
2147                 errno = pP->fxns->decodeInit(pP, pQ, pAsitCfg, sourceSelect);
2148                 if (errno)
2149                 {
2150                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x.  break after decodeInit", errno);
2151                     break;
2152                 }
2153                                
2154                 frame = 0;
2155                 block = 0;
2157                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2158                 state = INFO1;
2159                 continue;
2161             case INFO1: // first frame state
2162                 gAsipInfo1Cnt++;
2163                 Log_info0("TaskAsip: state=INFO1");
2164                 
2165                 // Establish primary timing
2166                 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2167                 if (errno)
2168                 {
2169                     gAsipInfo1_PrimaryErrCnt++;
2170                     TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2171                     break;
2172                 }
2173                 
2174                 tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2175                                               GATEMP_INDEX_DEC);
2176                 temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate), 
2177                                               GATEMP_INDEX_DEC);
2178                 // Don't start decode until major access unit is found.
2179                 if (((tempVar8 == PAF_SOURCE_THD)    ||
2180                      (tempVar8 == PAF_SOURCE_DXP)    ||
2181                      (tempVar8 == PAF_SOURCE_DTSHD)) &&
2182                      (temp2Var8 == PAF_SAMPLERATE_UNKNOWN)) 
2183                 {
2184                     Int z;
2185                     for (z=DECODE1; z < DECODEN; z++) 
2186                     {
2187                         Int zI = pP->inputsFromDecodes[z];
2188                         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode), 
2189                                                      GATEMP_INDEX_DEC);
2190                         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2191                         {
2192                             TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2193                             if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2194                                 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2195                             {
2196                                 gProbe2Err++;
2197                                 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2198                                 
2199                                 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2200                                 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2201                                 gNumPfpAsit2--;
2202                                 
2203                                 return (ASPERR_ISSUE);
2204                             }
2205                         }
2206                     }
2207                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2208                     gMajorAuMissed++; // debug
2209                     frame++;
2210                     state = INFO1;
2211                     continue;
2212                 }
2213                 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2215                 // Establish secondary timing
2216                 errno = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, frame, block);
2217                 if (errno)
2218                 {
2219                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x.  break after decodeInfo1", errno);
2220                     gAsipInfo1_ErrCnt++;
2221                     break;
2222                 }
2224                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2225                 state = DECODE;
2226                 continue;
2228             case INFO2: // subsequent frame state
2229                 gAsipInfo2Cnt++;
2230                 Log_info0("TaskAsip: state=INFO2");
2232                 // Establish primary timing
2233                 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2234                 if (errno)
2235                 {
2236                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2237                     gAsipInfo2_PrimaryErrCnt++;
2238                     break;
2239                 }
2240                                 
2241                 // Measure cycles in decode processing loop.
2242                 // Only measures cycles spent in loop.
2243                 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);         // PFP end
2244                 gNumPfpAsit2--;
2245                 pfpBegin(PFP_ID_ASIT_2, pAsitCfg->taskHandle);  // PFP begin
2246                 gNumPfpAsit2++;
2248                 errno = pP->fxns->decodeInfo2(pP, pQ, pAsitCfg, frame, block);
2249                 if (errno)
2250                 {
2251                     TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2252                     gAsipInfo2_ErrCnt++;
2253                     break;
2254                 }
2255                
2256                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2257                 state = DECODE;
2258                 continue;
2260             case DECODE: // decode state
2261                 gAsipDecodeCnt++;
2262                 Log_info0("TaskAsip: state=DECODE");
2264                 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
2265                 if (errno)
2266                 {
2267                     gAsipDecodeErrCnt++;
2268                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
2269                     break;
2270                 }
2271                 
2272                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2273                 state = FINAL;
2274                 continue;
2276             case FINAL: // frame-finalization state
2277                 gAsipFinalCnt++;
2278                 Log_info0("TaskAsip: state=FINAL");
2280                 // Check for final frame, and if indicated:
2281                 // - Exit state machine to "complete" processing.
2282                 if (pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, frame, block)) 
2283                 {
2284                     break;
2285                 }
2287                 frame++;
2288                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2289                 state = INFO2;
2290                 continue;
2292             case QUIT: // exit state
2293                 gAsipQuitCnt++;
2294                 Log_info0("TaskAsip: state=QUIT");
2296                 // Quit:
2297                 // - Set error number registers.
2298                 // - Exit state machine to "decode complete" processing.
2299                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2300                 errno = ASPERR_QUIT;
2301                 break;
2303             default: // unknown state
2305                 // Unknown:
2306                 // - Set error number registers.
2307                 // - Exit state machine to "decode complete" processing.
2309                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2310                 errno = ASPERR_UNKNOWNSTATE;
2311                 break;
2313         }  // End of switch (state).
2315         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2316         if (pP->fxns->decodeComplete(pP, pQ, pAsitCfg, alg, frame, block))
2317         {
2318             /* ignored? */;
2319         }
2320         
2321         TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2323         // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2324         //pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2325         //gNumPfpAsit2--;
2326         
2327         //return errno;
2328         break;
2329     }  // End of for (;;) to Receive, process, and transmit the data.
2330     
2331     // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2332     pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2333     gNumPfpAsit2--;
2334     
2335     return errno;
2336 } //PAF_ASIT_decodeProcessing
2338 // -----------------------------------------------------------------------------
2339 // ASIT Decoding Function - Decode Command Processing
2340 //
2341 //   Name:      PAF_ASIT_decodeCommand
2342 //   Purpose:   Decoding Function for processing Decode Commands.
2343 //   From:      AST Parameter Function -> decodeProcessing
2344 //   Uses:      See code.
2345 //   States:    x
2346 //   Return:    Error number in standard form (0 on success).
2347 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2348 //              * Command execution.
2349 //
2351 Int
2352 PAF_ASIT_decodeCommand(
2353     const PAF_ASIT_Params *pP, 
2354     const PAF_ASIT_Patchs *pQ, 
2355     PAF_ASIT_Config *pAsitCfg
2358     PAF_AST_Config *pAstCfg;
2359     Int as;                 /* Audio Stream Number (1, 2, etc.) */
2360     Int z;                  /* decode counter */
2361     Int zS;
2362     Int8 tempVar8;
2364     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2365     as = pAstCfg->as;
2367     for (z=DECODE1; z < DECODEN; z++) 
2368     {
2369         zS = pP->streamsFromDecodes[z];
2370         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.command2), 
2371                                      GATEMP_INDEX_DEC);
2372         if (!(tempVar8 & 0x80))
2373         {
2374             switch (tempVar8)
2375             {
2376                 case 0: // command none - process
2377                     tempVar8 |= 0x80;
2378                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2379                                        tempVar8, GATEMP_INDEX_DEC);
2380                     break;
2381                 case 1: // command abort - leave now
2382                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2383                     tempVar8 |= 0x80;
2384                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2385                                        tempVar8, GATEMP_INDEX_DEC);
2386                     return (ASPERR_ABORT);
2387                 case 2: // command restart - leave later
2388                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2389                     tempVar8 |= 0x80;
2390                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2391                                        tempVar8, GATEMP_INDEX_DEC);
2392                     return (ASPERR_QUIT);
2393                 default: // command unknown - ignore
2394                     break;
2395             }
2396         }
2397     }
2399     return 0;
2400 } //PAF_ASIT_decodeCommand
2402 // -----------------------------------------------------------------------------
2403 // ASIT Decoding Function - Reinitialization of Decode
2404 //
2405 //   Name:      PAF_ASIT_decodeInit
2406 //   Purpose:   Decoding Function for reinitializing the decoding process.
2407 //   From:      AST Parameter Function -> decodeProcessing
2408 //   Uses:      See code.
2409 //   States:    x
2410 //   Return:    Error number in standard or SIO form (0 on success).
2411 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2412 //              * State information as per parent.
2413 //
2414 Int
2415 PAF_ASIT_decodeInit(
2416     const PAF_ASIT_Params *pP, 
2417     const PAF_ASIT_Patchs *pQ, 
2418     PAF_ASIT_Config *pAsitCfg, 
2419     Int sourceSelect
2422     PAF_AST_Config *pAstCfg;
2423     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
2424     Int as;                             /* Audio Stream Number (1, 2, etc.) */
2425     Int z;                              /* decode/encode counter */
2426     Int errno;                          /* error number */
2427     Int zI, zS;
2428     Int zMD;
2429     Int zMI;
2430     Int argIdx;
2431     Int8 tempVar8;
2432     char decMsgBuf[ASP_MSG_BUF_LEN];
2433     
2434     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2435     as = pAstCfg->as;
2436     zMD = pAstCfg->masterDec;
2437     zMI = pP->zone.master;
2438     (void)as;  // clear compiler warning in case not used with tracing disabled
2439     
2440     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2442     // reset frameCount
2443     for (z=DECODE1; z < DECODEN; z++)
2444     {
2445         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2446                                      GATEMP_INDEX_DEC);
2447         if (tempVar8)
2448         {
2449             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2450                               (Int)0, GATEMP_INDEX_DEC);
2451         }
2452     }
2454     for (z=DECODE1; z < DECODEN; z++) 
2455     {
2456         zI = pP->inputsFromDecodes[z];
2457         zS = pP->streamsFromDecodes[z];
2458         (void)zS; // clear compiler warning in case not used with tracing disabled
2459         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode), 
2460                                      GATEMP_INDEX_DEC);
2461         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2462         {
2464             Uns gear;
2465             Int frameLength;
2466             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2468             // write back Dec configuration
2469             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2470             Cache_wait();
2472             // FL: send dec activate message to slave
2473             argIdx = 0; // set decIdx (zone index)
2474             *(Int32 *)&decMsgBuf[argIdx] = z;
2475             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE, 
2476                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
2477             {
2478                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
2479                 SW_BREAKPOINT; // temporary
2480                 return -1; // temporary
2481             }           
2483 #if 0 // FL: decoder activate call, slave
2484             if (decAlg[z]->fxns->algActivate)
2485                 decAlg[z]->fxns->algActivate (decAlg[z]);
2486 #endif
2487             // FL: send dec reset message to slave
2488             argIdx = 0; // set decIdx
2489             *(Int32 *)&decMsgBuf[argIdx] = z;
2490             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE, 
2491                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2492             {
2493                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
2494                 SW_BREAKPOINT; // temporary
2495                 return -1; // temporary
2496             }
2497             else
2498             {
2499                 argIdx = 0; // get decErrno
2500                 errno = *(Int32 *)&decMsgBuf[argIdx];                
2501             }   
2503             // (***) FL: revisit
2504             // invalidate Dec configuration
2505             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2506             Cache_wait();
2507             
2508 #if 0 // FL: decoder reset call, slave
2509             if (dec->fxns->reset
2510                 && (errno = dec->fxns->reset (dec, NULL,
2511                                               &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2512                 return errno;
2513 #endif
2514             if (errno != 0)
2515             {
2516                 return errno;
2517             }
2518             
2519             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2520                                               GATEMP_INDEX_DEC);
2521             tempVar8 = gear < GEARS ? gear : 0;
2522             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2523                                    tempVar8, GATEMP_INDEX_DEC);
2524             
2525 #if 0 // FL: change handle to decIdx (zone index)
2526             frameLength = pP->fxns->computeFrameLength(decAlg[z], 
2527                 FRAMELENGTH,
2528                 pC->xDec[z].decodeStatus.bufferRatio);
2529 #endif
2530 #if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
2531             frameLength = pP->fxns->computeFrameLength(z, 
2532                 FRAMELENGTH, 
2533                 pC->xDec[z].decodeStatus.bufferRatio);
2534 #else
2535             // Compute decoder frame length based on source selection
2536             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
2537 #endif    
2538             
2539             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2540             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2541             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2542           
2543 #if 0 // FL: Moved to ARM:ASDT:INFO
2544             // Initialize decoder output circular buffer for selected source
2545             errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2546             if (errno)
2547             {
2548                 SW_BREAKPOINT; // debug
2549                 return errno;
2550             }
2551             // debug
2552             cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2553 #endif
2554             
2555             if (z != zMD) 
2556             {
2557                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2558                 {
2559                     return errno;
2560                 }
2561             }
2563             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2564                                              GATEMP_INDEX_DEC);
2565             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2566                 DECSIOMAP(tempVar8)))
2567             {
2568                 return errno;
2569             }
2571             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, 
2572                 frameLength))
2573             {
2574                 return errno;
2575             }
2576             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus, 
2577                 &pAstCfg->xInp[zI].inpBufConfig))
2578             {
2579                 return errno;
2580             }
2581         }
2582     }
2584     if (pAstCfg->xInp[zMI].hRxSio) 
2585     {
2586         errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2587             sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2588         if (errno)
2589         {
2590             return errno;
2591         }
2592     }
2594     return 0;
2595 } //PAF_AST_decodeInit
2597 // -----------------------------------------------------------------------------
2598 // ASIT Decoding Function - Info Processing, Common
2599 //
2600 //   Name:      PAF_ASIT_decodeInfo
2601 //   Purpose:   Decoding Function for processing information in a manner that
2602 //              is common for both initial and subsequent frames of input data.
2603 //   From:      AST Parameter Function -> decodeProcessing
2604 //   Uses:      See code.
2605 //   States:    x
2606 //   Return:    Error number in standard form (0 on success).
2607 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2608 //              * State information as per parent.
2609 //
2610 Int
2611 PAF_ASIT_decodeInfo(
2612     const PAF_ASIT_Params *pP, 
2613     const PAF_ASIT_Patchs *pQ, 
2614     PAF_ASIT_Config *pAsitCfg, 
2615     Int frame, 
2616     Int block
2619     PAF_AST_Config *pAstCfg;
2620     Int as;                    /* Audio Stream Number (1, 2, etc.) */
2621     Int z;                     /* input/decode/stream counter */
2622     Int errno;                 /* error number */
2623     Int sioErr;                /* error number, SIO */
2624     Int zD, zI, zS, zX;
2625     Int zMD;
2626     Int zMI;
2627     Int zMS;
2628     UInt32 curTime;
2629     Int argIdx;
2630     Int8 tempVar8;
2631     Int tempVar;
2632     char decMsgBuf[ASP_MSG_BUF_LEN];
2633     // FL: revisit
2634     //Int size;
2635     //PAF_InpBufConfig *pIpBufConfig;
2637     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2638     as = pAstCfg->as;
2639     zMD = pAstCfg->masterDec;
2640     zMS = pAstCfg->masterStr;
2641     zMI = pP->zone.master;
2642     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
2643     
2644     // Set decode control: sample rate, emphasis
2645     for (z=INPUT1; z < INPUTN; z++)
2646     {
2647         zD = z;
2648         for (zX = DECODE1; zX < DECODEN; zX++) 
2649         {
2650             if (pP->inputsFromDecodes[zX] == z) 
2651             {
2652                 zD = zX;
2653                 break;
2654             }
2655         }
2656 #ifdef PROFILER
2657             // modify for different sampling rate
2658             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2659             {
2660                 start_profiling = 1;
2661             }
2662             else
2663             {
2664                 start_profiling = 0;
2665             }
2666 #endif
2667         if (pAstCfg->xInp[z].hRxSio) 
2668         {
2669             //determine associated decoder
2670             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus != 
2671                 pAstCfg->xDec[zD].decodeControl.sampleRate) 
2672             {
2673                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) 
2674                 {
2675                     pAstCfg->xDec[zD].decodeControl.sampleRate = 
2676                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2677                 }
2678                 else
2679                 {
2680                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2681                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2682                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus, 
2683                         pAstCfg->xDec[zD].decodeControl.sampleRate);
2684                     // return (ASPERR_INFO_RATECHANGE);
2685                 }
2686             }
2688             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2689                                              GATEMP_INDEX_DEC);
2690             pAstCfg->xDec[zD].decodeControl.emphasis = 
2691                 tempVar8 != PAF_SOURCE_PCM
2692                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2693                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2694         }
2695         else 
2696         {
2697             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2698             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2699         }
2700     }
2702     // Wait for info input
2703     TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2704     if (pAstCfg->xInp[zMI].hRxSio) 
2705     {
2706         TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2707         sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2708         if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2709         {
2710             TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM.  sioErr: 0x%x", sioErr);
2711             return ASPERR_RECLAIM;
2712         }
2713         
2714         //// FL: debug, capture input buffer
2715         //capIb(pAstCfg->xInp[zMI].pInpBuf);
2716         //gCapIb_cnt++;
2717         
2718 #if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2719         // (***) debug // B5
2720         {
2721             static Uint8 toggleState = 0;
2722             if (toggleState == 0)
2723                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2724             else
2725                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2726             toggleState = ~(toggleState);
2727         }
2728 #endif
2730         //
2731         // Simulate Rx SIO_reclaim() pend
2732         //
2733         //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER); 
2734         gTaskAsipCnt++;
2735         curTime = Clock_getTicks();
2736         //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);        
2737         //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2738         //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2739     } //pAstCfg->xInp[zMI].hRxSio
2741     // Decode info
2742     for (z=DECODE1; z < DECODEN; z++) 
2743     {
2744         zI = pP->inputsFromDecodes[z];
2745         zS = pP->streamsFromDecodes[z];
2746         (void)zS; // clear compiler warning in case not used with tracing disabled
2748         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2749                                      GATEMP_INDEX_DEC);
2750         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2751         {
2752             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2754             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2755                 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2756             {
2757                 TRACE_TERSE1("return error errno 0x%x.", errno);
2758                 return errno;
2759             }
2761 #if 1
2762             // (***) FL: revisit
2763             // write back Inp configuration
2764             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2765             // write back Dec configuration
2766             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2767             Cache_wait();
2768 #endif
2769             
2770             // FL: send info message to slave
2771             argIdx = 0; // set decIdx
2772             *(Int32 *)&decMsgBuf[argIdx] = z;
2773             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE, 
2774                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2775             {
2776                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
2777                 SW_BREAKPOINT; // temporary
2778                 return -1;     // temporary
2779             }
2780             else
2781             {
2782                 argIdx = 0; // get decErrno
2783                 errno = *(Int32 *)&decMsgBuf[argIdx];                
2784             }             
2786 #if 1
2787             // (***) FL: revisit
2788             // invalidate Dec configuration
2789             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2790             Cache_wait();                            
2791 #endif            
2792             
2793 #if 0 // FL: decoder info call, slave
2794             if (dec->fxns->info
2795                 && (errno = dec->fxns->info (dec, NULL,
2796                                              &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus))) 
2797 #endif
2798             if (errno)
2799             {
2800                 TRACE_TERSE1("return error errno 0x%x.", errno);
2801                 return errno;
2802             }
2804             // increment decoded frame count
2805             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2806                                        GATEMP_INDEX_DEC);
2807             tempVar += 1;
2808             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2809                               tempVar, GATEMP_INDEX_DEC);
2810         }
2811     } // z=DECODE1 to DECODEN
2813     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2814     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
2815                                  GATEMP_INDEX_DEC);
2816     if (tempVar8)
2817     {
2818         XDAS_Int8 sourceProgram;
2819         if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2820             (Arg)&sourceProgram))
2821         {
2822             TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2823             return ASPERR_AUTO_PROGRAM;
2824         }
2826         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
2827                            sourceProgram, GATEMP_INDEX_DEC);
2828     }
2830     // since now decoding update decode status for all enabled decoders
2831     for (z=DECODE1; z < DECODEN; z++)
2832     {
2833         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2834                                      GATEMP_INDEX_DEC);
2835         if (tempVar8)
2836         {
2837             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
2838                                          GATEMP_INDEX_DEC);
2839             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2840                                tempVar8, GATEMP_INDEX_DEC);
2842             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2843                                          GATEMP_INDEX_DEC);
2844             if (tempVar8 == PAF_SOURCE_SNG)
2845             {
2846                 tempVar8 = PAF_SOURCE_SNG;
2847                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2848                                    tempVar8, GATEMP_INDEX_DEC);
2849             }
2850         }
2851     }
2853 #if 0 // FL: ASDT (slave)
2854     // TODO: move this to start of this function so that it doesn't affect IO timing
2855     // Initialize audio frame(s)
2856     //    Re-initialize audio frame if there is an associated decode and
2857     //    that decode doesn't have a valid input or is turned off
2858     for (z=STREAM1; z < STREAMN; z++) 
2859     {
2860         Int reset = 0;
2861         for (zX = DECODE1; zX < DECODEN; zX++) 
2862         {
2863             if (pP->streamsFromDecodes[zX] == z) 
2864             {
2865                 zI = pP->inputsFromDecodes[zX];
2866                 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2867                 {
2868                     reset = 1;
2869                 }
2870             }
2871         }
2872         if (reset) 
2873         {
2874             TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2875             pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2876         }
2877         else
2878         {
2879             TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2880         }
2881     }
2882 #endif    
2884     return 0;
2885 } //PAF_ASIT_decodeInfo
2887 // -----------------------------------------------------------------------------
2888 // ASIT Decoding Function - Info Processing, Initial
2889 //
2890 //   Name:      PAF_ASIT_decodeInfo1
2891 //   Purpose:   Decoding Function for processing information in a manner that
2892 //              is unique to initial frames of input data.
2893 //   From:      AST Parameter Function -> decodeProcessing
2894 //   Uses:      See code.
2895 //   States:    x
2896 //   Return:    Error number in standard or SIO form (0 on success).
2897 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2898 //              * State information as per parent.
2899 //
2900 Int
2901 PAF_ASIT_decodeInfo1(
2902     const PAF_ASIT_Params *pP, 
2903     const PAF_ASIT_Patchs *pQ, 
2904     PAF_ASIT_Config *pAsitCfg, 
2905     Int frame, 
2906     Int block
2909     return 0;
2910 } //PAF_ASIT_decodeInfo1
2912 // -----------------------------------------------------------------------------
2913 // AST Decoding Function - Info Processing, Subsequent
2914 //
2915 //   Name:      PAF_AST_decodeInfo2
2916 //   Purpose:   Decoding Function for processing information in a manner that
2917 //              is unique to frames of input data other than the initial one.
2918 //   From:      AST Parameter Function -> decodeProcessing
2919 //   Uses:      See code.
2920 //   States:    x
2921 //   Return:    Error number in standard form (0 on success).
2922 //   Trace:     None.
2923 //
2924 Int
2925 PAF_ASIT_decodeInfo2(
2926     const PAF_ASIT_Params *pP, 
2927     const PAF_ASIT_Patchs *pQ, 
2928     PAF_ASIT_Config *pAsitCfg, 
2929     Int frame, 
2930     Int block
2933     return 0;
2934 } //PAF_ASIT_decodeInfo2
2936 #if 0
2937 // -----------------------------------------------------------------------------
2938 // AST Decoding Function - Continuation Processing
2939 //
2940 //   Name:      PAF_AST_decodeCont
2941 //   Purpose:   Decoding Function for processing that occurs subsequent to
2942 //              information processing but antecedent to timing processing
2943 //              for frames of input data other than the initial one.
2944 //   From:      AST Parameter Function -> decodeProcessing
2945 //   Uses:      See code.
2946 //   States:    x
2947 //   Return:    Error number in standard form (0 on success).
2948 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2949 //              * State information as per parent.
2950 //
2952 Int
2953 PAF_AST_decodeCont(
2954     const PAF_ASIT_Params *pP, 
2955     const PAF_ASIT_Patchs *pQ, 
2956     PAF_ASIT_Config *pAsitCfg, 
2957     ALG_Handle decAlg[], 
2958     Int frame, 
2959     Int block
2962     PAF_AST_Config *pAstCfg;
2963     Int as;                     /* Audio Stream Number (1, 2, etc.) */
2964     Int z;                      /* decode counter */
2965     Int zI, zS;
2966     Int zMD;
2967     Int8 tempVar8;
2969     
2970     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2971     as = pAstCfg->as;
2972     zMD = pAstCfg->masterDec;
2973     (void)as;  // clear compiler warning in case not used with tracing disabled
2974     
2975     // Await slave inputs
2976     for (z=DECODE1; z < DECODEN; z++)
2977     {
2978         zI = pP->inputsFromDecodes[z];
2979         zS = pP->streamsFromDecodes[z];
2980         (void)zS;
2981         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2982                                      GATEMP_INDEX_DEC);
2983         if (z == zMD
2984             || ! pAstCfg->xInp[zI].hRxSio
2985             || ! tempVar8)
2986             continue;
2987         TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2988         if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2989             != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2990             return (ASPERR_RECLAIM);
2991     }
2993     return 0;
2994 } //PAF_AST_decodeCont
2995 #endif
2997 // -----------------------------------------------------------------------------
2998 // ASIT Decoding Function - Decode Processing
2999 //
3000 //   Name:      PAF_ASIT_decodeDecode
3001 //   Purpose:   Decoding Function for processing of input data by the
3002 //              Decode Algorithm.
3003 //   From:      AST Parameter Function -> decodeProcessing
3004 //   Uses:      See code.
3005 //   States:    x
3006 //   Return:    Error number in standard form (0 on success).
3007 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
3008 //              * State information as per parent.
3009 //
3010 Int
3011 PAF_ASIT_decodeDecode(
3012     const PAF_ASIT_Params *pP, 
3013     const PAF_ASIT_Patchs *pQ, 
3014     PAF_ASIT_Config *pAsitCfg, 
3015     Int sourceSelect, 
3016     Int frame, 
3017     Int block
3020     PAF_AST_Config *pAstCfg;
3021     Int as;                     /* Audio Stream Number (1, 2, etc.) */
3022     Int z;                      /* decode/stream counter */
3023     Int errno;                  /* error number */
3024     //Int ch;
3025     Int argIdx;
3026     Int cbErrno;
3027     Int frameLength;    
3028     char decMsgBuf[ASP_MSG_BUF_LEN];
3030     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3031     as = pAstCfg->as;
3032     (void)as; // clear compiler warning in case not used with tracing disabled
3034 #if 0 // FL: slave
3035     // Clear samsiz for all channels - MID 208.
3036     for (z=STREAM1; z < STREAMN; z++) 
3037     {
3038         for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
3039         {
3040             pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
3041         }
3042     }
3043 #endif    
3045     // Decode data
3046     for (z=DECODE1; z < DECODEN; z++) 
3047     {
3048         Int zI = pP->inputsFromDecodes[z];
3049         Int zS = pP->streamsFromDecodes[z];
3050         (void)zS; // clear compiler warning in case not used with tracing disabled
3051         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3052         {
3053             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
3055             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
3056                     as+zS,
3057                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
3058                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
3060             // FL: debug, capture input buffer
3061             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
3062             
3063             // (***) FL: revisit
3064             // write back Dec configuration
3065             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3066             Cache_wait();                        
3068             // FL: send decode message to slave
3069             argIdx = 0; // set decIdx
3070             *(Int32 *)&decMsgBuf[argIdx] = z;
3071             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE, 
3072                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
3073             {
3074                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
3075                 SW_BREAKPOINT; // temporary
3076                 return -1;     // temporary
3077             }
3078             else 
3079             {
3080                 argIdx = 0; // get decErrno
3081                 errno = *(Int32 *)&decMsgBuf[argIdx];
3082                 argIdx += sizeof(Int32); // get cbErrno
3083                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
3084                 if (cbErrno != 0)
3085                 {
3086                     gCbWrtAfErrCnt++;
3087                     TRACE_TERSE1("CB write error=%d", cbErrno);
3088                     //SW_BREAKPOINT; // temporary
3089                 }
3090             }           
3092             // (***) FL: revisit
3093             // invalidate Dec configuration
3094             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3095             Cache_wait();
3097 #if 0 // FL: decoder decode call, slave
3098             if (dec->fxns->decode
3099                 && (errno = dec->fxns->decode (dec, NULL,
3100                                                &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct))) 
3101 #endif
3102             if (errno)
3103             {
3104                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3105                 return errno;
3106             }
3108 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3109             as_traceChannels(pC, z);
3110 #endif
3112 #if 0 // FL: change handle to decIdx (zone index)  
3113             frameLength = pP->fxns->computeFrameLength(decAlg[z],
3114                 FRAMELENGTH, 
3115                 pC->xDec[z].decodeStatus.bufferRatio);
3116 #endif
3117 #if 0 // (***) FL: revisit. Bypass decoder computeFrameLength() function.
3118             frameLength = pP->fxns->computeFrameLength(z, 
3119                 FRAMELENGTH, 
3120                 pC->xDec[z].decodeStatus.bufferRatio);
3121 #else
3122             // Compute decoder frame length based on source selection
3123             frameLength = getFrameLengthSourceSel(pP, sourceSelect);
3124 #endif
3127 //#ifdef PROFILER
3128 //            // modify for different decoders
3129 //            if (sourceSelect == PAF_SOURCE_THD)
3130 //            {
3131 //                start_profiling = 1;
3132 //            }
3133 //            else
3134 //            {
3135 //                start_profiling = 0;
3136 //            }
3137 //#endif
3140 // ............................................................................
3142             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3143             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3144             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3145                 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3146             {
3147                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3148                 return errno;
3149             }
3150                 
3151             TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3152             if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3153                 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3154                 PAF_SIO_REQUEST_NEWFRAME))
3155             {
3156                 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3157                 return (ASPERR_ISSUE);
3158             }
3159         } // hRxSio && decodeStatus.mode
3160         else
3161         {
3162             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3163         }
3164     } // z=DECODE1 to DECODEN
3166 #if 0 // FL: ASDT (slave)
3167     // Set up audio frames not decoded into
3168     //    Re-initialize audio frame if there is an assocatiated decode and
3169     //    that decode doesn't have a valid input or is turned off
3170     for (z=STREAM1; z < STREAMN; z++) 
3171     {
3172         Int zX;
3173         Int reset = 0;
3174         for (zX = DECODE1; zX < DECODEN; zX++) 
3175         {
3176             if (pP->streamsFromDecodes[zX] == z) 
3177             {
3178                 Int zI = pP->inputsFromDecodes[zX];
3179                 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3180                     reset = 1;
3181             }
3182         }
3183         if (reset) 
3184         {
3185             TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3186             pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3187         }
3188         else
3189             TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3190     }
3191 #endif
3192     
3193     return 0;
3194 } //PAF_ASIT_decodeDecode
3196 // -----------------------------------------------------------------------------
3197 // ASIT Decoding Function - Frame-Final Processing
3198 //
3199 //   Name:      PAF_ASIT_decodeFinalTest
3200 //   Purpose:   Decoding Function for determining whether processing of the
3201 //              current frame is complete.
3202 //   From:      AST Parameter Function -> decodeProcessing
3203 //   Uses:      See code.
3204 //   States:    x
3205 //   Return:    0 if incomplete, and 1 if complete.
3206 //   Trace:     None.
3207 //
3209 Int
3210 PAF_ASIT_decodeFinalTest(
3211     const PAF_ASIT_Params *pP, 
3212     const PAF_ASIT_Patchs *pQ, 
3213     PAF_ASIT_Config *pAsitCfg, 
3214     Int frame, 
3215     Int block
3218     PAF_AST_Config *pAstCfg;
3219     Int zMD;
3220     Int sourceSelect;
3221     Int sourceProgram;
3222     Int8 tempVar8, temp2Var8;
3224     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3225     zMD = pAstCfg->masterDec;
3227     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3228                                            GATEMP_INDEX_DEC);
3229     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3230                                            GATEMP_INDEX_DEC);
3232     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3233     {
3234         return 1;
3235     }
3237     // The following allows for Force modes to switch without command deferral. This might
3238     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3239     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM)) 
3240     {
3241         if (sourceSelect == PAF_SOURCE_DTSALL)
3242         {
3243             if (sourceProgram != PAF_SOURCE_DTS11 &&
3244                 sourceProgram != PAF_SOURCE_DTS12 &&
3245                 sourceProgram != PAF_SOURCE_DTS13 &&
3246                 sourceProgram != PAF_SOURCE_DTS14 &&
3247                 sourceProgram != PAF_SOURCE_DTS16 &&
3248                 sourceProgram != PAF_SOURCE_DTSHD)
3249             {
3250                 return 1;
3251             }
3252         }
3253         else if (sourceSelect == PAF_SOURCE_PCMAUTO) 
3254         {
3255             if (sourceProgram != PAF_SOURCE_PCM)
3256             {
3257                 return 1;
3258             }
3259         }
3260         else 
3261         {
3262             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3263                                           GATEMP_INDEX_DEC);
3264             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3265                                           GATEMP_INDEX_DEC);
3266             if (temp2Var8 != tempVar8)
3267             {
3268                 return 1;
3269             }
3270         }
3271     }
3273     return 0;
3274 } //PAF_ASIT_decodeFinalTest
3276 // -----------------------------------------------------------------------------
3277 // ASIT Decoding Function - Stream-Final Processing
3278 //
3279 //   Name:      PAF_ASIT_decodeComplete
3280 //   Purpose:   Decoding Function for terminating the decoding process.
3281 //   From:      AST Parameter Function -> decodeProcessing
3282 //   Uses:      See code.
3283 //   States:    x
3284 //   Return:    0.
3285 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
3286 //              * State information as per parent.
3287 //
3288 Int
3289 PAF_ASIT_decodeComplete(
3290     const PAF_ASIT_Params *pP, 
3291     const PAF_ASIT_Patchs *pQ, 
3292     PAF_ASIT_Config *pAsitCfg, 
3293     ALG_Handle decAlg[], 
3294     Int frame, 
3295     Int block
3298     PAF_AST_Config *pAstCfg;
3299     Int as;                     /* Audio Stream Number (1, 2, etc.) */
3300     Int z;                      /* decode/encode counter */
3301     Int argIdx;
3302     Int errno;                  /* error number */
3303     Int8 tempVar8;
3304     char decMsgBuf[ASP_MSG_BUF_LEN];
3305     
3306     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3307     as = pAstCfg->as;
3308     (void)as;  // clear compiler warning in case not used with tracing disabled
3310 #ifdef PAF_ASP_FINAL
3311     /* This material is currently not utilized */
3312 #endif /* PAF_ASP_FINAL */
3313     for (z=DECODE1; z < DECODEN; z++) 
3314     {
3315 #ifdef PAF_ASP_FINAL
3316         DEC_Handle dec = (DEC_Handle )decAlg[z];
3317 #endif /* PAF_ASP_FINAL */
3318         Int zI = pP->inputsFromDecodes[z];
3319         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3320                                      GATEMP_INDEX_DEC);
3321         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3322         {
3323             TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3324 #ifdef PAF_ASP_FINAL
3325             if (dec->fxns->final)
3326                 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3327                                  &pAstCfg->xDec[z].decodeStatus);
3328 #endif /* PAF_ASP_FINAL */
3330             // FL: send dec deactivate message to slave
3331             argIdx = 0; // set decIdx
3332             *(Int32 *)&decMsgBuf[argIdx] = z;
3333             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
3334                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
3335             {
3336                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
3337                 SW_BREAKPOINT;
3338                 return -1;
3339             }
3341 #if 0 // FL: decoder deactivate call, slave
3342             if (decAlg[z]->fxns->algDeactivate)
3343                 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3344 #endif    
3345         }
3346         else 
3347         {
3348             TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3349         }
3350     }
3351     return 0;
3352 } //PAF_ASIT_decodeComplete
3354 // -----------------------------------------------------------------------------
3355 // ASIT Selection Function - Input Device Selection
3356 //
3357 //   Name:      PAF_ASIT_selectDevices
3358 //   Purpose:   Audio Stream Input Task Function for selecting the devices used
3359 //              for input.
3360 //   From:      audioStream1Task or equivalent
3361 //   Uses:      See code.
3362 //   States:    x
3363 //   Return:    Error number in standard form (0 on success).
3364 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
3365 //              * State information as per parent.
3366 //
3367 Int
3368 PAF_ASIT_selectDevices(
3369     const PAF_ASIT_Params *pP, 
3370     const PAF_ASIT_Patchs *pQ, 
3371     PAF_ASIT_Config *pAsitCfg
3374     PAF_AST_Config *pAstCfg;
3375     Int as;                     /* Audio Stream Number (1, 2, etc.) */
3376     Int z;                      /* input/output counter */
3377     Int errno = 0;              /* error number */
3378     Int errme;                  /* error number, local */
3379     Int device;
3380     Int zMD;
3382     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3383     as = pAstCfg->as;
3384     zMD = pAstCfg->masterDec;
3385     (void)as;  // clear compiler warning in case not used with tracing disabled
3386     
3387     // Select input devices
3388     for (z=INPUT1; z < INPUTN; z++) 
3389     {
3390         if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0) 
3391         {
3392             TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3394             // check for valid index into device array
3395             if (device >= pQ->devinp->n)
3396             {
3397                 device = 0; /* treat as device None */
3398             }
3400             errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3401                 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3403             if (errme)
3404             {
3405                 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3406                 if (!errno)
3407                 {
3408                     errno = ASPERR_DEVINP + errme;
3409                 }
3410                 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3411             }
3412             else 
3413             {
3414                 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3415                 // register decodeStatus pointer with input devices
3416                 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3417                 // Use zMIs decodeStatus for all inputs
3418                 if (pAstCfg->xInp[z].hRxSio) 
3419                 {
3420                     // register PAF_SIO_IALG object address
3421                     SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR, 
3422                         (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3423                     SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR, 
3424                         (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3425                 }
3426             }
3427         }
3428     }
3430     return errno;
3431 } //PAF_ASIT_selectDevices
3433 // -----------------------------------------------------------------------------
3434 // ASIT Selection Function - Source Selection
3435 //
3436 //   Name:      PAF_ASIT_sourceDecode
3437 //   Purpose:   Audio Input Stream Task Function for selecting the sources used
3438 //              for decoding of input to output.
3439 //   From:      audioStream1Task or equivalent
3440 //   Uses:      See code.
3441 //   States:    x
3442 //   Return:    0.
3443 //   Trace:     None.
3444 //
3445 Int
3446 PAF_ASIT_sourceDecode(
3447     const PAF_ASIT_Params *pP, 
3448     const PAF_ASIT_Patchs *pQ, 
3449     PAF_ASIT_Config *pAsitCfg, 
3450     Int x
3453     PAF_AST_Config *pAstCfg;
3454     Int z;                              /* decode counter */
3455     Int8 tempVar8;
3457     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3459     for (z=DECODE1; z < DECODEN; z++)
3460     {
3461         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3462                                      GATEMP_INDEX_DEC);
3463         if (tempVar8)
3464         {
3465             tempVar8 = x;
3466             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3467                                tempVar8, GATEMP_INDEX_DEC);
3468         }
3469     }
3470     
3471     return 0;
3472 } //PAF_ASIT_sourceDecode
3474 // -----------------------------------------------------------------------------
3476 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3477 Int
3478 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3480     Int errno = 0;
3481     Int zMD = pC->masterDec;
3482     Int zI = pP->inputsFromDecodes[z];
3484     // only handle real errors, on primary input, for writeDECModeContinuous
3485     if ( !( error &&
3486             z == zMD ))
3487         return error;
3489     TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3490     TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3492     if (pC->xInp[zI].hRxSio) {
3493         DEC_Handle dec;
3495         if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3496             return errno;
3498         // indicates (primary) input not running
3499         pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3501         pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3503         // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3504         pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3506         if (decAlg[z]->fxns->algDeactivate)
3507             decAlg[z]->fxns->algDeactivate (decAlg[z]);
3509         decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3510         dec = (DEC_Handle )decAlg[z];
3512         TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3513                     pC->as+z));
3515         if (decAlg[z]->fxns->algActivate)
3516             decAlg[z]->fxns->algActivate (decAlg[z]);
3518         if (dec->fxns->reset
3519             && (errno = dec->fxns->reset (dec, NULL,
3520                                           &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3521             return errno;
3522     }
3524     return errno;
3525 } //PAF_AST_decodeHandleErrorInput
3526 #endif
3528 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3530 //------------------------------------------------------------------------------
3531 static int sSkipCount = 0;
3532 int gReportBuffers = 0;
3533 void as_traceChannels(PAF_AST_Config *pC, int z)
3535     PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3536     int i;
3537          
3538 // #ifdef THIS_IS_DSPA
3539     sSkipCount++;
3540     if (sSkipCount<1)
3541         return;
3542     sSkipCount = 0;
3543 // #endif
3545 #ifdef THIS_IS_DSPB
3546     if (!gReportBuffers)
3547         return;
3548     gReportBuffers = 0;
3549 #endif
3551     dp(NULL, "\n");
3552     for (i=0; i<PAF_MAXNUMCHAN; i++)
3553     {
3554         if (pAudioFrame->data.sample[i] != 0)
3555         {
3556             float *wp = (float*)pAudioFrame->data.sample[i];
3557                dp(NULL, "i: %d.  p: 0x%x.  %f, %f, %f, %f\n",
3558                        i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3559         }
3560     }
3562 #endif
3564 // Compute decoder frame length based on selected source
3565 static Int getFrameLengthSourceSel(
3566     const PAF_ASIT_Params *pP, 
3567     Int8 sourceSelect
3570     Int frameLength;
3571     
3572     switch(sourceSelect)
3573     {
3574         case PAF_SOURCE_PCM:
3575             frameLength = FRAMELENGTH;
3576             break;
3577         case PAF_SOURCE_AC3: 
3578         case PAF_SOURCE_DDP: 
3579             frameLength = ASIP_FRAMELEN_SS_DDP_AC3;
3580             break;
3581         case PAF_SOURCE_THD:
3582             frameLength = ASIP_FRAMELEN_SS_THD;
3583             break;
3584         default:
3585             frameLength = ASIP_FRAMELEN_SS_DEFAULT;
3586             break;
3587     }
3588     
3589     return frameLength;