Calculate SDL buffer size automatically based on sample rate.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1511
This commit is contained in:
Simon Howard 2009-05-07 21:59:38 +00:00
parent 5859134e1c
commit cc93c79792
2 changed files with 11 additions and 3 deletions

View file

@ -32,6 +32,7 @@
#include "pcsound.h" #include "pcsound.h"
#include "pcsound_internal.h" #include "pcsound_internal.h"
#define SOUND_SLICE_TIME 100 /* ms */
#define SQUARE_WAVE_AMP 0x2000 #define SQUARE_WAVE_AMP 0x2000
// If true, we initialised SDL and have the responsibility to shut it // 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) static int PCSound_SDL_Init(pcsound_callback_func callback_func)
{ {
int slicesize;
// Check if SDL_mixer has been opened already // Check if SDL_mixer has been opened already
// If not, we must initialise it now // If not, we must initialise it now
@ -176,7 +179,9 @@ static int PCSound_SDL_Init(pcsound_callback_func callback_func)
return 0; 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()); fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError());

View file

@ -49,6 +49,7 @@
#include "doomdef.h" #include "doomdef.h"
#define LOW_PASS_FILTER #define LOW_PASS_FILTER
#define SOUND_SLICE_TIME 100 /* ms */
#define NUM_CHANNELS 16 #define NUM_CHANNELS 16
static boolean sound_initialised = false; static boolean sound_initialised = false;
@ -666,10 +667,10 @@ static void I_SDL_ShutdownSound(void)
sound_initialised = false; sound_initialised = false;
} }
static boolean I_SDL_InitSound(void) static boolean I_SDL_InitSound(void)
{ {
int i; int i;
int slicesize;
// No sounds yet // No sounds yet
@ -689,7 +690,9 @@ static boolean I_SDL_InitSound(void)
return false; return false;
} }
if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, 1024) < 0) slicesize = (snd_samplerate * SOUND_SLICE_TIME) / 1000;
if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, slicesize) < 0)
{ {
fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError());
return false; return false;