exec_fir.c

来自「TI CCS开发环境下的FIR滤波器实现工程」· C语言 代码 · 共 86 行

C
86
字号
#include <stdio.h>

/*
		Exercise 1	FIR Filter
		DSPLab, Tianjin University
		2007.10.30
*/

#define BUFFERSIZE	2048	/* Input and output buffer size */
#define ASMFILTER	1		/* If use assembly code to implement filter */
#define FILEIO_OPEN	0		/* If use FILEIO */

#include "blackman_low_pass_filter_2000Hz.h"

#if ASMFILTER
#include "FIR_filters_asm.h"
#else
#include "FIR_filters.h"

#endif

#if FILEIO_OPEN
	int input_buffer[BUFFERSIZE];
#else
#include "importdata.h"
#endif


int output_buffer[BUFFERSIZE];
	
//Dummy function
void inject()
{
	return;
}

//Dummy function
void drawout()
{
	return;
}

void main()
{
	signed int mono_input;
    signed long output; 
	int i;

	printf("Program is running...\n");
	
	//For FileIO
	inject();
	
	for (i = 0; i < BUFFERSIZE/2; i++)
	{
		mono_input = stereo_to_mono(input_buffer[2*i], input_buffer[2*i+1]);

		/* Use blackman filter to seperate different frequency. */
#if ASMFILTER		
		output = FIR_dual_filter_asm(&blackman_low_pass_filter_2000Hz[0], mono_input);
#else
		output = FIR_dual_filter_tmp(&blackman_low_pass_filter_2000Hz[0], mono_input);
#endif
		
		//Low 8-bit and high 8-bit are the data of 2 channels respectively.
		output_buffer[2*i] = (signed int) (output & 0xFFFF );      
        output_buffer[2*i+1] = (signed int) (output >> 16 );
	}
	
	//For FileIO
	drawout();
}

signed int stereo_to_mono(signed int left_channel, signed int right_channel)
{
	 signed long temp;
 
	 /* Take average of left and right channels. */
 
	 temp = (signed long) left_channel + (signed long) right_channel;
 
	 temp >>= 1;    /* Divide by 2 to prevent overload at output */
 
	 return ((signed int) temp); /* Return mono value to calling function */
}

⌨️ 快捷键说明

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