Blame view

strech/modifreq.cpp 1.32 KB
6c227d28   rsimonin   premier push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #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*4
  
  
  int main(int argc, char **argv)
  {
  //Definition variables
      int i;
  	float pi=3.141592;
      double test[SIZE][2];
  	double test1[SIZE][2];
  	double test2[SIZE][2];
      double test3[SIZE*2][2];
      char *data = new char[SIZE];
  	char *data2 = new char[SIZE];
  	WavData w;
      
  //Creation de la donnée
  	for(i=0;i<SIZE;i++){
  		float w=2.0*3.14*FREQLA;
  		float t=(float)i/FREQ;
  		data[i]=AMPLITUDE*(1+sin(w*t));
  
  		test[i][0]=(double)data[i];
  		test[i][1]=(double)data[i];
      }
  
  //FFT
  	fft(32768*4,test,test2);
6a961b68   rsimonin   modifications
39
  	
6c227d28   rsimonin   premier push
40
41
42
  //Modification dans le domaine fréquentiel
  	for(i=0;i<SIZE;i+=2){
  		test3[i][0]=test2[i][0];
6a961b68   rsimonin   modifications
43
          //printf("%lf ",test2[i][0]);
6c227d28   rsimonin   premier push
44
45
46
47
  		test3[i+1][0]=test2[i][0];
  		test3[i][1]=0;
          test3[i+1][1]=0;
  	}
6a961b68   rsimonin   modifications
48
  	
6c227d28   rsimonin   premier push
49
50
  //FFT inverse
  	ifft(32768*4,test1,test3);
6a961b68   rsimonin   modifications
51
  	
6c227d28   rsimonin   premier push
52
  //Récupération des données
6a961b68   rsimonin   modifications
53
54
55
56
  	float moy=0.0;
  	for(i=0;i<SIZE;i+=2){
  		moy=+test3[i][0];
  	}
6c227d28   rsimonin   premier push
57
  
6a961b68   rsimonin   modifications
58
  	printf("%f ",moy);
6c227d28   rsimonin   premier push
59
  	for(i=0;i<SIZE;i++){
6a961b68   rsimonin   modifications
60
  		data2[i]=test1[i][0]*5+50;
6c227d28   rsimonin   premier push
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  	}
  //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("modifreq.WAV");
  
  }