From 10a652728f2bc8e5f01aedf97ccc849b8ac686ba Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 31 Aug 2022 14:34:38 -0500 Subject: update example.c and add panning example --- examples/panning.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/panning.c (limited to 'examples/panning.c') diff --git a/examples/panning.c b/examples/panning.c new file mode 100644 index 0000000..7ee9a76 --- /dev/null +++ b/examples/panning.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#define PI 3.14159 + + +#define SAMPLE_RATE 44100 +#define N_CHANNELS 8 + +int main() +{ + float sine_wave[8*SAMPLE_RATE]; + const int frequency = 440; + for (long i=0; i<8*SAMPLE_RATE; i++) { + float time = ((float)i)/SAMPLE_RATE; + sine_wave[i] = sin(2*PI*frequency*time); + } + + struct mossrose_sound_t sound = { + .left = sine_wave, .right = NULL, .mono = true, .len = 8*SAMPLE_RATE + }; + + int err = mossrose_init(SAMPLE_RATE, N_CHANNELS, true); + if (err != 0) + fprintf(stderr, "FAILED TO INITIALIZE MOSSROSE\n"); + + Pa_Sleep(500); + + int chan = mossrose_play(&sound, -1); + + for (int i=0; i<800; i++) { + float time = ((float)i)/100; + mossrose_channel_set_pan(chan, cos(2*PI*time), 0); + Pa_Sleep(10); + } + + mossrose_terminate(); + return 0; +} -- cgit v1.2.1