]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/as0.c
Add 1 16-bit word for EDMA padding for Input Driver
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / as0.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 //
37 // Framework support function (implementation)
38 //
41 #include <xdc/std.h> //<std.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Log.h>
44 #include <xdc/runtime/Memory.h>
45 #include <ti/sysbios/BIOS.h>
46 #include <ti/sysbios/heaps/HeapMem.h>
47 #include <ti/ipc/MessageQ.h>
48 #include <ti/ipc/MultiProc.h>
50 //#include <ti/procsdk_audio/procsdk_audio_typ.h>
51 #include <procsdk_audio_typ.h>
53 #include <sio.h>
55 #include "as0.h"
57 #include "inpbuf.h"
58 #include <pafdec.h>
59 #include <pafenc.h>
60 #include "outbuf.h"
62 #include <asperr.h> /* ASPERR_*OUT_* */
63 #include <pafsio.h>
64 //#include "pafhjt.h"
66 #include "common.h"
67 #include "paf_heapMgr.h"
68 #include "aspMsg_common.h"
69 #include "aspMsg_master.h"
70 #include "audioStreamProc_common.h"
72 #define PAF_DEVICE_VERSION (PAF_DEVICE & 0xffff)
73 #if PAF_DEVICE_VERSION == 0xE000
74 #define _DEBUG // This is to enable log_printfs
75 #endif /* PAF_DEVICE_VERSION */
76 #include <logp.h>
78 // allows you to set a different trace module in pa.cfg
79 #define TR_MOD  trace
81 // Allow a developer to selectively enable tracing.
82 // For release, set mask to 1 to make it easier to catch any errors.
83 #define CURRENT_TRACE_MASK  1   // terse only
85 #define TRACE_MASK_TERSE    1   // only flag errors
86 #define TRACE_MASK_GENERAL  2   // log a half dozen lines per loop
87 #define TRACE_MASK_VERBOSE  4   // trace full operation
89 #if (CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
90  #define TRACE_TERSE(a) LOG_printf a
91 #else
92  #define TRACE_TERSE(a)
93 #endif
95 #if (CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
96  #define TRACE_GEN(a) LOG_printf a
97 #else
98  #define TRACE_GEN(a)
99 #endif
101 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
102  #define TRACE_VERBOSE(a) LOG_printf a
103 #else
104  #define TRACE_VERBOSE(a)
105 #endif
107 //
108 // Audio Stream Task / Decode Processing - Device Allocation Function
109 //
110 //   Name:      PAF_DEC_deviceAllocate
111 //   Purpose:   Decode Function for "device allocation" to
112 //              (1) allocate buffer memory, and
113 //              (2) initialize a Buffer Configuration, including pointers
114 //                  to that buffer memory.
115 //   From:      AST Parameter Function -> deviceAllocate
116 //   Uses:      None.
117 //   States:    None.
118 //   Return:    0 on success.
119 //              1 on MEM_calloc failure.
120 //   Trace:     None.
121 //
123 Int
124 PAF_DEC_deviceAllocate(
125     SIO_Handle *pHandle,
126     int mode,
127     int heapID,
128     int bufSize,
129     Ptr pBufCfg )
131     Ptr pBuf;
132     Error_Block    eb;
134     *pHandle = NULL;
136     // Initialize error block
137     Error_init(&eb); 
139 //#ifdef _TMS320C6X
140 //#warn Changed back to MEM_calloc until Mantis ID 81 resolved -- mwatson
141 //#endif
142 //    if (! (pBuf = (Ptr )MEM_alloc (heapID, bufSize, 128)))
143     //if (! (pBuf = (Ptr )MEM_calloc (heapID, bufSize, 128)))
144     if (!(pBuf = (Ptr )Memory_calloc((IHeap_Handle)pafHeapMgr_readHeapHandle(heapID), bufSize, 128, &eb)))
145         return (SYS_EALLOC);        
147     if( mode ==     SIO_OUTPUT ) {
148         PAF_OutBufConfig *pConfig = (PAF_OutBufConfig *)pBufCfg;
150         pConfig->base.pVoid = pBuf;
151         pConfig->pntr.pVoid = pBuf;
152         pConfig->head.pVoid = pBuf;
153         pConfig->allocation = bufSize;
154         pConfig->precision = 24;
155     }
156     else {
157         PAF_InpBufConfig *pConfig = (PAF_InpBufConfig *)pBufCfg;
159         pConfig->base.pVoid = pBuf;
160         pConfig->pntr.pVoid = pBuf;
161         pConfig->head.pVoid = pBuf;
162         pConfig->allocation = bufSize;
163         pConfig->precision = 16;
164     }
166     return SYS_OK;
167 } /* PAF_DEC_deviceAllocate */
169 //
170 // Audio Stream Task / Decode Processing - Device Selection Function
171 //
172 //   Name:      PAF_DEC_deviceSelect
173 //   Purpose:   Decode Function for "device selection" which
174 //              (1) "closes" any open device on that handle, and
175 //              (2) "opens" a new device on that handle if not None.
176 //   From:      AST Parameter Function -> deviceSelect
177 //   Uses:      See code.
178 //   States:    None.
179 //   Return:    0 on success.
180 //              1 on error in device create.
181 //              2 on error in device open.
182 //              3 on error in device close.
183 //              4 on error in device idle.
184 //   Trace:     None.
185 //
187 Int
188 PAF_DEC_deviceSelect(
189     SIO_Handle *pHandle,
190     int mode,
191     int heapID,
192     Ptr pParams )
194     // Device must be idled, closed, and freed to select new:
195     if (*pHandle) {
196         if (SIO_idle (*pHandle))
197             return ASPERR_DEVINP_IDLE-ASPERR_DEVINP;
198         if (SIO_ctrl (*pHandle, PAF_SIO_CONTROL_CLOSE, 0))
199             return ASPERR_DEVINP_CLOSE-ASPERR_DEVINP;
200         PAF_SIO_free (*pHandle, mode );
201             /* For consistency, should return integer. --Kurt */
202     }
204     // Select new device:
205     if (! pParams) {
206         /* input/output device None */
207         *pHandle = NULL;
208     }
209     else if (! (*pHandle = PAF_SIO_recreate (pParams, mode, &trace, heapID)))
210         return ASPERR_DEVINP_CREATE-ASPERR_DEVINP;
211     else if (SIO_ctrl (*pHandle, PAF_SIO_CONTROL_OPEN, (Arg) pParams))
212                 return ASPERR_DEVINP_OPEN-ASPERR_DEVINP;
214     return 0;
215 } /* PAF_DEC_deviceSelect */
217 //
218 // Audio Stream Task / Decode Processing - Frame Length Computation Function
219 //
220 //   Name:      PAF_DEC_computeFrameLength
221 //   Purpose:   Compute frame length to be generated by a decode algorithm,
222 //              including effects of the "buffer ratio" which is used to
223 //              indicate possible subsequent up-sampling by 2 or 4 (-2 or
224 //              -4) or down-sampling by 2 or 4 (2 or 4).
225 //   From:      AST Parameter Function -> computeFrameLength
226 //   Uses:      See code.
227 //   States:    None.
228 //   Return:    Frame length.
229 //   Trace:     None.
230 //
232 #include <pcm.h>
233 #if 0 /* commenting IP component header file inclusion */
234 #include <ac3.h>
235 #include <dts.h>
236 #include <aac.h>
238 #define DEC_MINSAMGEN PCM_MINSAMGEN
240 #if DEC_MINSAMGEN != AC3_MINSAMGEN
241 #error internal error
242 #elif DEC_MINSAMGEN != DTS_MINSAMGEN
243 #error internal error
244 #elif DEC_MINSAMGEN != AAC_MINSAMGEN
245 #error internal error
246 #endif /* DEC_MINSAMGEN */
248 #define DEC_MAXSAMGEN PCM_MAXSAMGEN
250 #if DEC_MAXSAMGEN != AC3_MAXSAMGEN
251 #error internal error
252 #elif DEC_MAXSAMGEN != DTS_MAXSAMGEN
253 #error internal error
254 #elif defined (AAC_SUPPORT) && DEC_MAXSAMGEN != AAC_MAXSAMGEN
255 #error internal error
256 #endif /* DEC_MAXSAMGEN */
257 #else
258 #define DEC_MINSAMGEN PCM_MINSAMGEN
259 #define DEC_MAXSAMGEN PCM_MAXSAMGEN
260 #endif
262 // FL: change alg handle to decIdx, index is w.r.t. dec zones
263 //Int
264 //PAF_DEC_computeFrameLength(
265 //    ALG_Handle alg, 
266 //    Int frameLength, 
267 //    Int bufferRatio
268 //)
269 Int
270 PAF_DEC_computeFrameLength(
271     Int decIdx, 
272     Int frameLength, 
273     Int bufferRatio
276     Int m, n, o, p;
277     // Messaging
278     ASP_Msg *pAspMsg;
279     Int argIdx;
280     Int errno;                          /* error number */
281     Int status;
283     // FL: dec control message to slave
284     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
285     if (pAspMsg == NULL)
286     {
287         TRACE_TERSE0("MessageQ_alloc() failure.");
288         errno = -1; // temporary
289         return errno;
290     }
291     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
292     pAspMsg->cmd = ASP_SLAVE_DEC_CONTROL;                                              /* fill in message payload */
293     pAspMsg->procId = hAspMsgMaster->masterProcId;
294     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
295     pAspMsg->expectResp = TRUE;
296     argIdx = 0; //  set decIdx
297     *(Int *)&pAspMsg->buf[argIdx] = decIdx;
298     argIdx += sizeof(Int); // set decCtrlCmd
299     *(IALG_Cmd *)&pAspMsg->buf[argIdx] = DEC_MINSAMGEN;
300     TRACE_TERSE3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
301     TRACE_TERSE1("decIdx=%d", pAspMsg->buf[0]);
302     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
303     if (status != MessageQ_S_SUCCESS)
304     {
305         SW_BREAKPOINT;
306     }
307     // wait for dec control message from slave
308     status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
309     if (status != MessageQ_S_SUCCESS)
310     {
311         TRACE_TERSE0("decodeInit(): MessageQ_get() failure.");
312         SW_BREAKPOINT;
313         return -1; // temporary
314     }
315     if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) && 
316         (pAspMsg->cmd == ASP_MASTER_DEC_CONTROL_DONE) &&
317         (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
318     {
319         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
320         TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
321         
322         argIdx = 0; // get decCtrlRet
323         m = *(Int *)&pAspMsg->buf[argIdx];
324         TRACE_TERSE1("decCtrlRet (m)=%d", m);
325     }
326     else
327     {
328         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
329         SW_BREAKPOINT;
330     }
331     // free the message
332     status = MessageQ_free((MessageQ_Msg)pAspMsg);
333     if (status != MessageQ_S_SUCCESS)
334     {
335         SW_BREAKPOINT;
336     }
337     
338 #if 0 // FL: decoder control call, slave
339     m = alg->fxns->algControl(alg, DEC_MINSAMGEN, NULL);
340 #endif
341     
342     // FL: dec control message to slave
343     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
344     if (pAspMsg == NULL)
345     {
346         TRACE_TERSE0("MessageQ_alloc() failure.");
347         return -1; // temporary
348     }
349     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
350     pAspMsg->cmd = ASP_SLAVE_DEC_CONTROL;                                              /* fill in message payload */
351     pAspMsg->procId = hAspMsgMaster->masterProcId;
352     pAspMsg->expectResp = TRUE;
353     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
354     argIdx = 0; // set decIdx
355     *(Int *)&pAspMsg->buf[argIdx] = decIdx;
356     argIdx += sizeof(Int); // set decCtrlCmd
357     *(IALG_Cmd *)&pAspMsg->buf[argIdx] = DEC_MAXSAMGEN;
358     TRACE_TERSE3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
359     TRACE_TERSE1("decIdx=%d", pAspMsg->buf[0]);
360     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
361     if (status != MessageQ_S_SUCCESS)
362     {
363         SW_BREAKPOINT;
364     }
365     // wait for dec control message from slave
366     status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
367     if (status != MessageQ_S_SUCCESS)
368     {
369         TRACE_TERSE0("MessageQ_get() failure.");
370         SW_BREAKPOINT;
371         return -1; // temporary
372     }
373     if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) && 
374         (pAspMsg->cmd == ASP_MASTER_DEC_CONTROL_DONE) &&
375         (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
376     {
377         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
378         TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
380         argIdx = 0; // get decCtrlRet
381         n = *(Int *)&pAspMsg->buf[argIdx];
382         TRACE_TERSE1("decCtrlRet (n)=%d", n);
383     }
384     else
385     {
386         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
387         SW_BREAKPOINT;
388     }
389     // free the message
390     status = MessageQ_free((MessageQ_Msg)pAspMsg);            
391     if (status != MessageQ_S_SUCCESS)
392     {
393         SW_BREAKPOINT;
394     }
395     
396 #if 0 // FL: decoder control call, slave
397     n = alg->fxns->algControl(alg, DEC_MAXSAMGEN, NULL);
398 #endif
400     
401     if (m != n) {
402         o = n < frameLength ? n : frameLength;
403         o = o / m * m;
404         if (bufferRatio > 0) {
405             if (bufferRatio == 4 && (p = o / 4) > m && p % 8 == 0)
406                 return p;
407             else if (bufferRatio == 4 && (p = o / 2) > m && p % 8 == 0)
408                 return p;
409             else if (bufferRatio == 2 && (p = o / 2) > m && p % 8 == 0)
410                 return p;
411         }
412         else if (bufferRatio < 0) {
413             if (bufferRatio == -4 && (p = o * 4) > m && p % 8 == 0)
414                 return p;
415             else if (bufferRatio == -4 && (p = o * 2) > m && p % 8 == 0)
416                 return p;
417             else if (bufferRatio == -2 && (p = o * 2) > m && p % 8 == 0)
418                 return p;
419         }
420         if (o % 8 == 0)
421             return o;
422     }
424     return m;
425 } /* PAF_DEC_computeFrameLength */
427 //
428 // Audio Stream Task / Decode Processing - Input Status Update
429 //
430 //   Name:      PAF_DEC_updateInputStatus
431 //   Purpose:   Decode Function for maintaining Input Status.
432 //   From:      AST Parameter Function -> updateInputStatus
433 //   Uses:      See code.
434 //   States:    None.
435 //   Return:    0 on success.
436 //              Other on SIO Control failure (using SIO error numbers).
437 //   Trace:     None.
438 //
440 Int
441 PAF_DEC_updateInputStatus(
442     SIO_Handle hSio,
443     PAF_InpBufStatus *pStatus,
444     PAF_InpBufConfig *pConfig)
446     Int errno;
449     PAF_SIO_InputStatus inputStatus;
451     // initialize all values to unknown so that device specific
452     //   driver layer need only fill in those entries that it is aware of.
453     //   This allows extensibility of the structure without requiring users
454     //   to re-code.
455     inputStatus.lock = 0;
456     inputStatus.sampleRateData = PAF_SAMPLERATE_UNKNOWN;
457     inputStatus.sampleRateMeasured = PAF_SAMPLERATE_UNKNOWN;
458     inputStatus.nonaudio = PAF_IEC_AUDIOMODE_UNKNOWN;
459     inputStatus.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
461     errno = SIO_ctrl (hSio, (Uns)PAF_SIO_CONTROL_GET_INPUT_STATUS, (Arg) &inputStatus);
462     if (errno)
463         return errno;
464     pStatus->sampleRateData = inputStatus.sampleRateData;
465     pStatus->sampleRateMeasured = inputStatus.sampleRateMeasured;
466     pStatus->nonaudio = inputStatus.nonaudio;
467     pStatus->emphasisData = inputStatus.emphasis;
469     // if MSB of override clear then use as reported lock
470     // if = 0x80 then use default [0x81]
471     // if = 0x81 then use measured (from device)
472     // others not defined or implemented
473     if ((pStatus->lockOverride & (XDAS_Int8)0x80) == 0)
474         pStatus->lock = pStatus->lockOverride;
475     else if (pStatus->lockOverride == (XDAS_Int8)0x80)
476         pStatus->lock = inputStatus.lock;
477     else if (pStatus->lockOverride == (XDAS_Int8)0x81)
478         pStatus->lock = inputStatus.lock;
480     // if MSB of override clear then use it as sample rate for system,
481     // if = 0x80 then use default [0x82]
482     // if = 0x81 then use data
483     // if = 0x82 then use measured
484     // others not defined or implemented
485     if ((pStatus->sampleRateOverride & (XDAS_Int8)0x80) == 0)
486         pStatus->sampleRateStatus = pStatus->sampleRateOverride;
487     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x80)
488         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
489     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x81)
490         pStatus->sampleRateStatus = pStatus->sampleRateData;
491     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x82)
492         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
494     // Update emphasis status:
495     if ((pStatus->emphasisOverride & (XDAS_Int8)0x80) == 0) {
496         if (pStatus->emphasisData == PAF_IEC_PREEMPHASIS_YES)
497             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
498         else
499             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
500     }
501     else if (pStatus->emphasisOverride ==
502              (XDAS_Int8 )(0x80+PAF_IEC_PREEMPHASIS_YES))
503         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
504     else /* IBEmphasisOverrideNo or other */
505         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
507     // Update precision control
508     pConfig->precision = pStatus->precisionInput =
509         pStatus->precisionOverride < 0
510         ? pStatus->precisionDefault
511         : pStatus->precisionOverride > 0
512         ? pStatus->precisionOverride
513         : pStatus->precisionDetect > 0
514         ? pStatus->precisionDetect
515         : pStatus->precisionDefault;
517     return 0;
519 } /* PAF_DEC_updateInputStatus */
521 // ----------------------------------------------------------------------------
523 #ifndef HSE
525 // ............................................................................
527 //
528 // Audio Stream Task / Asynchronous Rate Conversion (ARC) - Control
529 //
530 //   Name:      PAF_ARC_controlRate
531 //   Purpose:   Control ARC conversion rate
532 //   From:      AST Parameter Function -> controlRate
533 //   Uses:      See code.
534 //   States:    None.
535 //   Return:    0 on success.
536 //              Other on SIO Control failure (using SIO error numbers).
537 //   Trace:     None.
538 //
540 #include <math.h>    /* ldexp() */
542 #include <acp.h>
544 #include <arc_a.h>
546 Int
547 PAF_ARC_controlRate(
548     SIO_Handle hRxSio,
549     SIO_Handle hTxSio,
550     ACP_Handle acp,
551     double arcRatio)  // KR032013
553     Int errno;
556     if (hRxSio && hTxSio) {
557         PAF_SIO_Stats *pRxStats, *pTxStats;
558       //extern double arcRatio;    // output / input rate  // KR032013
559         XDAS_UInt32 inputsPerOutputQ24 = (XDAS_UInt32) ldexp( arcRatio, 24);
561         static const ACP_Unit
562             readARCOutputsRemainingQ24_s[] = { readARCOutputsRemainingQ24 },
563             wroteARCInputsPerOutputQ24_s[] = { wroteARCInputsPerOutputQ24 };
565         ACP_Unit y4[4];
568         if (errno = SIO_ctrl (hRxSio, PAF_SIO_CONTROL_GET_STATS, (Arg) &pRxStats)) {
569             TRACE_TERSE ((&TR_MOD, "ARC: Error retrieving Rx xfer stats"
570                 " (0x%04x)", errno));
571             return errno;
572         }
574         if (errno = SIO_ctrl (hTxSio, PAF_SIO_CONTROL_GET_STATS, (Arg) &pTxStats)) {
575             TRACE_TERSE ((&TR_MOD, "ARC: Error retrieving Tx xfer stats"
576                 " (0x%04x)", errno));
577             return errno;
578         }
580         y4[0] = wroteARCInputsPerOutputQ24_s[0];
581         y4[1] = wroteARCInputsPerOutputQ24_s[1];
582         y4[2] = (MdInt) inputsPerOutputQ24;
583         y4[3] = (MdInt)(inputsPerOutputQ24 >> 16);
585         if (errno = acp->fxns->apply (acp, y4, NULL)) {
586             TRACE_TERSE ((&TR_MOD, "ARC: Error sending ARC rate ratio"
587                 " (0x%04x)", errno));
588             return errno;
589         }
591         if (errno = acp->fxns->apply (acp, readARCOutputsRemainingQ24_s, y4)) {
592             TRACE_TERSE ((&TR_MOD, "ARC: Error retrieving ARC timing"
593                 " (0x%04x)", errno));
594             return errno;
595         }
597         {
598         static XDAS_UInt32 outputsRemainingQ24[2];
600         const double arcDiff = pRxStats->dpll.v
601                             - (pTxStats->dpll.v + ldexp( outputsRemainingQ24[1], -24) * pTxStats->dpll.dv);
602         outputsRemainingQ24[1] = outputsRemainingQ24[0];
603         outputsRemainingQ24[0] = ((XDAS_UInt32) y4[3] << 16) + y4[2];
605         TRACE_GEN ((&TR_MOD, "time dif %d.%08d",
606             (int) arcDiff, (int) (1.e8 * (arcDiff - (int) arcDiff))));
608         }
609     }
611     return 0;
614 // ............................................................................
615 #else
616 Int
617 PAF_ARC_controlRate(
618     SIO_Handle hRxSio,
619     SIO_Handle hTxSio,
620     ACP_Handle acp,
621     double arcRatio) // KR032013
623     return 1;
625 #endif //HSE
627 // ----------------------------------------------------------------------------
629 //
630 // Audio Stream Task / Pass Processing - Buffer Copy
631 //
632 //   Name:      PAF_BUF_copy
633 //   Purpose:   Decode Function for copying the data in the input buffer
634 //              to the output buffer.
635 //   From:      AST Parameter Function -> copy
636 //   Uses:      None.
637 //   States:    None.
638 //   Return:    0 on success.
639 //              0x80000000 for errors in required arguments.
640 //   Trace:     None.
641 //
643 #define min(a, b)  (((a) < (b)) ? (a) : (b))
645 #include <pafdec.h>
646 #include <pafenc.h>
648 /* DO NOT REMOVE THIS CODE_SECTION. --Kurt */
649 #pragma CODE_SECTION(PAF_BUF_copy,".text:_PAF_BUF_copy")
651 Int
652 PAF_BUF_copy(
653     Uns inpChan,
654     PAF_InpBufConfig *pInpCfg,
655     Uns outChan,
656     PAF_OutBufConfig *pOutCfg)
658     Int i;
659     Int *pInBuf, *pOutBuf;
660     Int numSamples;
662 #ifndef __TI_EABI__
663     asm (" .clink");
664 #endif    
666     if( (pInpCfg == NULL) || (pOutCfg == NULL) )
667         return ASPERR_UNSPECIFIED;
669     if( (inpChan > pInpCfg->stride) || (outChan > pOutCfg->stride) )
670         return ASPERR_UNSPECIFIED;
672     //for now assume =32bit words
673     if( (pInpCfg->sizeofElement != 4) ||
674         (pInpCfg->sizeofElement != pOutCfg->sizeofElement) )
675         return ASPERR_UNSPECIFIED;
677     pInBuf = pInpCfg->pntr.pLgInt;
678     pOutBuf = pOutCfg->pntr.pLgInt;
680     numSamples = min(pInpCfg->frameLength, pOutCfg->lengthofFrame);
681     pInBuf += inpChan;
682     pOutBuf += outChan;
683     for( i=0; i < numSamples; i++ )
684     {
685         *pOutBuf = *pInBuf;
686         pInBuf += pInpCfg->stride;
687         pOutBuf += pOutCfg->stride;
688     }
690     return 0;
691 } /* PAF_BUF_copy */
693 // EOF