From 2cf000fb7cbe653c2e96e0b3b8f3c1425401d3fc Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 3 Sep 2022 21:32:25 -0500 Subject: add looping --- examples/CMakeLists.txt | 5 +++++ examples/example.c | 6 +++--- examples/loop.c | 40 ++++++++++++++++++++++++++++++++++++++++ examples/panning.c | 2 +- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 examples/loop.c (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 46e02d4..7fe2030 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,3 +8,8 @@ add_dependencies(examples example) add_executable(panning ${CMAKE_CURRENT_LIST_DIR}/panning.c) target_link_libraries(panning mossrose) add_dependencies(examples panning) + + +add_executable(loop ${CMAKE_CURRENT_LIST_DIR}/loop.c) +target_link_libraries(loop mossrose) +add_dependencies(examples loop) diff --git a/examples/example.c b/examples/example.c index 5e65d82..eefc41d 100644 --- a/examples/example.c +++ b/examples/example.c @@ -35,17 +35,17 @@ int main() Pa_Sleep(500); printf("play 1\n"); - mossrose_play(&sound_512, -1); + mossrose_play(&sound_512, -1, 1); printf("wait\n"); Pa_Sleep(1000); printf("play 2\n"); - mossrose_play(&sound_440, -1); + mossrose_play(&sound_440, -1, 1); printf("wait\n"); Pa_Sleep(500); printf("play 3\n"); - mossrose_play(&sound_512, -1); + mossrose_play(&sound_512, -1, 1); printf("wait\n"); Pa_Sleep(1000); diff --git a/examples/loop.c b/examples/loop.c new file mode 100644 index 0000000..1be04a9 --- /dev/null +++ b/examples/loop.c @@ -0,0 +1,40 @@ +#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 ); +} + +int main() +{ + float data[SAMPLE_RATE]; + for (long i=0; i