28 #define SAMPLE_RATE 48000 40 #include <sys/types.h> 51 gettimeofday(&tp, NULL);
52 ret = ((double) tp.tv_sec) + 1e-6*((double)tp.tv_usec);
65 filter_map[0] =
new SoDa::OSFilter(300.0, 400.0, 500.0, 600.0, 512, 1.0, 48000.0, inbuflen);
67 filter_map[1] =
new SoDa::OSFilter(300.0, 400.0, 900.0, 1000.0, 512, 1.0, 48000.0, inbuflen);
68 filter_map[2] =
new SoDa::OSFilter(200.0, 300.0, 2300.0, 2400.0, 512, 1.0, 48000.0, inbuflen);
69 filter_map[3] =
new SoDa::OSFilter(100.0, 200.0, 6200.0, 6300.0, 512, 1.0, 48000.0, inbuflen);
70 filter_map[4] =
new SoDa::OSFilter(100.0, 200.0, 18000.0, 19000.0, 512, 1.0, 48000.0, inbuflen);
71 std::ofstream f100(
"filt100.dat");
72 std::ofstream f500(
"filt500.dat");
73 std::ofstream f2000(
"filt_fd2000.dat");
74 std::ofstream f6000(
"filt_fd6000.dat");
75 std::ofstream fspec(
"filt_pass.dat");
77 filter_map[0]->
dump(f100);
78 filter_map[1]->
dump(f500);
79 filter_map[2]->
dump(f2000);
80 filter_map[3]->
dump(f6000);
81 filter_map[4]->
dump(fspec);
92 void add_sig(complex<float> * in,
float freq,
int len,
float acc)
95 float phase_step = 2.0 * M_PI * freq / ((float)
SAMPLE_RATE);
97 for(i = 0; i < len; i++) {
98 in[i] = acc * in[i] + complex<float>(cos(ang),sin(ang));
100 if(ang > M_PI) ang = ang - (2.0 * M_PI);
107 int main(
int argc,
char * argv[])
113 fprintf(stderr,
"Hey there!\n");
119 const int samp_len = 65536;
120 int inbuflen = samp_len / 8;
122 for(
int iii = 0; iii < 6; iii++) {
123 specbuf[iii] = (
float*) malloc(
sizeof(
float) * samp_len);
127 complex<float> in[samp_len];
128 complex<float> out[6][samp_len];
130 FILE * trace_outf = fopen(
"OSFilter_Test_Trace.dat",
"w");
131 FILE * spec_outf = fopen(
"OSFilter_Test_Spectrum.dat",
"w");
135 std::complex<float> sout[6][samp_len];
136 fftwf_plan sp = fftwf_plan_dft_1d(samp_len, (fftwf_complex *) out[0], (fftwf_complex *) sout[0],
137 FFTW_FORWARD, FFTW_ESTIMATE);
140 for(j = 0; j < 5; j++) {
141 for(i = 0; i < samp_len; i++) specbuf[j][i] = 0.0;
146 for(k = 0; k < 1000; k++) {
147 for(i = 0; i < samp_len; i++) {
148 long irand = random();
149 in[i] = ((float) (irand & 0xffff));
154 for(i = 0; i < samp_len; i++) {
160 for(i = 0; i < 5; i++) {
162 for(j = 0; j < samp_len; j += inbuflen) {
163 filter_map[i]->
apply(&(in[j]), &(out[i+1][j]));
170 for(i = 0; i < samp_len; i++) {
171 fprintf(trace_outf,
"%d ", i);
172 for(j = 0; j < 6; j++) {
173 fprintf(trace_outf,
"%g %g ", out[j][i].real(), out[j][i].imag());
175 fprintf(trace_outf,
"\n");
179 for(j = 0; j < 6; j++) {
180 fftwf_execute_dft(sp, (fftwf_complex*) out[j], (fftwf_complex*)sout[j]);
182 for(i = 0; i < samp_len; i++) {
183 for(j = 0; j < 6; j++) {
185 re = sout[j][i].real();
186 im = sout[j][i].imag();
187 specbuf[j][i] += sqrt(re * re + im * im);
193 float norm = 1.0 / ((float) k);
194 for(i = 0; i < samp_len / 2; i++) {
195 float freq = ((float) i) * 48000.0 / 65536.0;
196 fprintf(spec_outf,
"%d %f", i, freq);
197 for(j = 0; j < 6; j++) {
198 fprintf(spec_outf,
" %f", norm * specbuf[j][i]);
200 fprintf(spec_outf,
"\n");
This is an overlap-and-save frequency domain implementation of a general FIR filter widget...
int main(int argc, char *argv[])
void add_sig(complex< float > *in, float freq, int len, float acc)
void dump(std::ostream &os)
dump the filter FFT to the output stream
Overlap-and-save filter class.
unsigned int apply(std::complex< float > *inbuf, std::complex< float > *outbuf, float outgain=1.0)
run the filter on a complex input stream
SoDa::OSFilter ** buildFilterMap(int inbuflen)