From 2cf000fb7cbe653c2e96e0b3b8f3c1425401d3fc Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 3 Sep 2022 21:32:25 -0500 Subject: add looping --- src/channel.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/channel.c') diff --git a/src/channel.c b/src/channel.c index 1d0b63b..8615265 100644 --- a/src/channel.c +++ b/src/channel.c @@ -25,7 +25,12 @@ void channel_init(struct channel_t *chan) void channel_reset(struct channel_t *chan) { - p_atomic_int_set(&(chan->shared.active), false); + chan->pos = 0; + int loops = channel_atomic_get(chan->shared.loops); + if (loops) { + if (p_atomic_int_dec_and_test(&(chan->shared.loops))) + channel_atomic_set(chan->shared.active, false); + } } @@ -63,7 +68,7 @@ void channel_set_pan(struct channel_t *chan, float pan_left, float pan_right) } -int channel_sound_load(struct channel_t *chan, struct mossrose_sound_t *sound, bool force) +int channel_sound_load(struct channel_t *chan, struct mossrose_sound_t *sound, bool force, int loops) { if (!force && channel_atomic_get(chan->shared.active)) /* active, fail! */ @@ -74,6 +79,7 @@ int channel_sound_load(struct channel_t *chan, struct mossrose_sound_t *sound, b chan->pos = 0; p_atomic_int_set(&(chan->shared.paused), false); + p_atomic_int_set(&(chan->shared.loops), loops); if (!force) { /* overwrite channel settings */ -- cgit v1.2.1