From 87ca456c3f3e97f149604bc033fdd57998e2dcd4 Mon Sep 17 00:00:00 2001 From: realtradam Date: Tue, 2 May 2023 20:45:40 -0400 Subject: added sample audio system --- src/audio/rodeo_audio.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/audio/rodeo_audio.c (limited to 'src/audio') diff --git a/src/audio/rodeo_audio.c b/src/audio/rodeo_audio.c new file mode 100644 index 0000000..34d0f33 --- /dev/null +++ b/src/audio/rodeo_audio.c @@ -0,0 +1,57 @@ + +// -- internal -- +// public +#include "rodeo/audio.h" +#include "rodeo/log.h" + +// -- external -- +#include "SDL.h" +#include "SDL_mixer.h" + +Mix_Chunk *sample_sound = NULL; + +void +rodeo_audio_initialize(void) +{ + if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) + { + rodeo_log( + rodeo_logLevel_error, + "Failed to initialize SDL Audio. SDL_Error: %s", + SDL_GetError() + ); + } +} + +void +rodeo_audio_deinitialize(void) +{ + Mix_Quit(); +} + +void +rodeo_audio_loadSample(void) +{ + sample_sound = Mix_LoadWAV("assets/sample.wav"); + if(NULL == sample_sound) + { + rodeo_log( + rodeo_logLevel_error, + "Failed to load sound. Mix_Error: %s", + Mix_GetError() + ); + } +} + +void +rodeo_audio_freeSample(void) +{ + Mix_FreeChunk(sample_sound); + sample_sound = NULL; +} + +void +rodeo_audio_playSample(void) +{ + Mix_PlayChannel(-1, sample_sound, 0); +} -- cgit v1.2.3