summaryrefslogtreecommitdiff
path: root/pcsound
diff options
context:
space:
mode:
authorSimon Howard2009-05-21 19:33:16 +0000
committerSimon Howard2009-05-21 19:33:16 +0000
commit46ad00deca23f3c57fcaed47af67f9003d6a4048 (patch)
tree521384626ea446306e5847246194a806fde46fbd /pcsound
parent9eb11191b5ac68764da60c2f583d9c34ac05794e (diff)
parentbd20fc62a36475e7a9fff269784d0f1e5c1128b4 (diff)
downloadchocolate-doom-46ad00deca23f3c57fcaed47af67f9003d6a4048.tar.gz
chocolate-doom-46ad00deca23f3c57fcaed47af67f9003d6a4048.tar.bz2
chocolate-doom-46ad00deca23f3c57fcaed47af67f9003d6a4048.zip
Merge from trunk.
Subversion-branch: /branches/raven-branch Subversion-revision: 1528
Diffstat (limited to 'pcsound')
-rw-r--r--pcsound/pcsound_sdl.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c
index 546e6a36..6ba06785 100644
--- a/pcsound/pcsound_sdl.c
+++ b/pcsound/pcsound_sdl.c
@@ -32,7 +32,7 @@
#include "pcsound.h"
#include "pcsound_internal.h"
-#define SOUND_SLICE_TIME 100 /* ms */
+#define MAX_SOUND_SLICE_TIME 70 /* ms */
#define SQUARE_WAVE_AMP 0x2000
// If true, we initialised SDL and have the responsibility to shut it
@@ -164,6 +164,33 @@ static void PCSound_SDL_Shutdown(void)
}
}
+// 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 = (pcsound_sample_rate * 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 int PCSound_SDL_Init(pcsound_callback_func callback_func)
{
int slicesize;
@@ -179,7 +206,7 @@ static int PCSound_SDL_Init(pcsound_callback_func callback_func)
return 0;
}
- slicesize = (SOUND_SLICE_TIME * pcsound_sample_rate) / 1000;
+ slicesize = GetSliceSize();
if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, slicesize) < 0)
{