/*
 *  printwave.c * WaveAsText 
 *  Created by Christopher Dobrian on Wed Jan 14 2004. 
 *  Modified by CLaire Paterson in Mon Jan 17 2004
 *  The modification in the file allows the user to enter the sample length 
 *  and frequency.  This allows the program to be more versatile and used with a
 *  wider range of waveforms.
 */

#include <stdio.h>
#include <math.h>

#define SAMPLE_RATE	(44100.)
#define TWOPI		(6.283185307179586)
#define	MAXAMP		(1.)


int main(void);

int main(void)
{
    float seconds;
    float frequency;
    float amplitude = MAXAMP;
    float phase = 0.;
    float twopiFoverR;
    float y;                                              // the current sample value
    unsigned long n;                                      // the current sample number
    unsigned long totalsamples; 
   

    printf("Enter the seconds to be sampled: ");          //Obtain length of desired sample
    scanf("%f",&seconds); 
    printf("Enter the frequency to be sampled: ");        //Obtain frequency
    scanf("%f",&frequency); 
       
    totalsamples = (unsigned long)(seconds*SAMPLE_RATE);
    twopiFoverR = TWOPI*frequency/SAMPLE_RATE;
    for( n = 0 ; n < totalsamples ; n++ )
    {
        y = amplitude*sin(twopiFoverR*n+phase);
        fprintf( stdout, "%f\n", y);
    }

      
	return 0;
}
