diff options
Diffstat (limited to 'examples/example.c')
-rw-r--r-- | examples/example.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/examples/example.c b/examples/example.c index 960b9f2..9ae3acc 100644 --- a/examples/example.c +++ b/examples/example.c @@ -1,14 +1,44 @@ +#include <stdio.h> +#include <math.h> #include <mossrose.h> #include <portaudio.h> +#define PI 3.14159 + #define SAMPLE_RATE 44100 #define N_CHANNELS 8 int main() { - mr_init(SAMPLE_RATE, N_CHANNELS); - Pa_Sleep(3000); - mr_terminate(); + float sin1[SAMPLE_RATE]; + const int f1 = 440; + float sin2[SAMPLE_RATE]; + const int f2 = 512; + for (long i=0; i<SAMPLE_RATE; i++) { + float time = ((float)i)/SAMPLE_RATE; + sin1[i] = sin(2*PI*f1*time); + sin2[i] = sin(2*PI*f2*time); + } + mossrose_init(SAMPLE_RATE, N_CHANNELS); + + Pa_Sleep(500); + + printf("play 1\n"); + mossrose_play(sin1, NULL, SAMPLE_RATE, -1); + printf("wait\n"); + Pa_Sleep(1000); + + printf("play 2\n"); + mossrose_play(sin2, NULL, SAMPLE_RATE, -1); + printf("wait\n"); + Pa_Sleep(500); + + printf("play 3\n"); + mossrose_play(NULL, sin1, SAMPLE_RATE, -1); + printf("wait\n"); + Pa_Sleep(1000); + + mossrose_terminate(); return 0; } |