#include #include #include #include "waveio.h" #define SRATE 8000 void main() { FILE *out_file; struct soundhdr hdr; long i,j,total=0,OVERSAMP; double m,k,r,tau,omega,T,t,coeff1,coeff2,Y[3]={0},temp; short ideal,approx; m = 0.001; // Decrease this, frequency will go down k = 1000; // Increase this, frequency will go up r = 0.002; // This controls loss (decay) tau = r / 2 / m; omega = sqrt(k/m - tau*tau); OVERSAMP = 1000; // Increase this, we get more accurate T = 1.0 / ((float) SRATE * (float) OVERSAMP); // Oversampled rate temp = (m + (T*r) + (T*T*k)); // Coefficient denominator coeff1 = ((2.0*m) + (T*r)) / temp; coeff2 = - m / temp; // printf("%f %f\n",coeff1,coeff2); Y[1] = 1.0; // Normalized initial condition fillheader(&hdr,SRATE); #ifdef LITTLENDIAN out_file = opensoundout("masprdmp.wav",&hdr); #else out_file = opensoundout("masprdmp.snd",&hdr); #endif for (i=0;i