Rev | Line | |
---|
[154] | 1 | //roarsin.c: |
---|
| 2 | |
---|
| 3 | #include <math.h> /* sin() */ |
---|
| 4 | #include <stdio.h> /* *printf*() */ |
---|
| 5 | #include <roaraudio.h> /* libroar */ |
---|
| 6 | |
---|
| 7 | int main (void) { |
---|
| 8 | int rate = ROAR_RATE_DEFAULT; |
---|
| 9 | int bits = 8; |
---|
| 10 | int channels = 1; /* mono */ |
---|
| 11 | int codec = ROAR_CODEC_DEFAULT; |
---|
| 12 | float freq = 523.2; /* middle C */ |
---|
| 13 | float step = M_PI*2*freq/rate; /* how much time per sample we have to encode ... */ |
---|
| 14 | float t = 0; /* current time */ |
---|
| 15 | float length = 5; /* 5 sec */ |
---|
| 16 | int fh; |
---|
| 17 | int i; |
---|
| 18 | char out[1024]; |
---|
| 19 | |
---|
| 20 | if ( (fh = roar_simple_play(rate, channels, bits, codec, NULL, "sine gen")) == -1 ) { |
---|
| 21 | fprintf(stderr, "Error: can not open playback!\n"); |
---|
| 22 | exit(1); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | while (t < 2*M_PI*freq*length) { |
---|
| 26 | for (i = 0; i < 1024; i++) { |
---|
| 27 | out[i] = 127*sin(t); |
---|
| 28 | t += step; |
---|
| 29 | } |
---|
| 30 | write(fh, out, 1024); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | roar_simple_close(fh); |
---|
| 34 | |
---|
| 35 | return 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | //ll |
---|
Note: See
TracBrowser
for help on using the repository browser.