/* * putwaveint.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 (32000.) #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 short int y; // buffer of sample values for( n = 0 ; n < totalsamples ; n++ ) { y = (short int)amplitude*sin(twopiFoverR*n+phase); fputc( (char)((y >> 8) & 0xFF), stdout ); fputc( (char)(y & 0xFF), stdout ); } return 0; }