⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audioloop.c

📁 闻停开发板音频程序
💻 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 <std.h>
#include <stdio.h>
#include <log.h>
#include <sys.h>
#include <mem.h>
#include <sio.h>
#include <csl.h>
#include <csl_cache.h>

#include <evmdm642.h>
#include <evmdm642_led.h>
#include <evmdm642_edma_aic23.h>

#define NUM_CODEC_CHANNELS	 2	/* stereo: left + right		*/
#define SAMPLEING_RATE		8	/* 48 samples/ms			*/
#define FRAME_SIZE			20	/* 20 ms					*/
#define	NFRAMES				50	/* 50 frames = 1 second	*/
#define	BUFLEN	  	(NUM_CODEC_CHANNELS*SAMPLEING_RATE*FRAME_SIZE)

typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
#define BUFALIGN 128    /* alignment of buffer to allow use of L2 cache */
#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();
int nmadus=0;  

/*
// ======== createStreams ======== 
static Void createStreams()
{
    SIO_Attrs attrs;		//设置设备特征    
    // align the buffer to allow it to be used with L2 cache 
    attrs = SIO_ATTRS;
    attrs.align = BUFALIGN;
    attrs.model = SIO_ISSUERECLAIM;

    //open the I/O streams 产生一个指向设备的流
    inStream = SIO_create("/dio_codec", SIO_INPUT, , &attrs);
    if (inStream == NULL) {
    	SYS_abort("Create input stream FAILED.");
    }

    outStream = SIO_create("/dio_codec", SIO_OUTPUT, BUFSIZE, &attrs);
    if (outStream == NULL) {
        SYS_abort("Create output stream FAILED.");
    }
}

/*
 * ======== prime ========
 */
static Void prime()
{
    Ptr buf0, buf1, buf2, buf3;
    /* Allocate buffers for the SIO buffer exchanges */
    buf0 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
    buf1 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
    buf2 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
    buf3 = (Ptr)MEM_calloc(0, BUFSIZE, BUFALIGN);
    if (buf0 == NULL || buf1 == NULL || buf2 == NULL || buf3 == NULL) {
        SYS_abort("MEM_calloc failed.");
    } 
    //SIO_issue 将填满的缓冲区地址回送给流, 分配一个缓存到流中
    /* Issue the first & second empty buffers to the input stream */
    if (SIO_issue(inStream, buf0, SIO_bufsize(inStream), NULL) != SYS_OK) {
        SYS_abort("Error issuing buffer to the input stream");
    }
    if (SIO_issue(inStream, buf1, SIO_bufsize(inStream), NULL) != SYS_OK) {
        SYS_abort("Error issuing buffer to the input stream");
    }
	//SYS_OK 表示函数SIO_issue调用
    /* Issue the first & second empty buffers to the output stream */
    if (SIO_issue(outStream, buf2, SIO_bufsize(outStream), NULL) != SYS_OK) {
        SYS_abort("Error issuing buffer to the output stream");
    }
    if (SIO_issue(outStream, buf3, SIO_bufsize(outStream), NULL) != SYS_OK) {
        SYS_abort("Error issuing buffer to the output stream");
    }
}

/*
 * ======== tskAudioDemo ========
 * This function copies from the input SIO to the output SIO. You could
 * easily replace the copy function with a signal processing algorithm. 
 */
Void tskAudioEnc()
{
    Int nmadus;         /* number of minimal addressable units */
    short *inbuf, *outbuf;

	/* Call createStream function to create I/O streams */
  //  createStreams();
        
    /* Call prime function to do priming */
 //   prime();
    
    /* Loop forever looping back buffers */
    for (;;) {
        /* Reclaim full buffer from the input stream 	*/
        if ((nmadus = SIO_reclaim(inStream, (Ptr *)&inbuf, NULL)) < 0) {
            SYS_abort("Error reclaiming full buffer from the input stream");
        }

        /* Reclaim empty buffer from the output stream to be reused */
        if (SIO_reclaim(outStream, (Ptr *)&outbuf, NULL) < 0) {
            printf("Error reclaiming empty buffer from the output stream");
        }

		{
			int	i;
			for(i=0;i<nmadus/2;i++)
				outbuf[i] = inbuf[i];
		}

        /* Issue full buffer to the output stream */
        if (SIO_issue(outStream, outbuf, nmadus, NULL) != SYS_OK) {
            SYS_abort("Error issuing full buffer to the output stream");
        }

        /* Issue an empty buffer to the input stream */
        if (SIO_issue(inStream, inbuf, SIO_bufsize(inStream), NULL) != SYS_OK) {
            SYS_abort("Error issuing empty buffer to the input stream");
        }
    }
}


/*
 * ======== main ========
 */
Void main()
{
	tskAudioEnc();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -