diff options
Diffstat (limited to 'opl/opl_sdl.c')
-rw-r--r-- | opl/opl_sdl.c | 22 |
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) |