Merging the postbeta2 branch onto the mainline.
[platform/upstream/libvorbis.git] / lib / tone.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <math.h>
4
5 void usage(){
6   fprintf(stderr,"tone <frequency_Hz> [<amplitude>]\n");
7   exit(1);
8 }
9
10 int main (int argc,char *argv[]){
11   int i;
12   double f;
13   double amp=32767.;
14
15   if(argc<2)usage();
16   f=atof(argv[1]);
17   if(argc>=3)amp=atof(argv[2])*32767.;
18
19   for(i=0;i<44100*10;i++){
20     long val=rint(amp*sin(i/44100.*f*2*M_PI));
21     if(val>32767.)val=32767.;
22     if(val<-32768.)val=-32768.;
23
24     fprintf(stdout,"%c%c%c%c",
25             (char)(val&0xff),
26             (char)((val>>8)&0xff),
27             (char)(val&0xff),
28             (char)((val>>8)&0xff));
29   }
30   return(0);
31 }
32