// FFTTest.cpp : Definiert den Einsprungpunkt für die Konsolenanwendung.
//

#include "stdafx.h"
#include <stdio.h>
#include "fourierd.c"
#include "math.h"


#define SampleFrequency 44100
#define FFTSize 2048
#define InFreq 10000
#define  DDC_PI  (3.14159265358979323846)

int main(int argc, char* argv[])
{

	double	pdRealIn[FFTSize];
	double	pdRealOut[FFTSize];
	double	pdImgIn[FFTSize];
	double	pdImgOut[FFTSize];
	int i;
	for (i = 0; i < FFTSize; i++) {
		pdRealIn[i] = 0.0;
		pdRealOut[i]= 0.0;
		pdImgIn[i]	= 0.0;
		pdImgOut[i] = 0.0;
	}
	for (i = 0; i < FFTSize; i++) {
		pdRealIn[i] = sin(	((double)InFreq / (double)SampleFrequency) *
							2 * DDC_PI
							* i
							);
//		pdRealIn[i] = 1.0;
	}

	Hanning(FFTSize, pdRealIn);

	fft_double(FFTSize, 0, pdRealIn, pdImgIn, pdRealOut, pdImgOut);

	for (i = 0; i < FFTSize/2; i++) {
//		printf("%d - %1.3f\n", i, pdRealIn[i]);
		printf("%5.0f - %1.3f\n", ((SampleFrequency / (double)FFTSize)) * (double)i, sqrt(pdRealOut[i] * pdRealOut[i] + pdImgOut[i] * pdImgOut[i]));
	}

	int	piStopFreq[3];
	piStopFreq[0] =  500;
	piStopFreq[1] = 2000;
	piStopFreq[2] =22100;

	double pdSpectrum[3];
	Spectrum(FFTSize, SampleFrequency, pdRealOut, pdImgOut, piStopFreq, pdSpectrum);

	printf("\n%1.3f x %1.3f x %1.3f\n", pdSpectrum[0], pdSpectrum[1], pdSpectrum[2]);

	return 0;
}
