DvevmStRetCode dvtb_sphEnc1Encode(DvevmStSphEnc1Info *se, int *encDuration) { XDAS_Int32 status = -1; XDM1_SingleBufDesc inBufDesc, outBufDesc; DvevmStRetCode retCode = DVEVM_ST_SUCCESS; ASSERT(se != NULL); ASSERT(se->ceHdl != NULL); ASSERT(se->sencHdl != NULL); ASSERT(se->inBuf.start != NULL); ASSERT(se->outBuf.start != NULL); inBufDesc.buf = (XDAS_Int8 *) se->inBuf.start; inBufDesc.bufSize = se->inBuf.size; outBufDesc.buf = (XDAS_Int8 *) se->outBuf.start; outBufDesc.bufSize = se->outBuf.size; memset(&se->sencInArgs, 0, sizeof(se->sencInArgs)); memset(&se->sencOutArgs, 0, sizeof(se->sencOutArgs)); se->sencInArgs.size = sizeof(SPHENC1_InArgs); se->sencOutArgs.size = sizeof(SPHENC1_OutArgs); dvtb_timeReset(se->hTime); status = SPHENC1_process(se->sencHdl, &inBufDesc, &outBufDesc, &se->sencInArgs, &se->sencOutArgs); dvtb_timeDelta(se->hTime, encDuration); if (status != SPHENC1_EOK) { SYS_ERROR("Error (%d) in Speech Encoder Process\n", (int) status); retCode = DVEVM_ST_FAIL; } return retCode; }
/* * ======== encode_decode ======== */ static Void encode_decode(SPHENC1_Handle enc, SPHDEC1_Handle dec, FILE *in, FILE *out) { Int n; Int32 status; SPHDEC1_InArgs decInArgs; SPHDEC1_OutArgs decOutArgs; SPHDEC1_DynamicParams decDynParams; SPHDEC1_Status decStatus; SPHENC1_InArgs encInArgs; SPHENC1_OutArgs encOutArgs; SPHENC1_DynamicParams encDynParams; SPHENC1_Status encStatus; XDM1_SingleBufDesc inBufDesc; XDM1_SingleBufDesc encodedBufDesc; XDM1_SingleBufDesc outBufDesc; /* init buffer descriptor settings that don't change during processing */ inBufDesc.bufSize = IFRAMESIZE; inBufDesc.buf = inBuf; encodedBufDesc.buf = encodedBuf; outBufDesc.buf = outBuf; /* initialize all "sized" fields */ encInArgs.size = sizeof(encInArgs); decInArgs.size = sizeof(decInArgs); encOutArgs.size = sizeof(encOutArgs); decOutArgs.size = sizeof(decOutArgs); encDynParams.size = sizeof(encDynParams); decDynParams.size = sizeof(decDynParams); encStatus.size = sizeof(encStatus); decStatus.size = sizeof(decStatus); /* * We never use the decoder or encoder's inArgs.data fields, so * initialize them NULL. */ decInArgs.data.buf = NULL; encInArgs.data.buf = NULL; /* * Note that we use versionBuf in both the encoder and decoder. In this * application, this is okay, as there is always only one user of * the buffer. Not all applications can make this assumption. */ encStatus.data.buf = decStatus.data.buf = versionBuf; encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE; /* if the codecs support it, dump their versions */ status = SPHDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus); GT_1trace(curMask, GT_1CLASS, "Decoder version: %s\n", (status == SPHDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]")); status = SPHENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus); GT_1trace(curMask, GT_1CLASS, "Encoder version: %s\n", (status == SPHENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]")); /* * This app expects the encoder to provide 1 buf in and get 1 buf out, * and the buf sizes of the in and out buffer must be able to handle * NSAMPLES bytes of data. */ status = SPHENC1_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus); if (status != SPHENC1_EOK) { /* failure, report error and exit */ GT_1trace(curMask, GT_7CLASS, "encode control status = %ld\n", status); return; } /* Validate this encoder codec will meet our buffer requirements */ if ((IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) || (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ GT_0trace(curMask, GT_7CLASS, "Error: encoder codec feature conflict\n"); return; } status = SPHDEC1_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus); if (status != SPHDEC1_EOK) { /* failure, report error and exit */ GT_1trace(curMask, GT_7CLASS, "decode control status = %ld\n", status); return; } /* Validate this decoder codec will meet our buffer requirements */ if ((EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) || (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ GT_0trace(curMask, GT_7CLASS, "App-> ERROR: decoder does not meet buffer requirements.\n"); return; } /* * Read complete frames from in, encode, decode, and write to out. */ for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) { /* reset potentially changed 'output' buffers to actual buf sizes. */ encodedBufDesc.bufSize = EFRAMESIZE; outBufDesc.bufSize = OFRAMESIZE; #ifdef CACHE_ENABLED #ifdef xdc_target__isaCompatible_64P /* * fread() on this processor is implemented using CCS's stdio, which * is known to write into the cache, not physical memory. To meet * xDAIS DMA Rule 7, we must writeback the cache into physical * memory. Also, per DMA Rule 7, we must invalidate the buffer's * cache before providing it to any xDAIS algorithm. */ Memory_cacheWbInv(inBuf, IFRAMESIZE); #else #error Unvalidated config - add appropriate fread-related cache maintenance #endif /* Per DMA Rule 7, our output buffer cache lines must be cleaned */ Memory_cacheInv(encodedBuf, encodedBufDesc.bufSize); #endif GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n); /* encode the frame */ status = SPHENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs, &encOutArgs); GT_2trace(curMask, GT_2CLASS, "App-> Encoder frame %d process returned - 0x%x)\n", n, status); #ifdef CACHE_ENABLED /* Writeback this outBuf from the previous call. Also, as encodedBuf * is an inBuf to the next process call, we must invalidate it also, to * clean buffer lines. */ Memory_cacheWbInv(encodedBuf, encodedBufDesc.bufSize); /* Per DMA Rule 7, our output buffer cache lines must be cleaned */ Memory_cacheInv(outBuf, outBufDesc.bufSize); #endif if (status != SPHENC1_EOK) { GT_3trace(curMask, GT_7CLASS, "App-> Encoder frame %d processing FAILED, status = 0x%x, " "extendedError = 0x%x\n", n, status, encOutArgs.extendedError); break; } /* decode the frame */ status = SPHDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs, &decOutArgs); GT_2trace(curMask, GT_2CLASS, "App-> Decoder frame %d process returned - 0x%x)\n", n, status); if (status != SPHDEC1_EOK) { GT_3trace(curMask, GT_7CLASS, "App-> Decoder frame %d processing FAILED, status = 0x%x, " "extendedError = 0x%x\n", n, status, decOutArgs.extendedError); break; } #ifdef CACHE_ENABLED /* Writeback the outBuf. */ Memory_cacheWb(outBuf, outBufDesc.bufSize); #endif /* write to file */ fwrite(outBuf, outBufDesc.bufSize, 1, out); } GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n); }