#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N (400) //テーブルの大きさ
int para[N];
long buff[N];
int read_para(FILE *fp, int w, int gain)
{
double in;
int n=0, ret;
char line[256];
while((ret=fscanf(fp,"%lf",&in))!=EOF) {
if (!ret) {
fgets(line,255,fp);
// printf(">%s",line);
continue;
}
para[n++] = (gain*in)*pow(2,w-1);
}
return n;
}
main( int argc, char *argv[] )
{
FILE *fp;
int n=1, w=20, g=1, i=0, x;
long in, out;
if (argc>1)
fp = fopen(argv[1],"r"); //Parameter File
if (argc>2)
w = atoi(argv[2]); //Bit Width
if (argc>3)
g = atoi(argv[3]); //Gain
if (fp)
n = read_para(fp,w,g);
else
para[0] = 1;
while(fscanf(stdin,"%ld",&in)!=EOF) {
buff[i] = in;
out = 0;
for (x=0; x<n ;x++)
out += buff[(i-x+n)%n] * para[x];
printf("%ld\n",out);
i = (i+1)%n;
}
}
% pulse 400 | firf coeff.txt | gp_wav > firf_test.png
% white 3360 | imul 250 | firf coeff.txt | fftw | gp_fftl > firf_fftwx.png
% pulse 336000 | firf coeff.txt | fftw | gp_fftl > firf_fft.png
% white 336000 > white336000.dat
% cat white336000.dat | imul 20 | firf coeff.txt | fftw | gp_fftl > firf_fftw.png
% pulse 336000 | firf coeff.txt | fftw | head -50000 | gp_fftl > firf_fft20.png
% pulse 336000 | firf coeff.txt 32 | fftw | head -50000 | gp_fftl > firf_fft32.png
% pulse 308 | firf coeff.txt | gp_pulse2 > firf_testp2.png
% pulse 308 | firf coeff.txt | gp_wav2 > firf_testw2.png
元の周波数 | 処理 | 変換後の周波数 | 周波数間隔 | FIRタップ数 |
---|---|---|---|---|
48000 | Up7 | 336000 | 20000-28000 | 308 |
336000 | Down5 | 67200 | ||
67200 | Up7 | 470400 | 20000-47200 | 126 |
470400 | Down4 | 117600 | ||
117600 | Up3 | 352800 | 20000-97600 | 30 |
352800 | Down8 | 44100 |
% pulse 336000 | firf coeff1.txt | fftw | gp_fftl > fir1_fft20.png
% pulse 336000 | firf coeff1.txt | fftw | head -50000 | gp_fftl > fir1_fft20x.png
% pulse 470400 | firf coeff2.txt | fftw | gp_fftl > fir2_fft20.png
% pulse 470400 | firf coeff2.txt | fftw | head -80000 | gp_fftl > fir2_fft20x.png
% pulse 352800 | firf coeff3.txt | fftw | gp_fftl > fir3_fft20.png
% pulse 352800 | firf coeff3.txt | fftw | head -150000 | gp_fftl > fir3_fft20x.png
% pulse 352800 | firf coeff3.txt 18 | fftw | gp_fftl > fir3_fft18.png
% pulse 352800 | firf coeff3.txt 18 | fftw | head -150000 | gp_fftl > fir3_fft18x.png
% idds 20000 48000 | head -80 | gp_wav > dds20k48ksw.png
% idds 20000 48000 | fftw | gp_fftl > dds20k48ks.png
% idds 20000 48000 | lups 7 | head -500 | gp_wav > dds20k48ks_u7w.png
% idds 20000 48000 | lups 7 | fftw | gp_fftl > dds20k48ks_u7.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | head -500 | gp_wav > dds20k48ks_u7f1w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | fftw | gp_fftl > dds20k48ks_u7f1.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 | head -100 | gp_wav > dds20k48ks_u7f1d5w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 | fftw | gp_fftl > dds20k48ks_u7f1d5.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | head -700 | gp_wav > dds20k48ks_u7f1d5u7w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | fftw | gp_fftl > dds20k48ks_u7f1d5u7.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | head -700 | gp_wav > dds20k48ks_u7f1d5u7f2w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 | head -150 | gp_wav > dds20k48ks_u7f1d5u7f2d4w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2d4.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | head -500 | gp_wav > dds20k48ks_u7f1d5u7f2d4u3w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2d4u3.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt | head -500 | gp_wav > dds20k48ks_u7f1d5u7f2d4u3f3w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2d4u3f3.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | head -500 | gp_wav > dds20k48ks_u7f1d5u7f2d4u3f3xw.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2d4u3f3x.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | ldws 8 | head -80 | gp_wav > dds20k48ks_u7f1d5u7f2d4u3f3xd8w.png
% idds 20000 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | ldws 8 | fftw | gp_fftl > dds20k48ks_u7f1d5u7f2d4u3f3xd8.png
% pulse 48000 | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | ldws 8 | fftw | gp_fftl > pulse_u7f1d5u7f2d4u3f3xd8.png
% dumpwave saadekakeyo.wav > saadekakeyo.dat
% cat saadekakeyo.dat | lups 7 | firf coeff1.txt | ldws 5 \
| lups 7 | firf coeff2.txt | ldws 4 \
| lups 3 | firf coeff3.txt 18 | ldws 8 | imul 0.000000000000008 | tee > saadekakeyo_fir.dat
% txt2wav -44100 saadekakeyo_fir.dat
% lame --preset studio saadekakeyo.wav saadekakeyo.mp3
% lame --preset studio saadekakeyo_fir.wav saadekakeyo_fir.mp3