/* * putwave.c * WaveAsText * * Created by Christopher Dobrian on Wed Jan 14 2004. * */ #include #include #define NUM_SECONDS (1.) #define SAMPLE_RATE (44100.) #define BUF_SIZE 256 #define TWOPI (6.283185307179586) #define MAXAMP (1.) #define FREQUENCY (1000.) int main(void); int main(void) { float amplitude = MAXAMP; float frequency = FREQUENCY; float phase = 0.; unsigned long n; // the current sample number unsigned long totalsamples = (unsigned long)(NUM_SECONDS*SAMPLE_RATE); float twopiFoverR = TWOPI*frequency/SAMPLE_RATE; unsigned long o = 0; //counter for array float y[BUF_SIZE]; // buffer of sample values for( n = 0 ; n < totalsamples ; n++ ) { if (o >= BUF_SIZE) { fwrite( y, sizeof(y[0]), BUF_SIZE, stdout ); o = 0; } y[o++] = amplitude*sin(twopiFoverR*n+phase); } fwrite( y, sizeof(y[0]), o, stdout ); return 0; }