Skip to content

Instantly share code, notes, and snippets.

@Aurumaker72
Created April 7, 2023 20:40
Show Gist options
  • Select an option

  • Save Aurumaker72/5fa4429f3b3ff2820f76a0a7b12dad3f to your computer and use it in GitHub Desktop.

Select an option

Save Aurumaker72/5fa4429f3b3ff2820f76a0a7b12dad3f to your computer and use it in GitHub Desktop.
Raylib sound pool
#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]);
}
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