#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

#include "waveio.h"

double float_random(double max);

/*************************************************/
/****** Noise Generation Test Program ************/
/********       By Perry R. Cook      ************/
/********       Princeton U.  2001    ************/
/*************************************************/

int main(int argc,char *argv[])          /* time shift a file */
{
    FILE *wavOut;
    struct soundhdr hdr;
    int i;
    short data;

	if (argc<2) {
        fprintf(stderr,"usage: noise fileout\n");
		exit(0);
    }
        fillheader(&hdr,44100);
        wavOut = opensoundout(argv[1],&hdr);
	if (!wavOut)  {
                printf("Output File Problem!\n");
		exit(0);
	}

        for (i=0;i<44100;i++)   {
		data = (short) (float_random(32000.0) - 16000.0);
    		fwrite(&data,1,2,wavOut);
	}
    closesoundout(wavOut,44100);
    return 1;
}

#define __OS_Win_

// Return random float between 0.0 and max 
// This may break depending on compiler!!
double float_random(double max)     {
  double temp;
  temp = (double) (rand() * max);
  temp /= RAND_MAX;  //  32767.0;
  return temp;
}

