diff options
| author | pryazha <pryadeiniv@mail.ru> | 2025-10-12 15:25:23 +0500 |
|---|---|---|
| committer | pryazha <pryadeiniv@mail.ru> | 2025-10-12 15:25:23 +0500 |
| commit | 818f818f583881156eb279c71b1359bf2c4f3580 (patch) | |
| tree | 874e8d2fdc5334bc70925aa87923791f7662ddb8 /audio.h | |
| parent | 3cf987880e384140bf996c37f820ddeea38bc60e (diff) | |
change identation, maybe will change back, add own gl functions loading, and glx example
Diffstat (limited to 'audio.h')
| -rw-r--r-- | audio.h | 91 |
1 files changed, 29 insertions, 62 deletions
@@ -1,68 +1,35 @@ -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); +#ifndef audio_h +#define audio_h -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; -} +struct sound { + struct string name; + u8 *data; + i32 channels; + i32 freq; + i32 bps; + i32 size; +}; -i32 load_sound(sound_t *sounds, sound_t new_sound) -{ - assert(sounds); +struct sound_node { + struct sound *sound; + struct sound_node *next; + struct sound_node *prev; +}; - i32 i; - sound_t *sound; - for (i = 0; i < MAX_SOUNDS_LOADED; ++i) { - sound = sounds+i; - if (!sound->data) - break; - } +struct sound_queue { + i32 count; + struct sound_node *first; + struct sound_node *last; +}; - if (i == MAX_SOUNDS_LOADED) { - printf("warning: max sounds loaded\n"); - return -1; - } +#define max_sound_loaded 1 +#define max_sound_playing 1 - *sound = new_sound; +i32 load_vorbis(struct arena *arena, struct sound *sounds, struct string filename); +void play_sound(struct sound *sounds, struct sound_queue *queue, struct sound_node *nodes, i32 id); +i32 find_sound(struct sound *sounds, const char *name); +i32 load_sound(struct sound *sounds, struct sound new_sound); +i32 enqueue_sound(struct sound_queue *queue, struct sound_node *nodes, struct sound *sound); +struct sound *dequeue_sound(struct sound_queue *queue); - 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; -} +#endif |
