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

📄 delay.c

📁 tms320c6416与tlv320aic23b接口基本程序
💻 C
字号:
/***********************************************************************************/
/* 音乐延时效果。																   */ 
/*			版本  1.0															   */
/*			时间  2004.5.11														   */
/***********************************************************************************/
#include <csl_mcbsp.h>
#include <csl.h>

/*数据缓冲区的首址为0x5000,长度为0xb000*/
#define DELAY1BUFF  0x40000

// 定义McBSP的句柄
extern MCBSP_Handle hMcbsp;
/*延时时间设定数组*/
unsigned short delay1buffersize[]={
			5000,6250,
			7500,8750,
			10000,11250,
			12500,13750,
			15000,16250,
			17500,18750,
			20000,21250,
			22500,23750,
			25000,26250,
			27500,28750,
			30000,31250,
			32500,33750,
			35000,36250,
			37500,38750,
			40000,41250,
			42500,45056}; //  <=  45056
/*反馈深度的设定数组*/
short delay1ratio[]={
			15000,16000,
			17000,17500,
			18000,18500,
			19000,19500,
			20000,20500,
			21000,21500,
			22000,22500,
			23000,24000,
			15000,16000,
			17000,17500,
			18000,18500,
			19000,19500,
			20000,20500,
			21000,21500,
			22000,22500,
			23000,24000};

void delay1(int delay,int decay)
{
	/*设定缓冲区的数据长度*/
	//int BUFFER_SIZE=buffersize[delay];
	/*code for test*/
	unsigned int i;
	unsigned short BUFFER_SIZE = delay1buffersize[delay];
	/*设定反馈的深度*/
	//int delayagain=ratio[decay];
	/*code for test*/
	short delayagain=delay1ratio[decay];
	/*定义音频的输入(左,右)与输出*/
	int input,inputh;
	int output;
	int databuffer;
	/*定义循环变量*/                      
	unsigned int n;
	/*定义数据缓冲区,<32k*/
	unsigned short *delay1buffer;
//	int buffer[32000];
	unsigned int write_position = BUFFER_SIZE-1;
	unsigned int read_position=0;

  	/*初始化缓冲区,置0*/
  	 delay1buffer = (unsigned short *)DELAY1BUFF;

  	/*初始化缓冲区,置0*/
  	for(n=0;n<2*BUFFER_SIZE-1;n++)
  	{
  		*(unsigned short *)delay1buffer = 0;
  		delay1buffer= delay1buffer;
  	}
 	do{
 		
    
    	while (!MCBSP_rrdy(hMcbsp));
    	inputh = MCBSP_read(hMcbsp);

	
 	input = (inputh>>16)  & 0xffff;
 	
 	output = input; //* 0.732;
 	/*
  	databuffer = input * 732/1000;
  	//output = (unsigned int)databuffer;
  	output = *((unsigned short *)(DELAY1BUFF + read_position*2));
  	
  	if(output < 0x7fff)
  	{
  		output = (short)output + (short)databuffer;
 		if(output > 0x10000)
  		{
  			output = (output & 0xffff)|0x8000;
  		}
  		else
  		{
  			output = output & 0xffff;
  		}
  		databuffer = output * 732/1000;
 		*((unsigned short *)(DELAY1BUFF + write_position*2)) =(unsigned short)(input - (int)databuffer);
  		
  	}
  	else
  	{
  		output = (short)databuffer - (short)output;
  		if(output > 0x10000)
  		{
  			output = (output & 0xffff)|0x8000;
  		}
  		else
  		{
  			output = output & 0xffff;
  		}
  		databuffer = output * 0.732;
 		*((unsigned short *)(DELAY1BUFF + write_position*2)) =(unsigned short)(input - (int)databuffer);
  		
  	}
  		
  	*/	
  		
  	output = (output << 16) | output;
  	
	//while(!MCBSP_xrdy(hMcbsp));
	MCBSP_write(hMcbsp,output);
//  		output = output +( (input*delayagain)>>15);
  
//  		*((unsigned int *)(DELAY1BUFF + write_position)) = input;  		
//  		*((unsigned int *)(DELAY1BUFF + write_position)) -= (output*delayagain)>>15;   
  
 
		
	
  
   		read_position++;
   		if (read_position>(BUFFER_SIZE-1)) 
      	{
      		read_position=0;
      	}
		write_position++;
   		if (write_position>(BUFFER_SIZE-1))
   		{
   			write_position=0;	
   		}
    }while(TRUE);
}


⌨️ 快捷键说明

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