summaryrefslogtreecommitdiff
path: root/src/audio.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 12:34:52 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 12:34:52 +0200
commit5de0682c37fc8e9713bb566a637f19a3795abc4a (patch)
tree3269724b9027205faaa5792262ced3b4f3f064f7 /src/audio.c
parent06d520eb39b2448ee08dce9010651a423115c798 (diff)
prep for synched audio
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/audio.c b/src/audio.c
index ed25d4c..4a10241 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -1,5 +1,71 @@
#include "../include/audio.h"
+void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position) {
+ for (int i = 0; i < max_audio_events; i++) {
+ if (audio_events[i].active) continue;
+
+ audio_events[i] = (audio_event){.active = true, .playerid = playerid, .position = position, .type = event};
+ return;
+ }
+}
+
+static int get_channel_from_audio_event_type(audio_event_type event) {
+ switch (event)
+ {
+ case EVENT_BOUNCE_THROWABLE: return CHANNEL_THROWABLES;
+ case EVENT_SHOOT: return CHANNEL_SHOOTING;
+ case EVENT_RELOAD: return CHANNEL_SHOOTING;
+
+ default: return 0;
+ }
+}
+
+static Mix_Chunk* get_sample_from_audio_event_type(audio_event_type event, u32 playerid) {
+ player* p = get_player_by_id(playerid);
+ if (!p) return 0;
+
+ switch (event)
+ {
+ case EVENT_BOUNCE_THROWABLE: return wav_throwable_bounce;
+ case EVENT_SHOOT: {
+ switch (p->guntype)
+ {
+ case GUN_MP5: return wav_shoot_mp5;
+ default:
+ break;
+ }
+ }
+ case EVENT_RELOAD: {
+ switch (p->guntype)
+ {
+ case GUN_MP5: return wav_reload_mp5;
+ default:
+ break;
+ }
+ }
+
+ default:
+ break;
+ }
+}
+
+void play_sounds_in_queue() {
+ for (int i = 0; i < max_audio_events; i++) {
+ if (!audio_events[i].active) continue;
+
+ play_positioned_sound(
+ get_channel_from_audio_event_type(audio_events[i].type),
+ get_sample_from_audio_event_type(audio_events[i].type, audio_events[i].playerid),
+ audio_events[i].position, 20);
+ }
+}
+
+void clear_sounds_in_queue() {
+ for (int i = 0; i < max_audio_events; i++) {
+ audio_events[i].active = false;
+ }
+}
+
void play_sound(int channel, Mix_Chunk* wav) {
Mix_PlayChannel(channel, wav, 0);
}