lastrech.cpp 1.28 KB
#include <iostream>
#include "wavdata.h"
#include "fft.h"
#include <math.h>


#define FREQ 22400
#define AMPLITUDE 10
#define FREQDO 261
#define FREQLA	440
#define SIZE FREQ*2


int main(int argc, char **argv)
{
//Definition variables
    int i,j;
	float pi=3.141592;
    double test[SIZE*2][2];
	double test2[SIZE*2][2];
	double test1[SIZE*2][2];
	double test3[SIZE*2][2];

	char *data2 = new char[SIZE];
	WavData w;
    
//Creation de la donnée
	printf("===Creation data\n");
	for(i=0;i<SIZE;i++){
		float wla=2.0*3.14*FREQLA;
		float t=(float)i/FREQ;

		test[i][0]=AMPLITUDE*(1+sin(wla*t));
		test[i][1]=0;
    }

//FFT
	printf("===fft\n");
	fft(32768*2,test,test2);

//Modification dans le domaine fréquentiel
	printf("===modif freq\n");
	for(i=0;i<SIZE;i++){
		test3[2*i][0]=test2[i][0];
		test3[2*i+1][0]=test2[i][0];
		test3[2*i][1]=0;
        test3[2*i+1][1]=0;
	}
	
//FFT inverse
	ifft(32768*2,test1,test3);
	
//Récupération des données

	for(j=0;j<SIZE;j++){
		data2[j]=(test1[j][0]+10);
		printf("%d %lf %lf\n ",j,test1[j][0],test[j][0]);
	}

//Preapation format final
	w.setAudioFormat(1);
	w.setNbrChanel(1);
	w.setFrequency(FREQ);
	w.setBytePerBloc(4);
	w.setBytePerSec(FREQ);
	w.setBitsPerSample(8);
	w.clearData();
	
	w.setDatasize(SIZE);
	w.setData(data2);
	w.save("lastrech.WAV");


}