From c9c02c277374252bf03fde138f51e44f65d78f87 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 28 Jul 2009 08:10:26 +0000 Subject: [PATCH] git-svn-id: https://svn.eduke32.com/eduke32@1474 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/jaudiolib/src/driver_sdl.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c index 5ad85eb38..d34c27b47 100644 --- a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c +++ b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c @@ -134,9 +134,11 @@ const char *SDLDrv_ErrorString( int32_t ErrorNumber ) int32_t SDLDrv_Init(int32_t mixrate, int32_t numchannels, int32_t samplebits, void * initdata) { - Uint32 inited; + uint32_t inited; int32_t err = 0; + int32_t chunksize; + UNREFERENCED_PARAMETER(numchannels); UNREFERENCED_PARAMETER(initdata); if (Initialised) { @@ -159,11 +161,13 @@ int32_t SDLDrv_Init(int32_t mixrate, int32_t numchannels, int32_t samplebits, vo return SDLErr_Error; } - // same problem occurs here as in the icculus driver... - // we need a dummy channel so we don't fuck up the music - // thus numchannels + 1 here + chunksize = 512; + + if (mixrate >= 16000) chunksize *= 2; + if (mixrate >= 32000) chunksize *= 2; - err = Mix_OpenAudio(mixrate, (samplebits == 8) ? AUDIO_U8 : AUDIO_S16SYS, numchannels + 1, 512); + // allocate 4 channels: 2 for the game's SFX, 1 for music, and 1 for fillData() + err = Mix_OpenAudio(mixrate, (samplebits == 8) ? AUDIO_U8 : AUDIO_S16SYS, 4, chunksize); if (err < 0) { ErrorCode = SDLErr_OpenAudio; @@ -176,10 +180,10 @@ int32_t SDLDrv_Init(int32_t mixrate, int32_t numchannels, int32_t samplebits, vo // dummy channel 2 runs our fillData() callback as an effect Mix_RegisterEffect(2, fillData, NULL, NULL); - DummyBuffer = (uint8_t *) malloc(sizeof(intptr_t)); - memset(DummyBuffer, 0, sizeof(intptr_t)); + DummyBuffer = (uint8_t *) malloc(chunksize); + memset(DummyBuffer, 0, chunksize); - DummyChunk = Mix_QuickLoad_RAW(DummyBuffer, sizeof(intptr_t)); + DummyChunk = Mix_QuickLoad_RAW(DummyBuffer, chunksize); Mix_PlayChannel(2, DummyChunk, -1);