summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-28 14:21:42 -0500
committersanine <sanine.not@pm.me>2022-08-28 14:21:42 -0500
commitd232fd1b3add3a93b81fc040d8b7e165590930cf (patch)
treec57592f11907ae7ca7a13c7cb47ef752efab47b9 /src/channel.c
parent91726809f9e97d8d4fb7b6c0642234ff96535bdd (diff)
add channel_get_next_sample()
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/channel.c b/src/channel.c
index e6e6c3f..b9242c4 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -26,3 +26,33 @@ void channel_reset(struct channel_t *chan)
chan->pos = 0;
p_atomic_int_set(&(chan->active), false);
}
+
+
+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) {
+ /* skip this channel */
+ *left = 0;
+ *right = 0;
+ return;
+ }
+
+ if (!p_mutex_trylock(chan->sound_mutex)) {
+ /* can't lock mutex, skip */
+ *left = 0;
+ *right = 0;
+ return;
+ }
+
+ *left = chan->sound.left[chan->pos];
+ *right = chan->sound.right[chan->pos];
+ chan->pos += 1;
+
+ if (chan->pos >= chan->sound.len) {
+ channel_reset(chan);
+ }
+
+ p_mutex_unlock(chan->sound_mutex);
+}