test.cpp
1.8 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include "wavdata.h"
#include "fft.h"
#include <math.h>
#define FREQ 48000
#define AMPLITUDE 10
#define FREQDO 261
#define FREQLA 440
#define SIZE FREQ*1
int main(int argc, char **argv)
{
WavData w;
int pi=3.14;
char *data = new char[SIZE];
WavData w1;
w1.load("COW.WAV");
char *dat = w1.data();
int i;
for(i=0;i<SIZE;i++){
data[i]=AMPLITUDE*(sin(FREQLA*pi*2*i)+1);
}
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(data);
w.save("pur.WAV");
//----------------------------------------------------------------------------------------------//
double test[SIZE][2];
double test1[SIZE][2];
double test2[SIZE][2];
double test3[SIZE*2][2];
double test4[SIZE][2];
for(i=0;i<SIZE;i++){
test[i][0]=AMPLITUDE*(sin(FREQLA*pi*2*i)+1);
test[i][1]=0;
}
fft(512,test,test2);
for(i=0;i<SIZE;i++){
test3[i*2][0]=test2[i][0];
test3[(i*2)+1][0]=test2[i][0];
test3[i][1]=0;
}
ifft(512,test1,test3);
char *data2 = new char[SIZE*2];
for(i=0;i<SIZE*2;i++){
data2[i]=test1[i][0];
}
w.clearData();
w.setDatasize(SIZE*2);
w.setData(data2);
w.save("test.WAV");
//----------------------------------------------------------------------------------------------//
double test11[SIZE][2];
char *data22 = new char[SIZE];
for(i=0;i<SIZE;i++){
test4[i][0]=test2[i][0];
test4[i][1]=0;
printf("%d ",test1[i][0]);
}
ifft(512,test11,test4);
for(i=0;i<SIZE;i++){
data22[i]=test11[i][0];
}
w.clearData();
w.setDatasize(SIZE);
w.setData(data22);
w.save("test2.WAV");
}
/*
for(i=0;i<w.datasize();i++){
printf("%d ",data[i]);
}
printf("\n\n");
for(i=0;i<100;i++){
printf("%f %f i=%d, ",test2[i][1],test2[i][2],i);
}*/