diff options
author | Simon Howard | 2009-07-13 00:52:26 +0000 |
---|---|---|
committer | Simon Howard | 2009-07-13 00:52:26 +0000 |
commit | 480a31094b7621dd7d65ec05a6e36964dca99b66 (patch) | |
tree | 11b218d674e828c12981d819b8f2396b680436df /pcsound | |
parent | 37db69b86bc5052901e250578e9c3920886d79ff (diff) | |
parent | e66653a8a67f3613344ae4ea30b37403d6ff17cf (diff) | |
download | chocolate-doom-480a31094b7621dd7d65ec05a6e36964dca99b66.tar.gz chocolate-doom-480a31094b7621dd7d65ec05a6e36964dca99b66.tar.bz2 chocolate-doom-480a31094b7621dd7d65ec05a6e36964dca99b66.zip |
Merge from trunk.
Subversion-branch: /branches/opl-branch
Subversion-revision: 1624
Diffstat (limited to 'pcsound')
-rw-r--r-- | pcsound/pcsound.c | 4 | ||||
-rw-r--r-- | pcsound/pcsound_sdl.c | 34 | ||||
-rw-r--r-- | pcsound/pcsound_win32.c | 1 |
3 files changed, 38 insertions, 1 deletions
diff --git a/pcsound/pcsound.c b/pcsound/pcsound.c index 0746e24e..4695e6e1 100644 --- a/pcsound/pcsound.c +++ b/pcsound/pcsound.c @@ -27,6 +27,10 @@ #include <stdlib.h> #include <string.h> +#ifdef _WIN32_WCE +#include "libc_wince.h" +#endif + #include "config.h" #include "pcsound.h" #include "pcsound_internal.h" diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c index f862dfa7..6ba06785 100644 --- a/pcsound/pcsound_sdl.c +++ b/pcsound/pcsound_sdl.c @@ -32,6 +32,7 @@ #include "pcsound.h" #include "pcsound_internal.h" +#define MAX_SOUND_SLICE_TIME 70 /* ms */ #define SQUARE_WAVE_AMP 0x2000 // If true, we initialised SDL and have the responsibility to shut it @@ -163,8 +164,37 @@ 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; + // Check if SDL_mixer has been opened already // If not, we must initialise it now @@ -176,7 +206,9 @@ static int PCSound_SDL_Init(pcsound_callback_func callback_func) return 0; } - if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, 1024) < 0) + slicesize = GetSliceSize(); + + if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, slicesize) < 0) { fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); diff --git a/pcsound/pcsound_win32.c b/pcsound/pcsound_win32.c index 7976b444..0eb8cd6a 100644 --- a/pcsound/pcsound_win32.c +++ b/pcsound/pcsound_win32.c @@ -26,6 +26,7 @@ #ifdef _WIN32 #include "SDL.h" +#include "SDL_thread.h" #include <windows.h> #include "pcsound.h" |