#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
  int cnt = 0;
  int i;
  int sr = 44100;
  float freq = 300;
  int per = sr / freq;
  int frames = 256;
  int amp = 30000;
  short * buffer = (short *)malloc(frames * 4);
  
  int fc;
  
  float currs = 0.0;
  float currc = 1.0;
  float sv;
  float cv;
  float nexts;
  float nextc;
  float w;
  float dt;
  
  
  
  
  dt = 1.0f / 44100.0f;
  w = 2 * 3.14159 * freq;
  sv = sin(w*dt);
  cv = cos(w*dt);
  
  
  while(1) {
    for (i = 0; i < (frames*2); i+=2)
      {
	
	w = 2 * 3.14159 * freq;
	sv = sin(w*dt);
	cv = cos(w*dt);
	
	
	nexts = currs * cv + currc * sv;
	nextc = currc * cv - currs * sv;
	currs = nexts;
	currc = nextc;
	
	buffer[i] = amp * currs;
	buffer[i+1] = buffer[i];
	
	
      }
    fc = fwrite(buffer, sizeof(short),(frames*2),stdout);
    
  }
}
