summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channel.c24
-rw-r--r--src/channel.h18
-rw-r--r--src/channel.test.c58
-rw-r--r--src/test/mossrose-test.c2
4 files changed, 100 insertions, 2 deletions
diff --git a/src/channel.c b/src/channel.c
index fd6741b..e6e6c3f 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -4,5 +4,25 @@
#include "channel.h"
-struct channel_t {
-};
+void channel_init(struct channel_t *chan)
+{
+ chan->active = false;
+ chan->paused = false;
+ chan->volume = 255;
+ chan->pan = 0;
+
+ chan->sound_mutex = p_mutex_new();
+ chan->sound.left = NULL;
+ chan->sound.right = NULL;
+ chan->pos = 0;
+}
+
+
+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), 0);
+ chan->pos = 0;
+ p_atomic_int_set(&(chan->active), false);
+}
diff --git a/src/channel.h b/src/channel.h
index 6266a10..4d0800b 100644
--- a/src/channel.h
+++ b/src/channel.h
@@ -2,7 +2,25 @@
#define MOSSROSE_CHANNEL_H
#include <stddef.h>
+#include <stdbool.h>
#include <plibsys.h>
+#include <mossrose.h>
+
+
+struct channel_t {
+ volatile pint active; /* boolean */
+ volatile pint paused; /* boolean */
+ volatile pint volume; /* 0-255 */
+ volatile pint pan; /* -128-127 */
+
+ PMutex *sound_mutex;
+ struct mossrose_sound_t sound;
+ size_t pos;
+};
+
+
+void channel_init(struct channel_t *chan);
+void channel_reset(struct channel_t *chan);
#endif
diff --git a/src/channel.test.c b/src/channel.test.c
index 96b7364..e7f7e06 100644
--- a/src/channel.test.c
+++ b/src/channel.test.c
@@ -1,6 +1,64 @@
#include "test/mossrose-test.h"
+#include <plibsys.h>
+
+PMutex * mock_p_mutex_new_();
+
+#define p_mutex_new mock_p_mutex_new_
+#include "channel.c"
+#undef p_mutex_new
+
+
+lily_mock_t *mock_p_mutex_new = NULL;
+PMutex * mock_p_mutex_new_()
+{
+ mock_p_mutex_new->n_calls += 1;
+ return p_mutex_new();
+}
+
+
+void test_channel_init()
+{
+ lily_mock_use(&mock_p_mutex_new);
+
+ struct channel_t chan;
+ channel_init(&chan);
+
+ 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, 0);
+
+ lily_assert_null(chan.sound.left);
+ lily_assert_null(chan.sound.right);
+ lily_assert_int_equal(chan.pos, 0);
+}
+
+
+void test_channel_reset()
+{
+ struct channel_t chan;
+ chan.pos = 255;
+ chan.active = true;
+ chan.paused = true;
+ chan.volume = 5;
+ chan.pan = 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.volume, 255);
+ lily_assert_int_equal(chan.pan, 0);
+}
void suite_channel()
{
+ lily_run_test(test_channel_init);
+ lily_run_test(test_channel_reset);
+
+ lily_mock_destroy(mock_p_mutex_new);
}
diff --git a/src/test/mossrose-test.c b/src/test/mossrose-test.c
index 88ce5ff..e71fc2a 100644
--- a/src/test/mossrose-test.c
+++ b/src/test/mossrose-test.c
@@ -1,8 +1,10 @@
+#include <plibsys.h>
#include "mossrose-test.h"
int main()
{
+ p_libsys_init();
RUN_TESTS()
return 0;
}