Created
April 7, 2023 20:40
-
-
Save Aurumaker72/5fa4429f3b3ff2820f76a0a7b12dad3f to your computer and use it in GitHub Desktop.
Raylib sound pool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "sound_pool.h" | |
| t_sound_pool *create_sound_pool(const char *path, int size) { | |
| t_sound_pool * soundPool = (t_sound_pool*)MemAlloc(sizeof(t_sound_pool)); | |
| soundPool->current_index = 0; | |
| soundPool->size = size; | |
| soundPool->sounds = (Sound*)MemAlloc(sizeof(Sound) * size); | |
| for (int i = 0; i < size; ++i) { | |
| soundPool->sounds[i] = LoadSound(path); | |
| } | |
| return soundPool; | |
| } | |
| void sound_pool_play(t_sound_pool* soundPool) { | |
| soundPool->current_index += 1; | |
| if(soundPool->current_index >= soundPool->size) { | |
| soundPool->current_index = 0; | |
| } | |
| PlaySound(soundPool->sounds[soundPool->current_index]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct { | |
| Sound *sounds; | |
| int current_index; | |
| int size; | |
| } typedef t_sound_pool; | |
| t_sound_pool *create_sound_pool(const char *path, int size); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment