summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2009-11-21 16:54:05 +0000
committerSimon Howard2009-11-21 16:54:05 +0000
commit372ad50b2260e5e03c251ae8442a65bd32334cf6 (patch)
tree5e1aa7338e07273c18c7843554723b16ce194018 /src
parent3d577f70fb8a41a6609db76bdabae30f064a95bc (diff)
downloadchocolate-doom-372ad50b2260e5e03c251ae8442a65bd32334cf6.tar.gz
chocolate-doom-372ad50b2260e5e03c251ae8442a65bd32334cf6.tar.bz2
chocolate-doom-372ad50b2260e5e03c251ae8442a65bd32334cf6.zip
Auto-select SDL slice size based on sample rate.
Subversion-branch: /branches/raven-branch Subversion-revision: 1739
Diffstat (limited to 'src')
-rw-r--r--src/i_sdlsound.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index 3273907e..0b3f8aa3 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -49,6 +49,7 @@
#include "doomtype.h"
#define LOW_PASS_FILTER
+#define MAX_SOUND_SLICE_TIME 70 /* ms */
#define NUM_CHANNELS 16
static boolean sound_initialized = false;
@@ -681,11 +682,37 @@ static void I_SDL_ShutdownSound(void)
sound_initialized = false;
}
+// Calculate slice size, based on MAX_SOUND_SLICE_TIME.
+// The result must be a power of two.
+
+static int GetSliceSize(void)
+{
+ int limit;
+ int n;
+
+ limit = (snd_samplerate * MAX_SOUND_SLICE_TIME) / 1000;
+
+ // Try all powers of two, not exceeding the limit.
+
+ for (n=0;; ++n)
+ {
+ // 2^n <= limit < 2^n+1 ?
+
+ if ((1 << (n + 1)) > limit)
+ {
+ return (1 << n);
+ }
+ }
+
+ // Should never happen?
+
+ return 1024;
+}
static boolean I_SDL_InitSound(boolean _use_sfx_prefix)
-{
+{
int i;
-
+
use_sfx_prefix = _use_sfx_prefix;
// No sounds yet
@@ -701,7 +728,7 @@ static boolean I_SDL_InitSound(boolean _use_sfx_prefix)
return false;
}
- if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, 1024) < 0)
+ if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
{
fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError());
return false;