summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2009-10-17 22:45:22 +0000
committerSimon Howard2009-10-17 22:45:22 +0000
commita8e79308562fbcea7a39ed1846329959cbf343b3 (patch)
tree2b34e9b939f3a9d9fe21a671d38017eb3bc08a71
parente30325c40f6ea482862745db0f4555e513f2952e (diff)
downloadchocolate-doom-a8e79308562fbcea7a39ed1846329959cbf343b3.tar.gz
chocolate-doom-a8e79308562fbcea7a39ed1846329959cbf343b3.tar.bz2
chocolate-doom-a8e79308562fbcea7a39ed1846329959cbf343b3.zip
Change GetSliceSize() to always return a power of two.
Subversion-branch: /branches/opl-branch Subversion-revision: 1724
-rw-r--r--opl/opl_sdl.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c
index 2eb8288f..1963d5cd 100644
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -40,6 +40,8 @@
#include "opl_queue.h"
+#define MAX_SOUND_SLICE_TIME 100 /* ms */
+
// When the callback mutex is locked using OPL_Lock, callback functions
// are not invoked.
@@ -277,16 +279,26 @@ static void TimerHandler(int channel, double interval_seconds)
static unsigned int GetSliceSize(void)
{
- unsigned int slicesize;
+ int limit;
+ int n;
+
+ limit = (opl_sample_rate * MAX_SOUND_SLICE_TIME) / 1000;
- slicesize = 1024 * (opl_sample_rate / 11025);
+ // Try all powers of two, not exceeding the limit.
- if (slicesize <= 1024)
+ for (n=0;; ++n)
{
- slicesize = 1024;
+ // 2^n <= limit < 2^n+1 ?
+
+ if ((1 << (n + 1)) > limit)
+ {
+ return (1 << n);
+ }
}
- return slicesize;
+ // Should never happen?
+
+ return 1024;
}
static int OPL_SDL_Init(unsigned int port_base)