From 63db9380f84cb3eb35d2de430b0783afa5773e85 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 4 Sep 2022 00:39:24 -0500 Subject: implement callbacks --- examples/CMakeLists.txt | 5 +++++ examples/callback.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 examples/callback.c (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7fe2030..aea5060 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,3 +13,8 @@ add_dependencies(examples panning) add_executable(loop ${CMAKE_CURRENT_LIST_DIR}/loop.c) target_link_libraries(loop mossrose) add_dependencies(examples loop) + + +add_executable(callback ${CMAKE_CURRENT_LIST_DIR}/callback.c) +target_link_libraries(callback mossrose) +add_dependencies(examples callback) diff --git a/examples/callback.c b/examples/callback.c new file mode 100644 index 0000000..bf7e187 --- /dev/null +++ b/examples/callback.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#define PI 3.14159 + + +#define SAMPLE_RATE 44100 +#define N_CHANNELS 8 + +float f(float t) +{ + const int f0 = 440; + const int f1 = 880; + return ( t*f1 ) + ( (1-t)*f0 ); +} + + +void callback(int chan, void *d) +{ + bool *loop = d; + *loop = false; + printf("channel %d waves goodnight!\n", chan); +} + + +int main() +{ + float data[SAMPLE_RATE]; + for (long i=0; i