From 818f818f583881156eb279c71b1359bf2c4f3580 Mon Sep 17 00:00:00 2001 From: pryazha Date: Sun, 12 Oct 2025 15:25:23 +0500 Subject: change identation, maybe will change back, add own gl functions loading, and glx example --- audio.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 audio.c (limited to 'audio.c') diff --git a/audio.c b/audio.c new file mode 100644 index 0000000..40d5ac2 --- /dev/null +++ b/audio.c @@ -0,0 +1,71 @@ +#include "audio.h" + +struct sound * +find_sound(struct prge_context ctx, struct string name) +{ + for (i32 i = 0; i < cache.count; i++) { + struct sound *sound = sounds + i; + if (strings_equal(sound->name, name)) + return sound; + } + return 0; +} + +struct sound * +load_sound(struct sound *sounds, struct sound new_sound) +{ + assert(sounds); + + i32 i; + struct sound *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(struct sound_queue *queue, sound_queue_node_t *nodes, struct sound *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; +} + +struct sound *dequeue_sound(struct sound_queue *queue) +{ + if (queue->count == 0) + return 0; + + struct sound *sound = queue->first->sound; + queue->first->sound = 0; + dllremove(queue->first, queue->last, queue->first); + queue->count--; + + return sound; +} + +#endif -- cgit v1.2.3-70-g09d2