]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamOutProc.c
PASDK-568: added error check after calling encoder wrapper.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
index 34e9d73e006461ea60aa396798d1b54a7f93d347..a800d2d7cc7e155337b4d5c957de1382d34fea56 100644 (file)
@@ -46,6 +46,7 @@ All rights reserved.
 #include "audioStreamOutInit.h"
 #include "audioStreamOutDec.h"
 #include "audioStreamOutIo.h"
+#include "common.h"
 
 //#include "pfp/pfp.h"
 //#include "pfp_app.h"        /* contains all PFP ID's */
@@ -242,6 +243,14 @@ static Int PAF_ASOT_initSyncResync(
     Int frame
 );
 
+static Int asopDecOutProcEncodeWrap(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg,
+    Int frame,
+    Int zO
+);
+
 // ASOT SM function
 //   Purpose:   Re-select devices used for Output.
 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.
@@ -270,8 +279,8 @@ PAF_ASOT_Config gPAF_ASOT_config = {
     &gPAF_AST_config    // pAstCfg
 };
 
-/* ASOT event handle - to put in structure */
-Event_Handle asotEvt;
+// ASOT event handle - to put in structure
+Event_Handle gAsotEvtHandle;
 
 extern Int d10Initialized;
 
@@ -367,11 +376,11 @@ Void taskAsopFxn(
         //  Evt_Id_AsotTxMcaspEdma  : Tx McASP EDMA completion
         if (procEvents == TRUE)
         {
-            events = Event_pend(asotEvt, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
+            events = Event_pend(gAsotEvtHandle, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
         }
 
         asopLoopCount++;
-        TRACE_GEN1("TaskAsop (begin Main loop %d)", asopLoopCount);
+        //TRACE_GEN1("TaskAsop (begin Main loop %d)", asopLoopCount);
 
         switch (pAsotCfg->state)
         {
@@ -778,7 +787,7 @@ Void taskAsopFxn(
             gCommandOutputTask_ACK = 1;
             while (gCommandOutputTask_SYNC) 
             {
-                Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
+                Event_pend(gAsotEvtHandle, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
             }
             TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Re-start the process");
             pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // init state -- start over
@@ -806,7 +815,7 @@ Void taskAsopFxn(
 // ASOT wake timer (clock) function
 Void clkAsotFxn(Void)
 {
-    Event_post(asotEvt, Evt_Id_AsotWakeTimer);
+    Event_post(gAsotEvtHandle, Evt_Id_AsotWakeTimer);
 }
 
 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
@@ -814,7 +823,7 @@ void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
     /* post semaphore */
     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
         //Semaphore_post(asopSemTx);
-        Event_post(asotEvt, Evt_Id_AsotTxMcaspEdma);
+        Event_post(gAsotEvtHandle, Evt_Id_AsotTxMcaspEdma);
     } else {
         ;    // intermediate packet due to buffer wrapping around
     }
@@ -921,7 +930,7 @@ static Int PAF_ASOT_selectDevices(
     if ((ioPhyInit == TRUE) && (device >= 0))
     {
         // check for valid index into device array
-        if (device >= pQ->devout->n)
+        if (device >= pQ->devout->n)    // DEVOUT_N
         {
             device = 0; // treat as device None
         }
@@ -930,9 +939,9 @@ static Int PAF_ASOT_selectDevices(
         {
             // Select Output Devices
             //  FL, New IO: Placeholder function, this will be reorganized moving forward.
-            //  FL: New IO: API for single Output.
-            //  FL: New IO: Doesn't (re-)configure Output driver.
-            status = asopSelectDevices(&pAsotCfg->pIoOut[zO]);
+            //  FL, New IO: API for single Output.
+            //  FL, New IO: Doesn't (re-)configure Output driver.
+            status = asopSelectDevices(pQ->devout->x[device]->sio.pConfig, &pAsotCfg->pIoOut[zO]);
             if (status < 0)
             {
                 pAstCfg->xOut[zO].outBufStatus.sioSelect = 0x80;
@@ -1142,7 +1151,9 @@ static Int PAF_ASOT_initSyncDecInfo1(
             // THD sets this to 256 (hard-coded in Dec Info)
             // DDP sets this to 0 (audio frame pass through, 0 from ASDT AF frame length)
             // PCM sets this to 256 (decodeControl.frameLength)
-        pDecInfo1Af->sampleCount = gOutFrameLen;    // !!!! GJ: Revisit !!!!
+        //pDecInfo1Af->sampleCount = pAsotCfg->pAstCfg->xDecOpCb[zMS].strFrameLen; // gOutFrameLen;    // !!!! GJ: Revisit !!!!
+        pDecInfo1Af->sampleCount = 512; // debugging for 96kHz
+        //pDecInfo1Af->sampleCount = 1024; // debugging for 192kHz
         
         // Update Stream Audio Frame.
         // Copy Dec Reset AF to Stream AF.
@@ -1153,6 +1164,7 @@ static Int PAF_ASOT_initSyncDecInfo1(
         //      - Enc Info,
         //      - Start Output
         status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
+
         if (status < 0)
         {
             return status;
@@ -1223,6 +1235,7 @@ static Int PAF_ASOT_initSyncDecDecode1(
 
         // I/O physical layer prime operation required by McASP LLD
         asopIoPhyPrime(&pAsotCfg->pIoOut[zO]);        
+        TRACE_VERBOSE0("PAF_ASOT_initSyncDecDecode1: ASOP McASP LLD primed.");
         
         return ASOP_SOK;
     }
@@ -1321,11 +1334,18 @@ static Int PAF_ASOT_procDecOut(
 
     if (status == ASOP_SOK)
     {
-        // Update Output buffer configuration
-        asopUpdateOutBufConfig(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
-        
-        // Execute encode
-        errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
+        size_t totalOutputSize;
+
+        // Calculate the total size that encoder will write to output buffer
+        totalOutputSize = pAstCfg->xEnc[zO].encodeInStruct.pAudioFrame->sampleCount
+                          * pAstCfg->xOut[zO].outBufConfig.stride
+                          * pAstCfg->xOut[zO].outBufConfig.sizeofElement;
+
+        // Get output buffer pointers for encoder to write. Pointers are stored in pAsotCfg->pIoOut[zO]
+        asopGetOutBufPtrs(&pAsotCfg->pIoOut[zO], totalOutputSize);
+
+        // Invoke the encoder
+        errno = asopDecOutProcEncodeWrap(pP, pQ, pAsotCfg, frame, zO);
         if (errno < 0)
         {
             status = errno;
@@ -1367,6 +1387,95 @@ static Int PAF_ASOT_procDecOut(
     return status;
 }
 
+static Int asopDecOutProcEncodeWrap(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg,
+    Int frame,
+    Int zO
+)
+{
+    PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
+    Int errno;                  // error number
+    Int status;                 // status code
+    PAF_OutBufConfig *pOutBufCfg;
+    PAF_AudioFrame * pAf;
+
+    status = ASOP_SOK;
+    pAstCfg = pAsotCfg->pAstCfg;
+    pOutBufCfg = &(pAstCfg->xOut[zO].outBufConfig);
+    pAf = pAstCfg->xEnc[zO].encodeInStruct.pAudioFrame;
+
+    if(pAsotCfg->pIoOut[zO].buff2 == NULL)
+    {
+        // Output buffer won't wrap around - to invoke the encoder once
+        pOutBufCfg->lengthofFrame = pAf->sampleCount;
+        pOutBufCfg->pntr.pLgInt   = pAsotCfg->pIoOut[zO].buff1;
+
+        // Execute encode
+        errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
+        if (errno < 0)
+        {
+            status = errno;
+        }
+    }
+    else
+    {
+        // Output buffer will wrap around - to invoke the encoder twice
+        XDAS_Int16 sampleCountSave;
+        PAF_AudioData *afDataAddrSave[16];
+        PAF_AudioData **afDataAddr;
+        int i, ch;
+
+        sampleCountSave = pAf->sampleCount;  // save sample count for restoring later
+
+        // Invoke the encoder to write data to the end of output buffer
+        pOutBufCfg->lengthofFrame = pAsotCfg->pIoOut[zO].size1 / (pOutBufCfg->stride * pOutBufCfg->sizeofElement);
+        pAf->sampleCount = pOutBufCfg->lengthofFrame;
+        pOutBufCfg->pntr.pLgInt   = pAsotCfg->pIoOut[zO].buff1;
+
+        // Execute encode
+        errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
+        if (errno < 0)
+        {
+            status = errno;
+        }
+
+        // Adjust audio frame buffer addresses for second invoking of the encoder
+        afDataAddr = pAf->data.sample;
+        for(i=0; i<pOutBufCfg->stride; i++)
+        {
+            ch = pAstCfg->xEnc[zO].encodeStatus.channelMap.from[i];
+            afDataAddrSave[i] = afDataAddr[ch];   // save audio frame buffer addresses
+            afDataAddr[ch] = &afDataAddr[ch][pOutBufCfg->lengthofFrame];
+        }
+
+        // Invoke the encoder to write data to the beginning of output buffer (wrapping around)
+        pOutBufCfg->lengthofFrame = pAsotCfg->pIoOut[zO].size2 / (pOutBufCfg->stride * pOutBufCfg->sizeofElement);
+        pAf->sampleCount = pOutBufCfg->lengthofFrame;
+        pOutBufCfg->pntr.pLgInt   = pAsotCfg->pIoOut[zO].buff2;
+
+        // Execute encode
+        errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
+        if (errno < 0)
+        {
+            status = errno;
+        }
+
+        // Restore sample count and audio frame buffer addresses
+        pAf->sampleCount = sampleCountSave;
+        for(i=0; i<pOutBufCfg->stride; i++)
+        {
+            ch = pAstCfg->xEnc[zO].encodeStatus.channelMap.from[i];
+            afDataAddr[ch] = afDataAddrSave[i];
+        }
+
+        pAsotCfg->pIoOut[zO].ioBuffBuf2AllocCnt++; // debug
+    }
+
+    return status;
+}
+
 // ASOT SM function
 //   Purpose:   Init-Sync Re-Sync state function.
 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.