📄 sphenc1_copy.c
字号:
/* * Copyright 2006 * Texas Instruments Incorporated * * All rights reserved. Property of Texas Instruments Incorporated * Restricted rights to use, duplicate or disclose this code are * granted through contract. * *//* * ======== sphenc1_copy.c ======== * Speech encoder "copy" algorithm, PCM codec family. * * This file contains an implementation of the IALG interface * required by xDAIS. */#include <xdc/std.h>#include <string.h>#include <ti/xdais/dm/isphenc1.h>#include <ti/xdais/dm/ispeech1_pcm.h>#include "sphenc1_copy_ti.h"#include "sphenc1_copy_ti_priv.h"/* buffer definitions */#define MININBUFS 1#define MINOUTBUFS 1#define MININBUFSIZE 1#define MINOUTBUFSIZE 1extern IALG_Fxns SPHENC1COPY_TI_IALG;#define IALGFXNS \ &SPHENC1COPY_TI_IALG, /* module ID */ \ NULL, /* activate */ \ SPHENC1COPY_TI_alloc, /* alloc */ \ NULL, /* control (NULL => no control ops) */ \ NULL, /* deactivate */ \ SPHENC1COPY_TI_free, /* free */ \ SPHENC1COPY_TI_initObj, /* init */ \ NULL, /* moved */ \ NULL /* numAlloc (NULL => IALG_MAXMEMRECS) *//* * ======== SPHENC1COPY_TI_ISPHENC ======== * This structure defines TI's implementation of the ISPHENC1 interface * for the SPHENC1COPY_TI module. */ISPHENC1_Fxns SPHENC1COPY_TI_SPHENCCOPY = { /* module_vendor_interface */ {IALGFXNS}, SPHENC1COPY_TI_process, SPHENC1COPY_TI_control,};/* * ======== SPHENC1COPY_TI_IALG ======== * This structure defines TI's implementation of the IALG interface * for the SPHENC1COPY_TI module. */#ifdef _TI_asm("_SPHENC1COPY_TI_IALG .set _SPHENC1COPY_TI_SPHENCCOPY");#else/* * We duplicate the structure here to allow this code to be compiled and * run non-DSP platforms at the expense of unnecessary data space * consumed by the definition below. */IALG_Fxns SPHENC1COPY_TI_IALG = { /* module_vendor_interface */ IALGFXNS};#endifISPHENC1_Params SPHENC1COPY_TI_PARAMS = { sizeof(ISPHENC1_Params), 0, /* frameSize isn't relevant for copy codecs */ ISPEECH1_PCM_COMPAND_DEFAULT, 0, /* packingType is a don't care for PCM */ 0, /* vadSelection is a don't care for PCM */ ISPEECH1_CODECSELECT_DEFAULT, NULL};/* * ======== SPHENC1COPY_TI_alloc ======== */Int SPHENC1COPY_TI_alloc(const IALG_Params *algParams, IALG_Fxns **pf, IALG_MemRec memTab[]){ /* Request memory for my object */ memTab[0].size = sizeof(SPHENC1COPY_TI_Obj); memTab[0].alignment = 0; memTab[0].space = IALG_EXTERNAL; memTab[0].attrs = IALG_PERSIST; return (1);}/* * ======== SPHENC1COPY_TI_free ======== */Int SPHENC1COPY_TI_free(IALG_Handle handle, IALG_MemRec memTab[]){ SPHENC1COPY_TI_alloc(NULL, NULL, memTab); return (1);}/* * ======== SPHENC1COPY_TI_initObj ======== */Int SPHENC1COPY_TI_initObj(IALG_Handle handle, const IALG_MemRec memTab[], IALG_Handle p, const IALG_Params *algParams){ SPHENC1COPY_TI_Obj *obj = (SPHENC1COPY_TI_Obj *)handle; const ISPHENC1_Params *params = (ISPHENC1_Params *)algParams; if (params == NULL) { params = &SPHENC1COPY_TI_PARAMS; } obj->frameSize = params->frameSize; obj->compandingLaw = params->compandingLaw; obj->packingType = params->packingType; obj->vadSelection = params->vadSelection; obj->codecSelection = params->codecSelection; obj->bitRate = 0; /* doesn't matter for PCM */ obj->mode = 0; /* doesn't matter for PCM */ obj->vadFlag = ISPEECH1_VADFLAG_DEFAULT; obj->noiseSuppressionMode = 0; /* doesn't matter for PCM */ obj->ttyTddMode = 0; /* doesn't matter for PCM */ obj->dtmfMode = 0; /* doesn't matter for PCM */ obj->dataTransmit = 0; /* doesn't matter for PCM */ return (IALG_EOK);}/* * ======== SPHENC1COPY_TI_process ======== */XDAS_Int32 SPHENC1COPY_TI_process(ISPHENC1_Handle h, XDM_SingleBufDesc *inSamples, XDM_SingleBufDesc *outCodeWords, ISPHENC1_InArgs *inArgs, ISPHENC1_OutArgs *outArgs){ int numBytes; /* * The number of bytes we can encode is the lesser of the specified * number of bytes to encode (inSamples->bufSize) and the size of the * buffer that will contain the output (outCodeWords->bufSize). */ numBytes = (inSamples->bufSize <= outCodeWords->bufSize) ? inSamples->bufSize : outCodeWords->bufSize; /* process the data: read input, produce output */ memcpy(outCodeWords->buf, inSamples->buf, numBytes); /* Fill out the rest of the outArgs struct */ outArgs->frameType = ISPHENC1_FTYPE_SPEECH; outArgs->extendedError = 0; return (ISPHENC1_EOK);}/* * ======== SPHENC1COPY_TI_control ======== */XDAS_Int32 SPHENC1COPY_TI_control(ISPHENC1_Handle handle, ISPHENC1_Cmd id, ISPHENC1_DynamicParams *params, ISPHENC1_Status *status){ XDAS_Int32 retVal; SPHENC1COPY_TI_Obj *obj = (SPHENC1COPY_TI_Obj *)handle; /* validate arguments - this codec only supports "base" xDM. */ if ((params->size != sizeof(*params)) || (status->size != sizeof(*status))) { return (ISPHENC1_EUNSUPPORTED); } switch (id) { case XDM_GETSTATUS: case XDM_GETBUFINFO: status->frameSize = obj->frameSize; status->extendedError = 0; status->bitRate = obj->bitRate; status->mode = obj->mode; status->vadFlag = obj->vadFlag; status->noiseSuppressionMode = obj->noiseSuppressionMode; status->ttyTddMode = obj->ttyTddMode; status->dataTransmit = obj->dataTransmit; status->compandingLaw = obj->compandingLaw; status->packingType = obj->packingType; status->vadSelection = obj->vadSelection; status->codecSelection = obj->codecSelection; status->bufInfo.minNumInBufs = MININBUFS; status->bufInfo.minNumOutBufs = MINOUTBUFS; status->bufInfo.minInBufSize[0] = MININBUFSIZE; status->bufInfo.minOutBufSize[0] = MINOUTBUFSIZE; retVal = ISPHENC1_EOK; break; case XDM_SETPARAMS: obj->frameSize = params->frameSize; obj->bitRate = params->bitRate; obj->mode = params->mode; obj->vadFlag = params->vadFlag; obj->noiseSuppressionMode = params->noiseSuppressionMode; obj->ttyTddMode = params->ttyTddMode; obj->dtmfMode = params->dtmfMode; obj->dataTransmit = params->dataTransmit; retVal = ISPHENC1_EOK; break; case XDM_SETDEFAULT: /* should validate these rather than blindly assign them! */ obj->frameSize = SPHENC1COPY_TI_PARAMS.frameSize; obj->compandingLaw = SPHENC1COPY_TI_PARAMS.compandingLaw; obj->packingType = SPHENC1COPY_TI_PARAMS.packingType; obj->vadSelection = SPHENC1COPY_TI_PARAMS.vadSelection; obj->codecSelection = SPHENC1COPY_TI_PARAMS.codecSelection; obj->bitRate = 0; /* doesn't matter for PCM */ obj->mode = 0; /* doesn't matter for PCM */ obj->vadFlag = ISPEECH1_VADFLAG_DEFAULT; obj->noiseSuppressionMode = 0; /* doesn't matter for PCM */ obj->ttyTddMode = 0; /* doesn't matter for PCM */ obj->dtmfMode = 0; /* doesn't matter for PCM */ obj->dataTransmit = 0; /* doesn't matter for PCM */ retVal = ISPHENC1_EOK; break; case XDM_RESET: case XDM_FLUSH: retVal = ISPHENC1_EOK; break; default: /* unsupported cmd */ retVal = ISPHENC1_EFAIL; break; } return (retVal);}/* * @(#) ti.xdais.dm.examples.sphenc1_copy; 1,0,0,11; 10-18-2006 19:12:19; /db/wtree/library/trees/dais-g07x/src/ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -