diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 10:57:59 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 10:57:59 -0700 |
commit | a04d065e40adbca5694c608331e137a6280795bd (patch) | |
tree | 49834ea2334f40e478d7274d8f965e434464d883 /tests/sdl_audio_mix_channels.c | |
parent | 637ad69e97761fde5ec5dee882b14f3bb49f561e (diff) | |
parent | 7eaba0c3322cd5e44200bedcd070e6d149f413cd (diff) |
Merge pull request #1317 from michaeljbishop/sdl-mixer-sound-leak
SDL mixer sound leak
Diffstat (limited to 'tests/sdl_audio_mix_channels.c')
-rw-r--r-- | tests/sdl_audio_mix_channels.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/sdl_audio_mix_channels.c b/tests/sdl_audio_mix_channels.c new file mode 100644 index 00000000..dd91d594 --- /dev/null +++ b/tests/sdl_audio_mix_channels.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_mixer.h> +#include <assert.h> +#include <emscripten.h> + +static Mix_Chunk *sound = NULL; +static Mix_Chunk *noiseLoop = NULL; +static Mix_Music *music = NULL; + +static int soundChannel = 0; +static int noiseLoopChannel = 0; + +static const int kNumChannels = 40; + +static int loadAndPlay() +{ + return Mix_PlayChannel(-1, sound, -1); +} + +int main(int argc, char **argv) { + SDL_Init(SDL_INIT_AUDIO); + Mix_Init(MIX_INIT_OGG); + + int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these.. + assert(ret == 0); + + Mix_AllocateChannels(kNumChannels); + + sound = Mix_LoadWAV("sound.ogg"); + + // allocate all the channels + for ( int i = 0; i < kNumChannels; i++ ) + { + assert(loadAndPlay() != -1); + } + + // This point, we should have exhausted our channels + + + + + int lastChannel = loadAndPlay(); + +#if EMSCRIPTEN + int result = (lastChannel == -1); + REPORT_RESULT(); +#endif + + assert(lastChannel == -1); + + // force a quit + while(Mix_Init(0)) + Mix_Quit(); + Mix_CloseAudio(); + + return 0; +} + |