#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//1秒分のデータを生成
#define FREQ (1000) //生成周波数
#define SAMPLE (1000000) //サンプリング周波数
#define BWIDTH 16
main( int argc, char *argv[] )
{
double d;
int f,s;
int out,t,max;
f = FREQ;
s = SAMPLE;
if (argc>1)
f = atoi(argv[1]);
if (argc>2)
s = atoi(argv[2]);
d = 2*M_PI*f/s;
max = (int)pow(2,BWIDTH-1)-1;
for (t=0; t<s ;t++) {
out = (int)(sin(t*d)*max);
printf("%d\n",out);
}
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//1秒分のデータを生成
#define FREQ (1000) //生成周波数
#define SAMPLE (1000000) //サンプリング周波数
#define N (1000000) //テーブルの大きさ
#define BWIDTH 16
int sin_table[N/4+1];
int max;
void make_table(int n)
{
int x;
max = (int)pow(2,BWIDTH-1)-1;
for (x=0; x<=n/4 ;x++)
sin_table[x] = (int)(sin(2*M_PI/n*x)*max);
}
int sin_x(int x, int n)
{
int xx;
xx = x%(n/4);
if (x < n/4*1) return sin_table[xx];
else if (x < n/4*2) return sin_table[n/4-xx];
else if (x < n/4*3) return -sin_table[xx];
else return -sin_table[n/4-xx];
}
main( int argc, char *argv[] )
{
int i, d, t=0;
int f, n, s;
f = FREQ;
s = SAMPLE;
n = N;
if (argc>1)
f = atoi(argv[1]);
if (argc>2)
s = atoi(argv[2]);
n = s;
make_table(n);
d = (long)f*n/s;
for (i=0; i<s ;i++) {
printf("%d\n",sin_x(t,n));
t = (t+d)%n;
}
}
% isingen 1000 | head -1000 | gp_wav > isingen_1000.png
% idds 1000 | head -1000 | gp_wav > idds_1000.png
% isingen 1000 | fftw | gp_fft > isingen_1000_fft.png
% idds 1000 | fftw | gp_fft > idds_1000_fft.png
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main( int argc, char *argv[] )
{
FILE *fp;
double in1,in2;
fp = fopen(argv[1],"r");
if (fp) {
while((fscanf(stdin,"%lf",&in1)!=EOF)&&(fscanf(fp,"%lf",&in2)!=EOF)) {
printf("%d\n",(int)floor(in1*in2));
}
}
else {
in2 = 1;
if (argc>1)
in2 = atof(argv[1]);
while((fscanf(stdin,"%lf",&in1)!=EOF)) {
printf("%d\n",(int)floor(in1*in2));
}
}
}
#!/home/blueseed/bin/gnuplot
set terminal png
set nokey
set xlabel "f[kHz]"
set ylabel "|F(w)|"
set logscale x
set logscale y
plot [0.5:][1:1000000] '< cat -' using ($1/1000):4 with impulses linewidth 1
% idds 1000 | comp 0 | head -1000 | gp_wav > comp1000.png
% idds 1000 | comp 0 | fftw | gp_fftx > comp1000_fft.png
#include <stdio.h>
#include <math.h>
#define BWIDTH 16
int main(int argc, char *argv[])
{
int in,out,max;
int delta=0,sigma=0;
int a1=1;
max = (int)pow(2,BWIDTH-1);
if (argc>1)
a1 = atoi(argv[1]);
while (scanf("%d", &in) != EOF) {
sigma += in - (delta ? +a1*max : -a1*max);
out = (sigma > 0) ? 1 : 0;
delta = out;
printf("%d\n",out);
}
return 0;
}
% idds 1000 | ids1 | head -1000 | gp_wav > ids1_1000.png
% idds 1000 | ids1 | fftw | gp_fftx > ids1_1000_fft_1.png
#include <stdio.h>
#include <math.h>
#define BWIDTH 16
int main(int argc, char *argv[])
{
int in,out,max;
int delta1=0,delta2=0,sigma1=0,sigma2=0;
int a1=1,a2=1;
max = (int)pow(2,BWIDTH-1);
if (argc>1)
a1 = atoi(argv[1]);
if (argc>2)
a2 = atoi(argv[2]);
while (scanf("%d", &in) != EOF) {
sigma1 += in - (delta1 ? +a1*max : -a1*max);
sigma2 += sigma1 - (delta2 ? +a2*max : -a2*max);
out = (sigma2 > 0) ? 1 : 0;
delta1 = delta2;
delta2 = out;
printf("%d\n",out);
}
return 0;
}
% idds 1000 | ids2 | head -1000 | gp_wav > ids2_1000.png
% idds 1000 | ids2 | fftw | gp_fftx > ids2_1000_fft_1_1.png
% idds 1000 | ids2 2 1 | fftw | gp_fftx > ids2_1000_fft_2_1.png
% idds 1000 | ids2 4 1 | fftw | gp_fftx > ids2_1000_fft_4_1.png
% idds 1000 | ids2 8 1 | fftw | gp_fftx > ids2_1000_fft_8_1.png
% idds 1000 | ids2 16 1 | fftw | gp_fftx > ids2_1000_fft_16_1.png
% idds 1000 | ids2 1 2 | fftw | gp_fftx > ids2_1000_fft_1_2.png
% idds 1000 | ids2 1 4 | fftw | gp_fftx > ids2_1000_fft_1_4.png
% idds 1000 | ids2 1 8 | fftw | gp_fftx > ids2_1000_fft_1_8.png
% idds 1000 | ids2 1 16 | fftw | gp_fftx > ids2_1000_fft_1_16.png
% idds 1000 | ids2 2 2 | fftw | gp_fftx > ids2_1000_fft_2_2.png
% idds 1000 | ids2 2 4 | fftw | gp_fftx > ids2_1000_fft_2_4.png
% idds 1000 | ids2 2 8 | fftw | gp_fftx > ids2_1000_fft_2_8.png
% idds 1000 | ids2 2 16 | fftw | gp_fftx > ids2_1000_fft_2_16.png
% idds 1000 | ids2 4 2 | fftw | gp_fftx > ids2_1000_fft_4_2.png
% idds 1000 | ids2 4 4 | fftw | gp_fftx > ids2_1000_fft_4_4.png
% idds 1000 | ids2 4 8 | fftw | gp_fftx > ids2_1000_fft_4_8.png
% idds 1000 | ids2 4 16 | fftw | gp_fftx > ids2_1000_fft_4_16.png
% idds 1000 | ids1 | fftw | gp_fftx > ids1_1000_fft_1.png
% idds 1000 | ids1 2 | fftw | gp_fftx > ids1_1000_fft_2.png
#include <stdio.h>
#include <math.h>
#define BWIDTH 16
int main(int argc, char *argv[])
{
int in,out,max;
int sigma=0;
int a1=1;
max = (int)pow(2,BWIDTH-1);
if (argc>1)
a1 = atoi(argv[1]);
while (scanf("%d", &in) != EOF) {
out = (sigma > 0) ? 1 : 0;
sigma += in - (out ? +a1*max : -a1*max);
printf("%d\n",out);
}
return 0;
}
% idds 1000 | ids1 2 | fftw | gp_fftx > ids1_1000_fft_2.png
% idds 1000 | ids1x 2 | fftw | gp_fftx > ids1x_1000_fft_2.png
#include <stdio.h>
#include <math.h>
#define BWIDTH 16
int main(int argc, char *argv[])
{
int in,out,max;
int sigma1=0,sigma2=0;
int a1=1,a2=2;
max = (int)pow(2,BWIDTH-1);
if (argc>1)
a1 = atoi(argv[1]);
if (argc>2)
a2 = atoi(argv[2]);
while (scanf("%d", &in) != EOF) {
out = (sigma2 > 0) ? 1 : 0;
sigma2 += sigma1 - (out ? +a2*max : -a2*max);
sigma1 += in - (out ? +a1*max : -a1*max);
printf("%d\n",out);
}
return 0;
}
% idds 1000 | ids2 2 4 | fftw | gp_fftx > ids2_1000_fft_2_4.png
% idds 1000 | ids2x 2 4 | fftw | gp_fftx > ids2x_1000_fft_2_4.png
% idds 1000 | comp 0 | imul 255 > iddscmp.dat
% txt2wav -1000000 iddscmp.dat
% lame iddscmp.wav iddscmp.mp3
% idds 1000 | ids1x 2 | imul 255 > idds1x_2.dat
% txt2wav -1000000 idds1x_2.dat
% lame idds1x_2.wav idds1x_2.mp3
% idds 1000 | ids2x 2 4 | imul 255 > idds2x_2_4.dat
% txt2wav -1000000 idds2x_2_4.dat
% lame idds2x_2_4.wav idds2x_2_4.mp3
Resampling: input 1000 kHz output 48 kHz
Using polyphase lowpass filter, transition band: 16452 Hz - 17032 Hz
max = (int)pow(2,BWIDTH-1);
max = (int)pow(2,BWIDTH-1)-1;