1、5.Core Code and Explanation of SystemThe code of the system is listed as follows: /record.c record/play input using external memory#include #include math.hdsk6416_aic23.h /codec supportUint32 fs=DSK6416_AIC23_FREQ_8KHZ; /set sampling rateUint16 inputsource=DSK6416_AIC23_INPUT_MIC; / select input uns
2、igned long i,count,s;short bufferN;short buffer1SAMPLENUMBER;long m;float max;void InitForFFT();int INPUTSAMPLENUMBER,DATASAMPLENUMBER;float fWaveRSAMPLENUMBER,fWaveISAMPLENUMBER,wSAMPLENUMBER;float sin_tabSAMPLENUMBER,cos_tabSAMPLENUMBER;#pragma DATA_SECTION(buffer,.EXT_RAM) /buffer -external memor
3、yvoid main() int q,t,n,m,l,tt=0; short playing = 0; DSK6416_DIP_init(); DSK6416_LED_init(); comm_poll(); /init DSK, codec, McBSP InitForFFT(); count=0; while(1) /infinite loop if(DSK6416_DIP_get(3) = 0) /if SW#3 is pressed DSK6416_LED_on(3); /turn on LED#3 buffercount+ = input_left_sample(); if(DSK6
4、416_DIP_get(3) =1|(count=N-1) /if SW#3 is pressed DSK6416_LED_off(3); if(DSK6416_DIP_get(0)=0) /if SW#0 pressed playing = 1; while (playing = 1) DSK6416_LED_on(0); /turn on LED#0 output_left_sample(buffercount+); if(count=N-1) DSK6416_LED_off(0); for(s=50;sN/SAMPLENUMBER;s+) n=0; for(l=SAMPLENUMBER*
5、(s-1);ls*512;l+) n=l-SAMPLENUMBER*(s-1); buffer1n=bufferl; for(q=0;qSAMPLENUMBER;q+) fWaveRq=buffer1q; fWaveIq=0.0f; FFT(fWaveR,fWaveI); max=w0; m=0; for(t=0;tSAMPLENUMBER/2;t+) if(max=1046&tt513) DSK6416_LED_on(2);0) DSK6416_LED_on(1); else DSK6416_LED_on(3); DSK6416_LED_on(1); if(tt25) printf(%dn,
6、tt); DSK6416_LED_off(1); DSK6416_LED_off(2); DSK6416_LED_off(3); /for(s=1; /if(count / while (playing = 1) playing=0; /if(DSK6416_DIP_get(0)=0) /while(1)/main void FFT(float dataRSAMPLENUMBER,float dataISAMPLENUMBER) int x0,x1,x2,x3,x4,x5,x6,x7,x8,xx; int i,j,k,b,p,L; float TR,TI,temp; /* following
7、code invert sequence */ for ( i=0;ii+ ) x0=x1=x2=x3=x4=x5=x6=x7=x8=0; x0=i&0x01; x1=(i/2)& x2=(i/4)& x3=(i/8)&x4=(i/16)& x5=(i/32)& x6=(i/64)&x7=(i/128)&x8=(i/256)& /x=x0*1024+x1*512+x2*256+x3*128+x4*64+x5*32+x6*16+x7*8+x8*4+x9*2+x10; xx=x0*256+x1*128+x2*64+x3*32+x4*16+x5*8+x6*4+x7*2+x8; dataIxx=dat
8、aRi; dataRi=dataIi; dataIi=0; /* following code FFT */ for ( L=1;L0 ) b=b*2; i-; /* b= 2(L-1) */ for ( j=0;j0 ) /* p=pow(2,7-L)*j; */ p=p*2; p=p*j; for ( k=j;kk=k+2*b ) /* for (3) */ TR=dataRk; TI=dataIk; temp=dataRk+b; dataRk=dataRk+dataRk+b*cos_tabp+dataIk+b*sin_tabp; dataIk=dataIk-dataRk+b*sin_ta
9、bp+dataIk+b*cos_tabp; dataRk+b=TR-dataRk+b*cos_tabp-dataIk+b*sin_tabp; dataIk+b=TI+temp*sin_tabp-dataIk+b*cos_tabp; /* END for (3) */ /* END for (2) */ /* END for (1) */ wi=sqrt(dataRi*dataRi+dataIi*dataIi); /* END FFT */Firstly, I set the sampling fruquency as 8 Khz, and the total buffer number is
10、512000 which means that it can record the voice as long as 64 seconds. The core of the code includes three parts. One is the recording part, and the second is playing part, and the third is the FFT analysis part. While the DSP chip detect the switch three was pressed, then recording starts. Recordin
11、g is accomplished by the fuction called input_sample., which can complete the AD sampling and store the sampled value into buffer. LED three will turn off while the buffer has been filled or the switch three is uplifted. Then if you press switch zero, then playing starts, which can paly what has bee
12、n recorded. And the playing part is accomplished by the function called output_sample, which can read the discrete value in the buffer and turn in to analogy speech signal. After the palying is over, LED zero will turn off, and LED one will turn on indicating that FFT with the radix-2 analysis begin
13、s. FFT algorithm computing is accomplished by looking up to table, and the table is made up by the sine function and cosine fuction, we will get the real and imaginary parts of magnitudes. And then by the way of ergodic algorithm to find the accurate number of location of the maxmum magnitude. We wi
14、ll get the frequency by equation of, After the FFT finished, LED one will turn off, and the speech signal spectrum analyzer has fulfilled all function.6.Debugging Recording of System and Testing IllustrationEach time, FFT analyze 512 points. So I divide the whole buffer into lots of little buffer containing 512 points. The debugging processing mainly depends on the location of breakpoints. I set the breakpoint in the location of FFT analyze of each little buffer called buffer1, and when the code execute the lo
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1