diff options
| author | realtradam <[email protected]> | 2023-05-02 20:45:40 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-05-02 20:45:40 -0400 |
| commit | 87ca456c3f3e97f149604bc033fdd57998e2dcd4 (patch) | |
| tree | b326cacf8e135c939bfc90ba4dd75618cb8598e9 /src | |
| parent | 4b6ae783ce2c9f08d21d2a2969826412cc587de2 (diff) | |
| download | RodeoKit-87ca456c3f3e97f149604bc033fdd57998e2dcd4.tar.gz RodeoKit-87ca456c3f3e97f149604bc033fdd57998e2dcd4.zip | |
added sample audio system
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/rodeo_audio.c | 57 | ||||
| -rw-r--r-- | src/compile_flags.txt | 1 | ||||
| -rw-r--r-- | src/rodeo.c | 7 |
3 files changed, 64 insertions, 1 deletions
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); +} diff --git a/src/compile_flags.txt b/src/compile_flags.txt index 26d1cc4..df3f821 100644 --- a/src/compile_flags.txt +++ b/src/compile_flags.txt @@ -1,6 +1,7 @@ -I./ -I../include -I../external/SDL/include +-I../external/SDL_mixer/include -I../external/bgfx/include -I../external/bx/include -I../external/cglm/include diff --git a/src/rodeo.c b/src/rodeo.c index 71c4666..c6ee71b 100644 --- a/src/rodeo.c +++ b/src/rodeo.c @@ -1,3 +1,4 @@ + // -- internal -- // public #include "rodeo.h" @@ -13,6 +14,7 @@ #endif #include "SDL2/SDL.h" #include "SDL2/SDL_image.h" +#include "SDL2/SDL_mixer.h" #include "SDL2/SDL_syswm.h" #include "bgfx/c99/bgfx.h" /*#define CGLM_FORCE_LEFT_HANDED*/ @@ -44,7 +46,7 @@ rodeo_window_init( "Initializing SDL..." ); - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) { rodeo_log( rodeo_logLevel_error, @@ -241,6 +243,8 @@ rodeo_window_init( state.default_texture.width = 1; state.default_texture.height = 1; + rodeo_audio_initialize(); + state.active_texture_p = &state.default_texture.internal_texture->texture_bgfx; } @@ -260,6 +264,7 @@ rodeo_window_deinit(void) bgfx_shutdown(); SDL_DestroyWindow(state.window); + Mix_Quit(); SDL_Quit(); } |
