summaryrefslogtreecommitdiff
path: root/audio.h
diff options
context:
space:
mode:
Diffstat (limited to 'audio.h')
-rw-r--r--audio.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/audio.h b/audio.h
new file mode 100644
index 0000000..96dd11e
--- /dev/null
+++ b/audio.h
@@ -0,0 +1,68 @@
+extern i32 load_vorbis(arena_t *arena, sound_t *sounds, const char *filename);
+extern void play_sound(sound_t *sounds, sound_queue_t *queue, sound_queue_node_t *nodes, i32 id);
+
+i32 find_sound(sound_t *sounds, const char *name)
+{
+ for (i32 i = 0; i < MAX_SOUNDS_LOADED; i++) {
+ sound_t *sound = sounds+i;
+ if (streq(sound->name, name))
+ return i;
+ }
+ return -1;
+}
+
+i32 load_sound(sound_t *sounds, sound_t new_sound)
+{
+ assert(sounds);
+
+ i32 i;
+ sound_t *sound;
+ for (i = 0; i < MAX_SOUNDS_LOADED; ++i) {
+ sound = sounds+i;
+ if (!sound->data)
+ break;
+ }
+
+ if (i == MAX_SOUNDS_LOADED) {
+ printf("warning: max sounds loaded\n");
+ return -1;
+ }
+
+ *sound = new_sound;
+
+ return i;
+}
+
+i32 enqueue_sound(sound_queue_t *queue, sound_queue_node_t *nodes, sound_t *sound)
+{
+ if (queue->count == MAX_SOUNDS_PLAYING)
+ return 0;
+
+ sound_queue_node_t *node;
+ for (i32 i = 0; i < MAX_SOUNDS_PLAYING; ++i) {
+ node = nodes+i;
+ if (!node->sound)
+ break;
+ }
+
+ node->sound = sound;
+
+ dllpushfront(queue->first, queue->last, node);
+
+ queue->count++;
+
+ return 1;
+}
+
+sound_t *dequeue_sound(sound_queue_t *queue)
+{
+ if (queue->count == 0)
+ return 0;
+
+ sound_t *sound = queue->first->sound;
+ queue->first->sound = 0;
+ dllremove(queue->first, queue->last, queue->first);
+ queue->count--;
+
+ return sound;
+}