summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/panning.c6
-rw-r--r--src/channel.c87
-rw-r--r--src/channel.h14
-rw-r--r--src/channel.test.c232
-rw-r--r--src/mossrose.c4
5 files changed, 188 insertions, 155 deletions
diff --git a/examples/panning.c b/examples/panning.c
index 7ee9a76..485833a 100644
--- a/examples/panning.c
+++ b/examples/panning.c
@@ -30,10 +30,10 @@ int main()
int chan = mossrose_play(&sound, -1);
- for (int i=0; i<800; i++) {
- float time = ((float)i)/100;
+ for (int i=0; i<8000; i++) {
+ float time = ((float)i)/1000;
mossrose_channel_set_pan(chan, cos(2*PI*time), 0);
- Pa_Sleep(10);
+ Pa_Sleep(1);
}
mossrose_terminate();
diff --git a/src/channel.c b/src/channel.c
index 62e32fc..1d0b63b 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -5,14 +5,16 @@
#include "channel.h"
#include "sound.h"
+#define channel_atomic_get(var) p_atomic_int_get(&(var))
+#define channel_atomic_set(var, value) p_atomic_int_set(&(var), (value))
void channel_init(struct channel_t *chan)
{
- chan->active = false;
- chan->paused = false;
- chan->volume = 255;
- chan->pan_left = -128;
- chan->pan_right = 128;
+ chan->shared.active = false;
+ chan->shared.paused = false;
+ chan->shared.volume = 255;
+ chan->shared.pan_left = -128;
+ chan->shared.pan_right = 128;
chan->sound_mutex = p_mutex_new();
chan->sound.left = NULL;
@@ -23,21 +25,19 @@ void channel_init(struct channel_t *chan)
void channel_reset(struct channel_t *chan)
{
- p_atomic_int_set(&(chan->paused), false);
- chan->pos = 0;
- p_atomic_int_set(&(chan->active), false);
+ p_atomic_int_set(&(chan->shared.active), false);
}
void channel_pause(struct channel_t *chan)
{
- p_atomic_int_set(&(chan->paused), true);
+ p_atomic_int_set(&(chan->shared.paused), true);
}
void channel_resume(struct channel_t *chan)
{
- p_atomic_int_set(&(chan->paused), false);
+ p_atomic_int_set(&(chan->shared.paused), false);
}
@@ -46,7 +46,7 @@ void channel_set_volume(struct channel_t *chan, float volume)
if (volume > 1.0f) volume = 1.0f;
if (volume < 0.0f) volume = 0.0f;
- p_atomic_int_set(&(chan->volume), 255*volume);
+ p_atomic_int_set(&(chan->shared.volume), 255*volume);
}
@@ -58,14 +58,14 @@ void channel_set_pan(struct channel_t *chan, float pan_left, float pan_right)
if (pan_right > 1.0f) pan_right = 1.0f;
if (pan_right < -1.0f) pan_right = -1.0f;
- p_atomic_int_set(&(chan->pan_left), 128*pan_left);
- p_atomic_int_set(&(chan->pan_right), 128*pan_right);
+ p_atomic_int_set(&(chan->shared.pan_left), 128*pan_left);
+ p_atomic_int_set(&(chan->shared.pan_right), 128*pan_right);
}
int channel_sound_load(struct channel_t *chan, struct mossrose_sound_t *sound, bool force)
{
- if (!force && p_atomic_int_get(&(chan->active)))
+ if (!force && channel_atomic_get(chan->shared.active))
/* active, fail! */
return 1;
@@ -73,24 +73,24 @@ int channel_sound_load(struct channel_t *chan, struct mossrose_sound_t *sound, b
sound_copy(&(chan->sound), sound);
chan->pos = 0;
- p_atomic_int_set(&(chan->paused), false);
+ p_atomic_int_set(&(chan->shared.paused), false);
if (!force) {
/* overwrite channel settings */
- p_atomic_int_set(&(chan->volume), 255);
+ p_atomic_int_set(&(chan->shared.volume), 255);
if (sound->mono) {
- p_atomic_int_set(&(chan->pan_left), 0);
- p_atomic_int_set(&(chan->pan_right), 0);
+ p_atomic_int_set(&(chan->shared.pan_left), 0);
+ p_atomic_int_set(&(chan->shared.pan_right), 0);
}
else {
/* stereo */
- p_atomic_int_set(&(chan->pan_left), -128);
- p_atomic_int_set(&(chan->pan_right), 128);
+ p_atomic_int_set(&(chan->shared.pan_left), -128);
+ p_atomic_int_set(&(chan->shared.pan_right), 128);
}
}
p_mutex_unlock(chan->sound_mutex);
- p_atomic_int_set(&(chan->active), true);
+ p_atomic_int_set(&(chan->shared.active), true);
return 0;
}
@@ -104,11 +104,31 @@ static void pan_gain(float *gain_l, float *gain_r, float pan)
}
+void channel_update_shared(struct channel_t *chan)
+{
+ if (channel_atomic_get(chan->shared.paused) || !channel_atomic_get(chan->shared.active))
+ chan->skip = true;
+ else
+ chan->skip = false;
+
+ float vol = ((float)channel_atomic_get(chan->shared.volume))/255;
+
+ float pan_l = ((float)channel_atomic_get(chan->shared.pan_left))/128;
+ float pan_r = ((float)channel_atomic_get(chan->shared.pan_right))/128;
+
+ pan_gain(&(chan->gain_ll), &(chan->gain_lr), pan_l);
+ pan_gain(&(chan->gain_rl), &(chan->gain_rr), pan_r);
+
+ chan->gain_ll *= vol;
+ chan->gain_lr *= vol;
+ chan->gain_rl *= vol;
+ chan->gain_rr *= vol;
+}
+
+
void channel_get_next_sample(float *left, float *right, struct channel_t *chan)
{
- bool active = p_atomic_int_get(&(chan->active));
- bool paused = p_atomic_int_get(&(chan->paused));
- if (!active || paused) {
+ if (chan->skip) {
/* skip this channel */
*left = 0;
*right = 0;
@@ -122,29 +142,18 @@ void channel_get_next_sample(float *left, float *right, struct channel_t *chan)
return;
}
- float volume = ((float)p_atomic_int_get(&(chan->volume)))/255;
-
if (chan->sound.mono) {
float x = chan->sound.left[chan->pos];
- float pan = ((float)p_atomic_int_get(&(chan->pan_left)))/128;
- float gain_l, gain_r;
- pan_gain(&gain_l, &gain_r, pan);
- *left = volume * gain_l * x;
- *right = volume * gain_r * x;
+ *left = chan->gain_ll * x;
+ *right = chan->gain_lr * x;
}
else {
float l, r;
l = chan->sound.left[chan->pos];
r = chan->sound.right[chan->pos];
- float pan_l = ((float)p_atomic_int_get(&(chan->pan_left)))/128;
- float pan_r = ((float)p_atomic_int_get(&(chan->pan_right)))/128;
- float gain_ll, gain_lr, gain_rl, gain_rr;
- pan_gain(&gain_ll, &gain_lr, pan_l);
- pan_gain(&gain_rl, &gain_rr, pan_r);
-
- *left = volume * ((gain_ll * l) + (gain_rl * r));
- *right = volume * ((gain_lr * l) + (gain_rr * r));
+ *left = (chan->gain_ll * l) + (chan->gain_rl * r);
+ *right = (chan->gain_lr * l) + (chan->gain_rr * r);
}
chan->pos += 1;
diff --git a/src/channel.h b/src/channel.h
index d4ff6ee..ae9c24b 100644
--- a/src/channel.h
+++ b/src/channel.h
@@ -7,12 +7,20 @@
#include <mossrose.h>
-struct channel_t {
+struct channel_shared_t {
volatile pint active; /* boolean */
volatile pint paused; /* boolean */
volatile pint volume; /* 0-255 */
- volatile pint pan_left; /* -128-128 */
- volatile pint pan_right; /* -128-128 */
+ volatile pint pan_left; /* -255-255 */
+ volatile pint pan_right; /* -255-255 */
+};
+
+
+struct channel_t {
+ struct channel_shared_t shared;
+ bool skip;
+ float gain_ll, gain_lr;
+ float gain_rl, gain_rr;
PMutex *sound_mutex;
struct mossrose_sound_t sound;
diff --git a/src/channel.test.c b/src/channel.test.c
index cab741b..4591b43 100644
--- a/src/channel.test.c
+++ b/src/channel.test.c
@@ -59,11 +59,11 @@ void test_channel_init()
lily_assert_int_equal(mock_p_mutex_new->n_calls, 1);
- lily_assert_int_equal(chan.active, false);
- lily_assert_int_equal(chan.paused, false);
- lily_assert_int_equal(chan.volume, 255);
- lily_assert_int_equal(chan.pan_left, -128);
- lily_assert_int_equal(chan.pan_right, 128);
+ lily_assert_int_equal(chan.shared.active, false);
+ lily_assert_int_equal(chan.shared.paused, false);
+ lily_assert_int_equal(chan.shared.volume, 255);
+ lily_assert_int_equal(chan.shared.pan_left, -128);
+ lily_assert_int_equal(chan.shared.pan_right, 128);
lily_assert_null(chan.sound.left);
lily_assert_null(chan.sound.right);
@@ -75,91 +75,89 @@ void test_channel_reset()
{
struct channel_t chan;
chan.pos = 255;
- chan.active = true;
- chan.paused = true;
- chan.volume = 5;
- chan.pan_left = 30;
- chan.pan_right = 30;
+ chan.shared.active = true;
+ chan.shared.paused = true;
+ chan.shared.volume = 5;
+ chan.shared.pan_left = 30;
+ chan.shared.pan_right = 30;
channel_reset(&chan);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
- lily_assert_int_equal(chan.paused, false);
+ lily_assert_int_equal(chan.shared.active, false);
}
void test_channel_pause()
{
struct channel_t chan;
- chan.paused = false;
+ chan.shared.paused = false;
channel_pause(&chan);
- lily_assert_int_equal(chan.paused, true);
+ lily_assert_int_equal(chan.shared.paused, true);
}
void test_channel_resume()
{
struct channel_t chan;
- chan.paused = true;
+ chan.shared.paused = true;
channel_resume(&chan);
- lily_assert_int_equal(chan.paused, false);
+ lily_assert_int_equal(chan.shared.paused, false);
}
void test_channel_set_volume()
{
struct channel_t chan;
- chan.volume = 255;
+ chan.shared.volume = 255;
channel_set_volume(&chan, 0.0f);
- lily_assert_int_equal(chan.volume, 0);
+ lily_assert_int_equal(chan.shared.volume, 0);
channel_set_volume(&chan, 0.5f);
- lily_assert_int_equal(chan.volume, 127);
+ lily_assert_int_equal(chan.shared.volume, 127);
channel_set_volume(&chan, 1.0f);
- lily_assert_int_equal(chan.volume, 255);
+ lily_assert_int_equal(chan.shared.volume, 255);
/* oob */
channel_set_volume(&chan, -1.0f);
- lily_assert_int_equal(chan.volume, 0);
+ lily_assert_int_equal(chan.shared.volume, 0);
channel_set_volume(&chan, 2.0f);
- lily_assert_int_equal(chan.volume, 255);
+ lily_assert_int_equal(chan.shared.volume, 255);
}
void test_channel_set_pan()
{
struct channel_t chan;
- chan.pan_left = 255;
- chan.pan_right = 255;
+ chan.shared.pan_left = 255;
+ chan.shared.pan_right = 255;
channel_set_pan(&chan, -1.0f, 1.0f);
- lily_assert_int_equal(chan.pan_left, -128);
- lily_assert_int_equal(chan.pan_right, 128);
+ lily_assert_int_equal(chan.shared.pan_left, -128);
+ lily_assert_int_equal(chan.shared.pan_right, 128);
channel_set_pan(&chan, -0.5f, 0.5f);
- lily_assert_int_equal(chan.pan_left, -64);
- lily_assert_int_equal(chan.pan_right, 64);
+ lily_assert_int_equal(chan.shared.pan_left, -64);
+ lily_assert_int_equal(chan.shared.pan_right, 64);
channel_set_pan(&chan, 0.0f, 0.0f);
- lily_assert_int_equal(chan.pan_left, 0);
- lily_assert_int_equal(chan.pan_right, 0);
+ lily_assert_int_equal(chan.shared.pan_left, 0);
+ lily_assert_int_equal(chan.shared.pan_right, 0);
channel_set_pan(&chan, 0.5f, -0.5f);
- lily_assert_int_equal(chan.pan_left, 64);
- lily_assert_int_equal(chan.pan_right, -64);
+ lily_assert_int_equal(chan.shared.pan_left, 64);
+ lily_assert_int_equal(chan.shared.pan_right, -64);
channel_set_pan(&chan, 1.0f, -1.0f);
- lily_assert_int_equal(chan.pan_left, 128);
- lily_assert_int_equal(chan.pan_right, -128);
+ lily_assert_int_equal(chan.shared.pan_left, 128);
+ lily_assert_int_equal(chan.shared.pan_right, -128);
/* oob */
channel_set_pan(&chan, -10.0f, 2.0f);
- lily_assert_int_equal(chan.pan_left, -128);
- lily_assert_int_equal(chan.pan_right, 128);
+ lily_assert_int_equal(chan.shared.pan_left, -128);
+ lily_assert_int_equal(chan.shared.pan_right, 128);
channel_set_pan(&chan, 2.0f, -10.0f);
- lily_assert_int_equal(chan.pan_left, 128);
- lily_assert_int_equal(chan.pan_right, -128);
+ lily_assert_int_equal(chan.shared.pan_left, 128);
+ lily_assert_int_equal(chan.shared.pan_right, -128);
}
@@ -177,9 +175,10 @@ void test_channel_sound_load()
sound.len = 3;
struct channel_t chan;
- chan.active = false;
+ chan.shared.active = false;
chan.sound.left = NULL;
chan.sound.right = NULL;
+ chan.pos = 5;
int result = channel_sound_load(&chan, &sound, false);
@@ -187,11 +186,11 @@ void test_channel_sound_load()
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
lily_assert_int_equal(result, 0);
- lily_assert_int_equal(chan.active, true);
- lily_assert_int_equal(chan.paused, false);
- lily_assert_int_equal(chan.volume, 255);
- lily_assert_int_equal(chan.pan_left, -128);
- lily_assert_int_equal(chan.pan_right, 128);
+ lily_assert_int_equal(chan.shared.active, true);
+ lily_assert_int_equal(chan.shared.paused, false);
+ lily_assert_int_equal(chan.shared.volume, 255);
+ lily_assert_int_equal(chan.shared.pan_left, -128);
+ lily_assert_int_equal(chan.shared.pan_right, 128);
lily_assert_memory_equal(chan.sound.left, audio_left, sizeof(audio_left));
lily_assert_memory_equal(chan.sound.right, audio_right, sizeof(audio_right));
@@ -213,7 +212,7 @@ void test_channel_sound_load_mono()
sound.len = 3;
struct channel_t chan;
- chan.active = false;
+ chan.shared.active = false;
chan.sound.left = NULL;
chan.sound.right = NULL;
@@ -223,11 +222,11 @@ void test_channel_sound_load_mono()
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
lily_assert_int_equal(result, 0);
- lily_assert_int_equal(chan.active, true);
- lily_assert_int_equal(chan.paused, false);
- lily_assert_int_equal(chan.volume, 255);
- lily_assert_int_equal(chan.pan_left, 0);
- lily_assert_int_equal(chan.pan_right, 0);
+ lily_assert_int_equal(chan.shared.active, true);
+ lily_assert_int_equal(chan.shared.paused, false);
+ lily_assert_int_equal(chan.shared.volume, 255);
+ lily_assert_int_equal(chan.shared.pan_left, 0);
+ lily_assert_int_equal(chan.shared.pan_right, 0);
lily_assert_memory_equal(chan.sound.left, audio, sizeof(audio));
lily_assert_null(chan.sound.right);
@@ -250,12 +249,12 @@ void test_channel_sound_load_preserve()
sound.len = 3;
struct channel_t chan;
- chan.active = false;
+ chan.shared.active = false;
chan.sound.left = NULL;
chan.sound.right = NULL;
- chan.volume = 127;
- chan.pan_left = 0;
- chan.pan_right = 64;
+ chan.shared.volume = 127;
+ chan.shared.pan_left = 0;
+ chan.shared.pan_right = 64;
int result = channel_sound_load(&chan, &sound, true);
@@ -263,11 +262,11 @@ void test_channel_sound_load_preserve()
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
lily_assert_int_equal(result, 0);
- lily_assert_int_equal(chan.active, true);
- lily_assert_int_equal(chan.paused, false);
- lily_assert_int_equal(chan.volume, 127);
- lily_assert_int_equal(chan.pan_left, 0);
- lily_assert_int_equal(chan.pan_right, 64);
+ lily_assert_int_equal(chan.shared.active, true);
+ lily_assert_int_equal(chan.shared.paused, false);
+ lily_assert_int_equal(chan.shared.volume, 127);
+ lily_assert_int_equal(chan.shared.pan_left, 0);
+ lily_assert_int_equal(chan.shared.pan_right, 64);
lily_assert_memory_equal(chan.sound.left, audio_left, sizeof(audio_left));
lily_assert_memory_equal(chan.sound.right, audio_right, sizeof(audio_right));
@@ -290,11 +289,11 @@ void test_channel_sound_fail()
sound.len = 3;
struct channel_t chan;
- chan.active = true;
- chan.paused = true;
- chan.volume = 2;
- chan.pan_left = 4;
- chan.pan_right = 4;
+ chan.shared.active = true;
+ chan.shared.paused = true;
+ chan.shared.volume = 2;
+ chan.shared.pan_left = 4;
+ chan.shared.pan_right = 4;
chan.sound.left = NULL;
chan.sound.right = NULL;
chan.sound.mono = true;
@@ -306,11 +305,11 @@ void test_channel_sound_fail()
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 0);
lily_assert_int_equal(result, 1);
- lily_assert_int_equal(chan.active, true);
- lily_assert_int_equal(chan.paused, true);
- lily_assert_int_equal(chan.volume, 2);
- lily_assert_int_equal(chan.pan_left, 4);
- lily_assert_int_equal(chan.pan_right, 4);
+ lily_assert_int_equal(chan.shared.active, true);
+ lily_assert_int_equal(chan.shared.paused, true);
+ lily_assert_int_equal(chan.shared.volume, 2);
+ lily_assert_int_equal(chan.shared.pan_left, 4);
+ lily_assert_int_equal(chan.shared.pan_right, 4);
lily_assert_null(chan.sound.left);
lily_assert_null(chan.sound.right);
@@ -326,9 +325,10 @@ void test_channel_get_next_sample_inactive()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = false;
+ chan.shared.active = false;
chan.pos = 0;
float l = 22; float r = 22;
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 0);
@@ -345,10 +345,11 @@ void test_channel_get_next_sample_paused()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = true;
+ chan.shared.active = true;
+ chan.shared.paused = true;
chan.pos = 0;
float l = 22; float r = 22;
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 0);
@@ -365,12 +366,13 @@ void test_channel_get_next_sample_nolock()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
+ chan.shared.active = true;
+ chan.shared.paused = false;
chan.pos = 0;
float l = 22; float r = 22;
lily_store_value(mock_p_mutex_trylock, pboolean, FALSE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 0);
@@ -387,11 +389,11 @@ void test_channel_get_next_sample_normal()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
- chan.volume = 255;
- chan.pan_left = -128;
- chan.pan_right = 128;
+ chan.shared.active = true;
+ chan.shared.paused = false;
+ chan.shared.volume = 255;
+ chan.shared.pan_left = -128;
+ chan.shared.pan_right = 128;
float audio_left[] = { 0.0, 0.5, 1.0 };
float audio_right[] = { 1.0, 0.5, 0.0 };
chan.sound.left = audio_left;
@@ -403,6 +405,7 @@ void test_channel_get_next_sample_normal()
float l, r;
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
@@ -411,6 +414,7 @@ void test_channel_get_next_sample_normal()
lily_assert_float_equal(r, 1.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2);
@@ -419,11 +423,11 @@ void test_channel_get_next_sample_normal()
lily_assert_float_equal(r, 0.5f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
+ lily_assert_int_equal(chan.shared.active, false);
lily_assert_float_equal(l, 1.0f, 0.1f);
lily_assert_float_equal(r, 0.0f, 0.1f);
}
@@ -435,11 +439,11 @@ void test_channel_get_next_sample_volume_0()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
- chan.volume = 0;
- chan.pan_left = -128;
- chan.pan_right = 128;
+ chan.shared.active = true;
+ chan.shared.paused = false;
+ chan.shared.volume = 0;
+ chan.shared.pan_left = -128;
+ chan.shared.pan_right = 128;
float audio_left[] = { 0.0, 0.5, 1.0 };
float audio_right[] = { 1.0, 0.5, 0.0 };
chan.sound.left = audio_left;
@@ -451,6 +455,7 @@ void test_channel_get_next_sample_volume_0()
float l, r;
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
@@ -459,6 +464,7 @@ void test_channel_get_next_sample_volume_0()
lily_assert_float_equal(r, 0.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2);
@@ -467,11 +473,11 @@ void test_channel_get_next_sample_volume_0()
lily_assert_float_equal(r, 0.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
+ lily_assert_int_equal(chan.shared.active, false);
lily_assert_float_equal(l, 0.0f, 0.1f);
lily_assert_float_equal(r, 0.0f, 0.1f);
}
@@ -483,11 +489,11 @@ void test_channel_get_next_sample_mono()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
- chan.volume = 255;
- chan.pan_left = 0;
- chan.pan_right = 128;
+ chan.shared.active = true;
+ chan.shared.paused = false;
+ chan.shared.volume = 255;
+ chan.shared.pan_left = 0;
+ chan.shared.pan_right = 128;
float audio[] = { 0.0, 0.5, 1.0 };
chan.sound.left = audio;
chan.sound.right = NULL;
@@ -500,6 +506,7 @@ void test_channel_get_next_sample_mono()
const float gain = 0.7071; /* constant-power panning center gain */
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
@@ -508,6 +515,7 @@ void test_channel_get_next_sample_mono()
lily_assert_float_equal(r, gain * 0.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2);
@@ -516,11 +524,11 @@ void test_channel_get_next_sample_mono()
lily_assert_float_equal(r, gain * 0.5f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
+ lily_assert_int_equal(chan.shared.active, false);
lily_assert_float_equal(l, gain * 1.0f, 0.1f);
lily_assert_float_equal(r, gain * 1.0f, 0.1f);
}
@@ -532,11 +540,11 @@ void test_channel_get_next_sample_mono_panned()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
- chan.volume = 255;
- chan.pan_left = -128;
- chan.pan_right = 128;
+ chan.shared.active = true;
+ chan.shared.paused = false;
+ chan.shared.volume = 255;
+ chan.shared.pan_left = -128;
+ chan.shared.pan_right = 128;
float audio[] = { 0.0, 0.5, 1.0 };
chan.sound.left = audio;
chan.sound.right = NULL;
@@ -547,6 +555,7 @@ void test_channel_get_next_sample_mono_panned()
float l, r;
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
@@ -555,6 +564,7 @@ void test_channel_get_next_sample_mono_panned()
lily_assert_float_equal(r, 0.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2);
@@ -563,11 +573,11 @@ void test_channel_get_next_sample_mono_panned()
lily_assert_float_equal(r, 0.0f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
+ lily_assert_int_equal(chan.shared.active, false);
lily_assert_float_equal(l, 1.0f, 0.1f);
lily_assert_float_equal(r, 0.0f, 0.1f);
}
@@ -579,11 +589,11 @@ void test_channel_get_next_sample_panned()
lily_mock_use(&mock_p_mutex_unlock);
struct channel_t chan;
- chan.active = true;
- chan.paused = false;
- chan.volume = 255;
- chan.pan_left = 128;
- chan.pan_right = 0;
+ chan.shared.active = true;
+ chan.shared.paused = false;
+ chan.shared.volume = 255;
+ chan.shared.pan_left = 128;
+ chan.shared.pan_right = 0;
float audio_left[] = { 0.2, 0.5, 1.0 };
float audio_right[] = { 1.0, 0.5, 0.2 };
chan.sound.left = audio_left;
@@ -596,6 +606,7 @@ void test_channel_get_next_sample_panned()
const float gain = 0.7071; /* constant-power panning center gain */
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1);
@@ -604,6 +615,7 @@ void test_channel_get_next_sample_panned()
lily_assert_float_equal(r, gain * 1.0f + 0.2f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2);
@@ -612,11 +624,11 @@ void test_channel_get_next_sample_panned()
lily_assert_float_equal(r, gain * 0.5f + 0.5f, 0.1f);
lily_store_value(mock_p_mutex_trylock, pboolean, TRUE);
+ channel_update_shared(&chan);
channel_get_next_sample(&l, &r, &chan);
lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3);
lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3);
- lily_assert_int_equal(chan.pos, 0);
- lily_assert_int_equal(chan.active, false);
+ lily_assert_int_equal(chan.shared.active, false);
lily_assert_float_equal(l, gain * 0.2f, 0.1f);
lily_assert_float_equal(r, gain * 0.2f + 1.0f, 0.1f);
}
diff --git a/src/mossrose.c b/src/mossrose.c
index fb017cd..04770f5 100644
--- a/src/mossrose.c
+++ b/src/mossrose.c
@@ -21,9 +21,13 @@ static int callback(
PaStreamCallbackFlags status_flags,
void *user_data)
{
+ printf("frame count: %d\n", frame_count);
float *out = output;
float *left, *right;
float l, r;
+
+ for (int i=0; i<mossrose_global.n_channels; i++)
+ channel_update_shared(mossrose_global.channels + i);
for (int i=0; i<frame_count; i++) {
left = out + 2*i;