zenilib: zenilib/jni/external/libvorbis/lib/tone.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tone.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <math.h>
4 #include <string.h>
5
6 void usage(){
7 fprintf(stderr,"tone <frequency_Hz>,[<amplitude>] [<frequency_Hz>,[<amplitude>]...]\n");
8 exit(1);
9 }
10
11 int main (int argc,char *argv[]){
12 int i,j;
13 double *f;
14 double *amp;
15
16 if(argc<2)usage();
17
18 f=alloca(sizeof(*f)*(argc-1));
19 amp=alloca(sizeof(*amp)*(argc-1));
20
21 i=0;
22 while(argv[i+1]){
23 char *pos=strchr(argv[i+1],',');
24
25 f[i]=atof(argv[i+1]);
26 if(pos)
27 amp[i]=atof(pos+1)*32767.f;
28 else
29 amp[i]=32767.f;
30
31 fprintf(stderr,"%g Hz, %g amp\n",f[i],amp[i]);
32
33 i++;
34 }
35
36 for(i=0;i<44100*10;i++){
37 float val=0;
38 int ival;
39 for(j=0;j<argc-1;j++)
40 val+=amp[j]*sin(i/44100.f*f[j]*2*M_PI);
41 ival=rint(val);
42
43 if(ival>32767.f)ival=32767.f;
44 if(ival<-32768.f)ival=-32768.f;
45
46 fprintf(stdout,"%c%c%c%c",
47 (char)(ival&0xff),
48 (char)((ival>>8)&0xff),
49 (char)(ival&0xff),
50 (char)((ival>>8)&0xff));
51 }
52 return(0);
53 }
54
val
GLuint const GLfloat * val
Definition: glew.h:2715
main
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
f
GLclampf f
Definition: glew.h:3390
j
int32_t j
Definition: e_log.c:102
M_PI
#define M_PI
Definition: os.h:45
sin
double sin(double x)
Definition: s_sin.c:56
String.h
i
int i
Definition: pngrutil.c:1377
usage
GLsizeiptr const GLvoid GLenum usage
Definition: glew.h:1667