From cc93c797921f08d48ac8dfc64fefcf7725a84517 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 7 May 2009 21:59:38 +0000 Subject: Calculate SDL buffer size automatically based on sample rate. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1511 --- pcsound/pcsound_sdl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pcsound/pcsound_sdl.c') diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c index f862dfa7..546e6a36 100644 --- a/pcsound/pcsound_sdl.c +++ b/pcsound/pcsound_sdl.c @@ -32,6 +32,7 @@ #include "pcsound.h" #include "pcsound_internal.h" +#define SOUND_SLICE_TIME 100 /* ms */ #define SQUARE_WAVE_AMP 0x2000 // If true, we initialised SDL and have the responsibility to shut it @@ -165,6 +166,8 @@ static void PCSound_SDL_Shutdown(void) static int PCSound_SDL_Init(pcsound_callback_func callback_func) { + int slicesize; + // Check if SDL_mixer has been opened already // If not, we must initialise it now @@ -176,7 +179,9 @@ static int PCSound_SDL_Init(pcsound_callback_func callback_func) return 0; } - if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, 1024) < 0) + slicesize = (SOUND_SLICE_TIME * pcsound_sample_rate) / 1000; + + if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, slicesize) < 0) { fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); -- cgit v1.2.3