www.pudn.com > DM642_TLV320ALC23B.rar > main.c
/* * Copyright 2003 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. * */ /* * ======== main.c ======== * * This example demonstrates the use of IOM drivers with SIOs and tasks by * using the DIO class driver with a user defined device mini-driver * called "codec" and a class driver DIO instance called "dio_codec". This is * the loopback application where audio is read from an input SIO, then sent * back via an output SIO. * The following objects need to be created in the DSP/BIOS * configuration for this application: * * * A UDEV object, which links in a user device driver. In this * case the UDEV is a codec based IOM device driver. * * A DIO object, which links the UDEV object. * * A TSK object, with the function to run set to the function demo * defined in this file. * * A LOG named trace for debug and status output. */ #include#include #include #include #include #include #include #include "seeddm642.h" #include #define NUM_CODEC_CHANNELS 8 /* stereo: left + right */ #define SAMPLEING_RATE 48 /* 48 samples/ms */ #define FRAME_SIZE 10 /* 10 ms */ #define NFRAMES 100 /* 100 frames = 1 second */ #define BUFLEN (NUM_CODEC_CHANNELS*SAMPLEING_RATE*FRAME_SIZE) #ifdef _6x_ extern far LOG_Obj trace; /* * Buffers placed in external memory are aligned on a 128 bytes boundary. * In addition, the buffer should be of a size multiple of 128 bytes for * the cache work optimally on the C6x. */ #define BUFALIGN 128 /* alignment of buffer to allow use of L2 cache */ #else extern LOG_Obj trace; #define BUFALIGN 1 #endif #define BUFSIZE (BUFLEN * sizeof(short)) /* * ======== EVMDM642_DEVPARAMS ======== * This static initialization defines the default parameters used for * EVMDM642_EDMA_AIC23 IOM driver */ EVMDM642_EDMA_AIC23_DevParams EVMDM642_CODEC_DEVPARAMS = EVMDM642_EDMA_AIC23_DEFAULT_DEVPARAMS; /* inStream and outStream are SIO handles created in main */ SIO_Handle inStream, outStream; /* Function prototype */ static Void createStreams(); static Void prime(); /* * ======== main ======== */ Void main() { LOG_printf(&trace, "echo started"); } short *pEchoBuf; const int echoBufSize = NFRAMES * BUFLEN; int echoBufOffset = 0; int delayTime = 500; int echoAtt = 64; /* * ======== initEchoBuffer ======== * Allocate echo buffer and fill with silence */ int initEchoBuffer() { pEchoBuf = MEM_calloc(0, echoBufSize * sizeof(short), BUFALIGN); return (pEchoBuf == MEM_ILLEGAL) ? -1 : 0; } /* * ======== copyWithEcho ======== * Copy an incoming buffer with stereo audio samples into an outgoing * buffer, mixing with samples from the echo buffer indexed by * the parameter timeDelay. The parameter "a" indicates the mix * attenuation * 256 (i.e. 64 = 0.25). */ void copyWithEcho(short *inBuf, short *outBuf, int timeDelay, int a) { int i; int srcSample; for(i = 0;i