#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
  short L = 0;
  short R = 0;
  int cnt = 0;
  int i;
  int sr = 44100;
  int freq = 300;
  int amp = 30000;
  int per = sr / freq;
  int frames = 256;
  short * buffer = (short *)malloc(frames * 4);
  int fc;
  while(1) {
    for (i = 0; i < (frames*2); i+=2)
      {
	if (cnt > (per/2))
	  {
	    L = amp;
	    R = amp;
	  }
	else
	  {
	    L = -amp;
	    R = -amp;
	  }
	cnt++; if (cnt >= per) { cnt = 0; }
	buffer[i] = L;
	buffer[i+1] = R;	
      }
    
    fc = fwrite(buffer, sizeof(short),(frames*2),stdout);
    
  }
}
