From 48e6520f6517f196a0a8f39bf86159075ad44c6b Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 31 Aug 2022 14:34:22 -0500 Subject: finish basic implementation --- include/mossrose.h | 6 +++- src/CMakeLists.txt | 1 + src/mossrose.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/include/mossrose.h b/include/mossrose.h index 44d5477..81f71db 100644 --- a/include/mossrose.h +++ b/include/mossrose.h @@ -11,10 +11,14 @@ struct mossrose_sound_t { size_t len; }; -int mossrose_init(double sample_rate, int n_channels); +int mossrose_init(double sample_rate, int n_channels, bool init_plibsys); int mossrose_terminate(); int mossrose_play(struct mossrose_sound_t *sound, int channel); +void mossrose_channel_set_volume(int channel, float volume); +void mossrose_channel_set_pan(int channel, float left, float right); +void mossrose_channel_pause(int channel); +void mossrose_channel_resume(int channel); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cca9610..0453c34 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ project(mossrose) target_sources(mossrose PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mossrose.c ${CMAKE_CURRENT_LIST_DIR}/channel.c + ${CMAKE_CURRENT_LIST_DIR}/sound.c ) diff --git a/src/mossrose.c b/src/mossrose.c index 4babfd7..fb017cd 100644 --- a/src/mossrose.c +++ b/src/mossrose.c @@ -13,26 +13,125 @@ struct mossrose_global_t { } mossrose_global; +static int callback( + const void *input, + void *output, + unsigned long frame_count, + const PaStreamCallbackTimeInfo* time_info, + PaStreamCallbackFlags status_flags, + void *user_data) +{ + float *out = output; + float *left, *right; + float l, r; + + for (int i=0; i= 0) { + /* play on specified channel */ + if (channel_sound_load(mossrose_global.channels + channel, sound, true) == 0) + return channel; + else + return -1; + } + else { + /* play on first available channel */ + for (int i=0; i