From 1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Sun, 15 Oct 2023 21:28:29 -0300 Subject: A lot has certainly happened! --- src/gunner/audio_sys.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/gunner/audio_sys.c (limited to 'src/gunner/audio_sys.c') diff --git a/src/gunner/audio_sys.c b/src/gunner/audio_sys.c new file mode 100644 index 0000000..54aba0e --- /dev/null +++ b/src/gunner/audio_sys.c @@ -0,0 +1,134 @@ +// Defines + +#define MAX_SOUND 8 + +static Sound sounds[MAX_SOUND] = {0}; +static s8 sound_paths[MAX_SOUND] = {0}; + +static Music track = {0}; +static s8 music_path = {0}; + +// Audio things + +i32 load_audio(const char* path) +{ + i32 current_idx = BLANK_DEFAULT; + + if(path == NULL) + return current_idx; + + s8 path_str = cstr_to_s8(path); + + for(int i = 0; i < MAX_SOUND; ++i){ + if(equal_s8(path_str, sound_paths[current_idx])){ + free_s8(&path_str); + return i; + } + + if(sounds[i].stream.buffer == NULL){ + current_idx = i; + sounds[i] = LoadSound(path); + sound_paths[i] = path_str; + break; + } + } + + return current_idx; +} + +void play_audio(i32 idx) +{ + assert(idx >= 0 && idx < MAX_SOUND); + PlaySound(sounds[idx]); +} + +void pause_audio(i32 idx) +{ + assert(idx >= 0 && idx < MAX_SOUND); + PauseSound(sounds[idx]); +} + +void resume_audio(i32 idx) +{ + assert(idx >= 0 && idx < MAX_SOUND); + ResumeSound(sounds[idx]); +} + +// Music things // + +void load_music(const char* path) +{ + if(path == NULL) + return; + + s8 path_str = cstr_to_s8(path); + if(equal_s8(path_str, music_path)){ + free_s8(&path_str); + return; + } + + track = LoadMusicStream(path); +} + +void play_music(void) +{ + PlayMusicStream(track); +} + +void set_music_loop(b32 loop) +{ + track.looping = loop; +} + +void set_music_loop_point(f32 point) +{ + track.loopPoint = point; +} + +void pause_music(void) +{ + PauseMusicStream(track); +} + +void resume_music(void) +{ + ResumeMusicStream(track); +} + +// Main funcs + +void set_main_vol(f32 vol) +{ + assert(vol >= 0.f); + SetMasterVolume(vol); +} + +// Update stuff + +void update_audio(void) +{ + UpdateMusicStream(track); +} + +void unload_audio(i32 idx) +{ + StopSound(sounds[idx]); + UnloadSound(sounds[idx]); + free_s8(&sound_paths[idx]); +} + +void unload_active_audio(void) +{ + for(int i = 0; i < MAX_SOUND; ++i){ + if(sounds[i].stream.buffer != NULL){ + unload_audio(i); + } + } +} + +void unload_current_music(void) +{ + StopMusicStream(track); + UnloadMusicStream(track); + free_s8(&music_path); +} \ No newline at end of file -- cgit v1.2.3