From cc93c797921f08d48ac8dfc64fefcf7725a84517 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 7 May 2009 21:59:38 +0000 Subject: Calculate SDL buffer size automatically based on sample rate. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1511 --- pcsound/pcsound_sdl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pcsound') diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c index f862dfa7..546e6a36 100644 --- a/pcsound/pcsound_sdl.c +++ b/pcsound/pcsound_sdl.c @@ -32,6 +32,7 @@ #include "pcsound.h" #include "pcsound_internal.h" +#define SOUND_SLICE_TIME 100 /* ms */ #define SQUARE_WAVE_AMP 0x2000 // If true, we initialised SDL and have the responsibility to shut it @@ -165,6 +166,8 @@ static void PCSound_SDL_Shutdown(void) 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 +179,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 = (SOUND_SLICE_TIME * pcsound_sample_rate) / 1000; + + if (Mix_OpenAudio(pcsound_sample_rate, AUDIO_S16SYS, 2, slicesize) < 0) { fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); -- cgit v1.2.3 From e80490d431d940f1e549c3a0426a5815d0be4dbf Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 17 May 2009 13:54:19 +0000 Subject: Always use an SDL buffer size that is a power of two. Reduce buffer size to 70ms. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1524 --- pcsound/pcsound_sdl.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'pcsound') 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) { -- cgit v1.2.3 From cf6e976f371dfe19af0bd3917745698d778586dc Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 7 Jun 2009 16:39:08 +0000 Subject: Add missing SDL_thread include. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1569 --- pcsound/pcsound_win32.c | 1 + 1 file changed, 1 insertion(+) (limited to 'pcsound') 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 #include "pcsound.h" -- cgit v1.2.3 From a91a1c60f544d26195c2df9dd9cd1ef042deacf9 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 8 Jun 2009 18:15:57 +0000 Subject: Use SDL's getenv/putenv implementation, and populate at startup. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1577 --- pcsound/pcsound.c | 1 + 1 file changed, 1 insertion(+) (limited to 'pcsound') diff --git a/pcsound/pcsound.c b/pcsound/pcsound.c index 0746e24e..09ef2752 100644 --- a/pcsound/pcsound.c +++ b/pcsound/pcsound.c @@ -27,6 +27,7 @@ #include #include +#include "SDL_getenv.h" #include "config.h" #include "pcsound.h" #include "pcsound_internal.h" -- cgit v1.2.3 From 3a4db2509420fa89c2ee940cc0998d0d614d63a5 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 11 Jun 2009 18:19:05 +0000 Subject: Include libc_wince.h on Windows CE. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1593 --- pcsound/pcsound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pcsound') diff --git a/pcsound/pcsound.c b/pcsound/pcsound.c index 09ef2752..4695e6e1 100644 --- a/pcsound/pcsound.c +++ b/pcsound/pcsound.c @@ -27,7 +27,10 @@ #include #include -#include "SDL_getenv.h" +#ifdef _WIN32_WCE +#include "libc_wince.h" +#endif + #include "config.h" #include "pcsound.h" #include "pcsound_internal.h" -- cgit v1.2.3