aboutsummaryrefslogtreecommitdiff
path: root/src/gunner/audio_sys.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-10-15 21:28:29 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-10-15 21:28:29 -0300
commit1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 (patch)
treef5d692d046868261275c7430a624c3ea9ed75d3d /src/gunner/audio_sys.c
parenta89f892640cf12f75c7ce18e6e88c70a8d3965ed (diff)
A lot has certainly happened!
Diffstat (limited to 'src/gunner/audio_sys.c')
-rw-r--r--src/gunner/audio_sys.c134
1 files changed, 134 insertions, 0 deletions
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