예제 #1
0
Array<T,N> convolutionWithFFT(
    const Array<T,N>& A,
    const Array<T,N>& B
){
    TinyVector<int,N> a = A.length();
    TinyVector<int,N> b = B.length();
    Array<T,N> padA(a+b);
    Array<T,N> padB(a+b);
    padAround(A,padA);
    padAround(B,padB);

    Array<std::complex<T>,N> Afft = forwardFFT(padA);
    Array<std::complex<T>,N> Bfft = forwardFFT(padB);
    Afft *= Bfft;
    Array<T,N> C = inverseFFT(Afft);
    TinyVector<int, N> c = (a+b+1)/2;
    return circularShift(C,c); 
}
int main(void)		//main program
{
	ex_sask_init( );	//init sask

	ADCChannelInit	(pADCChannelHandle,adcBuffer);	//init audio input handler
	OCPWMInit		(pOCPWMHandle,ocPWMBuffer);

	ADCChannelStart	(pADCChannelHandle);	//start audio input handler
	OCPWMStart		(pOCPWMHandle);	

	while(1)
	{
		if(state==0)	//Program is in READY state
		{
			state=0; //set state to 0[READY]
			state=displayState(STATE_READY); //call ready state function and read new state back
			turnOffAll();	//turn off all LEDs when leaving ready state
		}
		else if(state==1)		//Program is in READ state
		{
			while(ADCChannelIsBusy(pADCChannelHandle)); //read audio input
				ADCChannelRead	(pADCChannelHandle,AudioIn,FFT_FRAME_SIZE);
			
			state=3;
		}
		else if(state==3)		//Program is in ANALZYE state
		{
			int i=0;

				analysingState(1);
			FFT(&AudioIn, &FFTcompResults); //FFT function used on audio input, using FFT_FRAME_SIZE and returning the results in FFTcompResults
			
				analysingState(2);
			generateAuralisation(&AuralisationWorkSpace, &FFTcompResults);
			
				analysingState(3);
			for(i=0;i<FFT_FRAME_SIZE;i++)
			{
				inverseFFT(AudioOut[i], AuralisationWorkSpace[i]);
			}

			state=displayState(STATE_ANALYSE);	//analising finished
		}
		else if(state==4)		//Program is in PLAY BACK state
		{
			int x;
			for(x=0;x<FFT_FRAME_SIZE;x++)
			{
				while(OCPWMIsBusy(pOCPWMHandle));	
					OCPWMWrite (pOCPWMHandle,AudioOut[x],FFT_FRAME_SIZE);

				playbackState();
			}

			OCPWMStop (pOCPWMHandle); //stop audio output
			state=0;
		}
		else		//Program is in ERROR state
		{
			state=displayState(STATE_ERROR);	//show error state on LEDs and read new state
		}
	}
}