?? g711_sun_ialg.c
字號:
/* * Copyright 2006 by Texas Instruments Incorporated. * * All rights reserved. Property of Texas Instruments Incorporated. * Restricted rights to use, duplicate or disclose this code are * granted through contract. * *//* * ======== g711_sun_ialg.c ======== * Implementation of the G711ENC_SUN.h interface; SUN's implementation * of the IG711 interface. */#include <xdc/std.h>#include <ti/xdais/dm/isphenc.h>#include <assert.h>#include "g711enc_sun.h"#include "g711_sun_internal.h"#include "g711_sun_priv.h"extern IALG_Fxns G711ENC_SUN_IALG;/* * ======== G711ENC_SUN_Obj ======== */typedef struct G711ENC_SUN_Obj { IALG_Obj alg; /* MUST be first field of all xDAIS inst objs */ Int frameLen; /* frame length in samples. */ Int inbufferSize; /* Input Buffer size in bytes. */ Int bytesGenerated; /* Output buffer size in bytes. */ Int rate;} G711ENC_SUN_Obj;#define IALGFXNS \ &G711ENC_SUN_IALG, /* module ID */ \ NULL, /* activate */ \ G711ENC_SUN_alloc, /* algAlloc */ \ NULL, /* control (NULL => no control ops) */ \ NULL, /* deactivate */ \ G711ENC_SUN_free, /* free */ \ G711ENC_SUN_initObj, /* init */ \ NULL, /* moved */ \ NULL /* numAlloc *//* * ======== G711ENC_SUN_IG711ENC ======== * This structure defines SUN's implementation of the IG711 interface * for the G711ENC_SUN module. */ISPHENC_Fxns G711ENC_SUN_IG711ENC = { /* module_vendor_interface */ {IALGFXNS}, G711ENC_SUN_encodeLin2Alaw, G711ENC_SUN_control,};/* * ======== G711ENC_SUN_IALG ======== * This structure defines SUN's implementation of the IALG interface * for the G711ENC_SUN module. */#ifdef _TI_asm("_G711ENC_SUN_IALG .set _G711ENC_SUN_IG711ENC");#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 G711ENC_SUN_IALG = { /* module_vendor_interface */ IALGFXNS};#endif/* * ======== G711ENC_SUN_alloc ======== * Return a table of memory descriptors that describe the memory needed * to construct a G711ENC_SUN_Obj structure. */Int G711ENC_SUN_alloc(const IALG_Params *g711Params, IALG_Fxns **pf, IALG_MemRec memTab[]){ /* Request memory for G711 object */ memTab[0].size = sizeof(G711ENC_SUN_Obj); memTab[0].alignment = 0; memTab[0].space = IALG_EXTERNAL; memTab[0].attrs = IALG_PERSIST; return (1);}/* * ======== G711ENC_SUN_free ======== * Return a table of memory pointers that should be freed. Note * that this should include *all* memory requested in the * G711ENC_SUN_alloc operation above. */Int G711ENC_SUN_free(IALG_Handle handle, IALG_MemRec memTab[]){ Int n; n = G711ENC_SUN_alloc(NULL, NULL, memTab); return (n);}/* * ======== G711ENC_SUN_initObj ======== * Initialize the memory allocated on our behalf (including our object). */Int G711ENC_SUN_initObj(IALG_Handle handle, const IALG_MemRec memTab[], IALG_Handle p, const IALG_Params *g711Params){ G711ENC_SUN_Obj *g711Enc = (Void *)handle;/* const IG711ENC_Params *params = (IG711ENC_Params *)g711Params; *//* g711Enc->frameLen = params->sphenc_params.inbufferSize / sizeof(MdUns); */ g711Enc->bytesGenerated = 0; return (IALG_EOK);}/* * ======== Implementation of the ISPHENC Interface Fxns ======== * * G711ENC_SUN_encodeLin2Alaw - implements ISPHENC::process() function. * Args: * input buffer pointer output buffer pointers. * App sets pointers to NULL in case algorithm has to return * this address to application. * params: determines behaviour of basic encoding. * * * Retuns: status status structure. * IALG_EOK for success or IALG_EFAIL for failure. */XDAS_Int32 G711ENC_SUN_encodeLin2Alaw(ISPHENC_Handle handle, XDM_BufDesc *inBufs, XDM_BufDesc *outBufs, ISPHENC_InArgs *inArgs, ISPHENC_OutArgs *outArgs){ Int i; short *in = (short *)inBufs->bufs[0]; unsigned char *out = (unsigned char *)outBufs->bufs[0]; Int frameLen = inBufs->bufSizes[0] / sizeof(short); for (i = 0; i < frameLen; i++) { *out++ = G711_SUN_linear2alaw(*in++); } if (outArgs) { outArgs->size = sizeof(*outArgs); outArgs->rate = 0; /* TODO */; outArgs->frameType = 0; /* TODO */ outArgs->outbufferSize = frameLen * sizeof(unsigned char); } return (IALG_EOK);}/* * ======== Implementation of the ISPHENC Interface Fxns ======== * * G711ENC_SUN_control: implements ISPHENC::control() * Args: * 'id': Command id. XDM Cmds: SETPARAMS, GETSTATUS, RESET and FLUSH. * Returns: * IALG_EOK for success or IALG_EFAIL * */XDAS_Int32 G711ENC_SUN_control(ISPHENC_Handle handle, ISPHENC_Cmd cmdId, ISPHENC_DynamicParams *dynParams, ISPHENC_Status *status){ XDAS_Int32 retVal; G711ENC_SUN_Obj *g711Enc = (Void *)handle; switch (cmdId) { case XDM_GETSTATUS: assert(status != NULL); status->frameSize = g711Enc->frameLen; /* TODO ... status->bufInfo = ... */ retVal = IALG_EOK; break; case XDM_SETPARAMS: assert(dynParams != NULL); g711Enc->rate = dynParams->bitRate; retVal = IALG_EOK; break; case XDM_RESET: case XDM_SETDEFAULT: case XDM_FLUSH: retVal = IALG_EOK; break; default: /* unsupported cmd */ retVal = ISPHENC_EFAIL; break; } return (retVal);}/* * @(#) ti.xdais.dm.examples.g711; 1,0,0,20; 10-18-2006 19:11:57; /db/wtree/library/trees/dais-g07x/src/ */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -