Changeset 887:a5d48b62c4fc in roaraudio for roarclients/roarsin.c
- Timestamp:
- 11/19/08 22:29:07 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarsin.c
r669 r887 27 27 #include <roaraudio.h> /* libroar */ 28 28 29 int main (void) { 29 double rect (double x) { 30 x /= 2*M_PI; 31 x -= (int)x; 32 33 if ( x < 0.5 ) 34 return 1; 35 else 36 return -1; 37 } 38 39 double saw (double x) { 40 x /= 2*M_PI; 41 x -= (int)x; 42 43 return 2*x - 1; 44 } 45 46 double tri (double x) { 47 x /= 2*M_PI; 48 x -= (int)x; 49 50 if ( x < 0.5 ) 51 return 4* x - 1; 52 else 53 return -4*(x-0.5) + 1; 54 } 55 56 int main (int argc, char * argv[]) { 30 57 int rate = ROAR_RATE_DEFAULT; 31 int bits = 8;58 int bits = 16; 32 59 int channels = 1; /* mono */ 33 60 int codec = ROAR_CODEC_DEFAULT; 34 61 float freq = 523.2; /* middle C */ 35 float step = M_PI*2*freq/rate; /* how much time per sample we have to encode ... */36 62 float t = 0; /* current time */ 37 63 float length = 5; /* 5 sec */ 64 float step; /* how much time per sample we have to encode ... */ 38 65 int fh; 39 66 int i; 40 char out[1024]; 67 int16_t out[1024]; 68 double (*func)(double x) = sin; 69 70 for (i = 1; i < argc; i++) { 71 if ( !strcmp(argv[i], "--freq") ) { 72 freq = atof(argv[++i]); 73 } else if ( !strcmp(argv[i], "--time") ) { 74 length = atof(argv[++i]); 75 } else if ( !strcmp(argv[i], "--sin") ) { 76 func = sin; 77 } else if ( !strcmp(argv[i], "--saw") ) { 78 func = saw; 79 } else if ( !strcmp(argv[i], "--tri") ) { 80 func = tri; 81 } else { 82 return 2; 83 } 84 } 85 86 step = M_PI*2*freq/rate; 41 87 42 88 if ( (fh = roar_simple_play(rate, channels, bits, codec, NULL, "sine gen")) == -1 ) { … … 47 93 while (t < 2*M_PI*freq*length) { 48 94 for (i = 0; i < 1024; i++) { 49 out[i] = 127*sin(t);95 out[i] = 32767*func(t); 50 96 t += step; 51 97 } 52 write(fh, out, 1024);98 write(fh, out, 2048); 53 99 } 54 100
Note: See TracChangeset
for help on using the changeset viewer.