summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/channel.c b/src/channel.c
index d039701..62e32fc 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3,6 +3,7 @@
#include <math.h>
#include <plibsys.h>
#include "channel.h"
+#include "sound.h"
void channel_init(struct channel_t *chan)
@@ -23,9 +24,6 @@ void channel_init(struct channel_t *chan)
void channel_reset(struct channel_t *chan)
{
p_atomic_int_set(&(chan->paused), false);
- p_atomic_int_set(&(chan->volume), 255);
- p_atomic_int_set(&(chan->pan_left), -128);
- p_atomic_int_set(&(chan->pan_right), 128);
chan->pos = 0;
p_atomic_int_set(&(chan->active), false);
}
@@ -65,6 +63,38 @@ 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)
+{
+ if (!force && p_atomic_int_get(&(chan->active)))
+ /* active, fail! */
+ return 1;
+
+ p_mutex_lock(chan->sound_mutex);
+ sound_copy(&(chan->sound), sound);
+ chan->pos = 0;
+
+ p_atomic_int_set(&(chan->paused), false);
+
+ if (!force) {
+ /* overwrite channel settings */
+ p_atomic_int_set(&(chan->volume), 255);
+ if (sound->mono) {
+ p_atomic_int_set(&(chan->pan_left), 0);
+ p_atomic_int_set(&(chan->pan_right), 0);
+ }
+ else {
+ /* stereo */
+ p_atomic_int_set(&(chan->pan_left), -128);
+ p_atomic_int_set(&(chan->pan_right), 128);
+ }
+ }
+ p_mutex_unlock(chan->sound_mutex);
+
+ p_atomic_int_set(&(chan->active), true);
+ return 0;
+}
+
+
#define QUARTER_PI 0.785397
static void pan_gain(float *gain_l, float *gain_r, float pan)
{