diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2024-01-07 12:59:38 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2024-01-07 12:59:38 +0100 |
| commit | 6376a9ccecf911b8ffbcc3dba6e93ecc79ba75fb (patch) | |
| tree | 537529d90d1771e15ffe888bde16d7a18c3313e7 | |
| parent | 33f39cd8ef08db0007c9690992bad99edbaa1795 (diff) | |
fix channel mess
| -rw-r--r-- | include/audio.h | 4 | ||||
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | src/audio.c | 26 |
3 files changed, 7 insertions, 24 deletions
diff --git a/include/audio.h b/include/audio.h index 6414f5a..9ee0bfd 100644 --- a/include/audio.h +++ b/include/audio.h @@ -40,13 +40,11 @@ typedef struct t_audio_event { throwable_type throwable; } audio_event; -#define MAX_AUDIO_EVENTS 20 +#define MAX_AUDIO_EVENTS (NUM_AUDIO_CHANNELS) audio_event audio_events[MAX_AUDIO_EVENTS] = {0}; -bool audio_channel_usage[NUM_AUDIO_CHANNELS] = {0}; int max_audio_events = MAX_AUDIO_EVENTS; void play_music(Mix_Music* music); -void audio_channel_finished(int channel); void add_throwable_audio_event_to_queue(audio_event_type event, throwable_type throwable, u32 playerid, vec3f position); void add_zombie_audio_event_to_queue(audio_event_type event, zombie_type zombie, vec3f position); void add_object_audio_event_to_queue(audio_event_type event, object_type obj, u32 playerid, vec3f position); @@ -104,7 +104,6 @@ int main(int argc, char **argv) if (Mix_AllocateChannels(NUMBER_OF_AUDIO_CHANNELS) == NUM_AUDIO_CHANNELS) { log_info("Audio system initialized."); Mix_MasterVolume(MIX_MAX_VOLUME/4); - Mix_ChannelFinished(audio_channel_finished); } else { log_info("Channel allocation failed."); diff --git a/src/audio.c b/src/audio.c index 4059854..e8b268a 100644 --- a/src/audio.c +++ b/src/audio.c @@ -7,6 +7,7 @@ void add_throwable_audio_event_to_queue(audio_event_type event, throwable_type t audio_events[i] = (audio_event){.active = true, .throwable = throwable, .obj = OBJECT_NONE, .zombie = ZOMBIE_TYPE_NONE, .playerid = playerid, .position = position, .type = event}; return; } + log_info("Audio queue full"); } void add_zombie_audio_event_to_queue(audio_event_type event, zombie_type zombie, vec3f position) { @@ -16,6 +17,7 @@ void add_zombie_audio_event_to_queue(audio_event_type event, zombie_type zombie, audio_events[i] = (audio_event){.active = true, .throwable = THROWABLE_NONE, .obj = OBJECT_NONE, .zombie = zombie, .playerid = -1, .position = position, .type = event}; return; } + log_info("Audio queue full"); } void add_object_audio_event_to_queue(audio_event_type event, object_type obj, u32 playerid, vec3f position) { @@ -25,6 +27,7 @@ void add_object_audio_event_to_queue(audio_event_type event, object_type obj, u3 audio_events[i] = (audio_event){.active = true, .throwable = THROWABLE_NONE, .obj = obj, .zombie = ZOMBIE_TYPE_NONE, .playerid = playerid, .position = position, .type = event}; return; } + log_info("Audio queue full"); } void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position) { @@ -35,17 +38,6 @@ void add_ui_audio_event_to_queue(audio_event_type event) { add_object_audio_event_to_queue(event, OBJECT_NONE, -1, (vec3f){-1,-1,-1}); } -static int get_channel_from_audio_event_type(audio_event_type event) { - for (int i = 0; i < NUM_AUDIO_CHANNELS; i++) { - if (!audio_channel_usage[i]) { - audio_channel_usage[i] = true; - return i; - } - } - log_info("Ran out of audio channels"); - return 0; -} - static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) { player* p = get_player_by_id(playerid); if (!p) return 0; @@ -141,9 +133,7 @@ void play_sounds_in_queue() { audio_events[i].type, audio_events[i].obj, audio_events[i].zombie, audio_events[i].throwable); }*/ - int channel = get_channel_from_audio_event_type(audio_events[i].type); - play_positioned_sound( - channel, sample, audio_events[i].position, 20); + play_positioned_sound(0, sample, audio_events[i].position, 20); } } @@ -157,10 +147,6 @@ void play_sound(int channel, Mix_Chunk* wav) { Mix_PlayChannel(channel, wav, 0); } -void audio_channel_finished(int channel) { - audio_channel_usage[channel] = false; -} - void play_music(Mix_Music* music) { Mix_FadeInMusic(music, -1, 2000); Mix_VolumeMusic(MIX_MAX_VOLUME/6); @@ -186,6 +172,6 @@ void play_positioned_sound(int channel, Mix_Chunk* wav, vec3f pos, float max_aud if (rads > 360) rads -= 360; */ - Mix_SetPosition(channel, 0, (int)(volume*255)); - Mix_PlayChannel(channel, wav, 0); + int c = Mix_PlayChannel(-1, wav, 0); + Mix_SetPosition(c, 0, (int)(volume*255)); } |
