#include <math.h>
SDL_AudioSpec Desired;
SDL_AudioSpec Obtained;
double Frequency = 440;
SDL_Event tickEvent;

double wave(double t)
{
  return t - abs(t) < 0.5 ? 1 : -1;
}

double _wave(double t)
{
  return cos(t * 2 * 3.14);
}

void callback(void *unused, Uint8 *stream, int len)
{
  int i;
  static unsigned int step= 0;
  Uint16 *frames = (Uint16 *) stream;
  int framesize = len / 2;
  for (i = 0; i < framesize; i++, step++) {
    frames[i]= wave(step * Frequency / Obtained.freq) * 3000;
  }
}

Uint32 windowTimer(Uint32 interval, void *param)
{
  tickEvent.type = SDL_USEREVENT;
  tickEvent.user.code = 0;
  tickEvent.user.data1 = 0;
  tickEvent.user.data2 = 0;
  SDL_PushEvent(&tickEvent);
  return interval;
}
