diff --git a/src/audio/mockingboard.c b/src/audio/mockingboard.c index bb4bdb62..5baf7e1c 100644 --- a/src/audio/mockingboard.c +++ b/src/audio/mockingboard.c @@ -1033,18 +1033,16 @@ static void MB_Update() nBytesRemaining += g_dwDSBufferSize; // Calc correction factor so that play-buffer doesn't under/overflow - const int nErrorInc = SoundCore_GetErrorInc(); if((unsigned int)nBytesRemaining < g_dwDSBufferSize / 4) - nNumSamplesError += nErrorInc; // < 0.25 of buffer remaining + nNumSamplesError += SOUNDCORE_ERROR_INC; // < 0.25 of buffer remaining else if((unsigned int)nBytesRemaining > g_dwDSBufferSize / 2) - nNumSamplesError -= nErrorInc; // > 0.50 of buffer remaining + nNumSamplesError -= SOUNDCORE_ERROR_INC; // > 0.50 of buffer remaining else nNumSamplesError = 0; // Acceptable amount of data in buffer #ifdef APPLE2IX - const int nErrorMax = SoundCore_GetErrorMax(); // Cap feedback to +/-nMaxError units - if(nNumSamplesError < -nErrorMax) nNumSamplesError = -nErrorMax; - if(nNumSamplesError > nErrorMax) nNumSamplesError = nErrorMax; + if(nNumSamplesError < -SOUNDCORE_ERROR_MAX) nNumSamplesError = -SOUNDCORE_ERROR_MAX; + if(nNumSamplesError > SOUNDCORE_ERROR_MAX) nNumSamplesError = SOUNDCORE_ERROR_MAX; static time_t dbg_print = 0; time_t now = time(NULL); diff --git a/src/audio/soundcore.c b/src/audio/soundcore.c index 0891883d..eeb295a7 100644 --- a/src/audio/soundcore.c +++ b/src/audio/soundcore.c @@ -51,8 +51,6 @@ bool DSGetLock(AudioBuffer_s *pVoice, unsigned long dwOffset, unsigned long dwBy #warning ^^^^ FIXME TODO ... this is opposite the other API methods ... } -//----------------------------------------------------------------------------- - long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels) { AudioParams_s params = { 0 }; @@ -122,7 +120,7 @@ bool audio_init(void) { audio_isAvailable = true; } while (0); - if (num_sound_devices) { + if (num_sound_devices > 0) { char **p = sound_devices; while (*p) { FREE(*p); @@ -143,30 +141,3 @@ void audio_shutdown(void) { audio_isAvailable = false; } -//============================================================================= - -static int g_nErrorInc = 20; // Old: 1 -static int g_nErrorMax = 200; // Old: 50 - -int SoundCore_GetErrorInc(void) -{ - return g_nErrorInc; -} - -void SoundCore_SetErrorInc(const int nErrorInc) -{ - g_nErrorInc = nErrorInc < g_nErrorMax ? nErrorInc : g_nErrorMax; - LOG("Speaker/MB Error Inc = %d", g_nErrorInc); -} - -int SoundCore_GetErrorMax(void) -{ - return g_nErrorMax; -} - -void SoundCore_SetErrorMax(const int nErrorMax) -{ - g_nErrorMax = nErrorMax < MAX_SAMPLES ? nErrorMax : MAX_SAMPLES; - LOG("Speaker/MB Error Max = %d", g_nErrorMax); -} - diff --git a/src/audio/soundcore.h b/src/audio/soundcore.h index fe323165..7907718e 100644 --- a/src/audio/soundcore.h +++ b/src/audio/soundcore.h @@ -21,6 +21,10 @@ #define AUDIO_STATUS_PLAYING 0x00000001 #define AUDIO_STATUS_NOTPLAYING 0x08000000 +// AppleWin-sourced default error increment and max adjustment values ... +#define SOUNDCORE_ERROR_INC 20 +#define SOUNDCORE_ERROR_MAX 200 + typedef struct AudioBuffer_s { bool bActive; // Playback is active bool bMute; @@ -76,11 +80,6 @@ bool DSGetLock(AudioBuffer_s *bufferObj, unsigned long dwOffset, unsigned long d long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels); void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice); -int SoundCore_GetErrorInc(void); -void SoundCore_SetErrorInc(const int nErrorInc); -int SoundCore_GetErrorMax(void); -void SoundCore_SetErrorMax(const int nErrorMax); - /* * Prepare the audio subsystem, including the backend renderer. */ diff --git a/src/audio/speaker.c b/src/audio/speaker.c index aca1762b..e4a4aedc 100644 --- a/src/audio/speaker.c +++ b/src/audio/speaker.c @@ -251,21 +251,18 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) { // calculate CPU cycles feedback adjustment to prevent system audio buffer under/overflow // - const int error_increment = SoundCore_GetErrorInc(); - if (bytes_queued < IDEAL_MIN) { - samples_adjustment_counter += error_increment; // need moar data + samples_adjustment_counter += SOUNDCORE_ERROR_INC; // need moar data } else if (bytes_queued > IDEAL_MAX) { - samples_adjustment_counter -= error_increment; // need less data + samples_adjustment_counter -= SOUNDCORE_ERROR_INC; // need less data } else { samples_adjustment_counter = 0; // Acceptable amount of data in buffer } - const int samples_adjustment_max = SoundCore_GetErrorMax(); // capped to a max/min - if (samples_adjustment_counter < -samples_adjustment_max) { - samples_adjustment_counter = -samples_adjustment_max; - } else if (samples_adjustment_counter > samples_adjustment_max) { - samples_adjustment_counter = samples_adjustment_max; + if (samples_adjustment_counter < -SOUNDCORE_ERROR_MAX) { + samples_adjustment_counter = -SOUNDCORE_ERROR_MAX; + } else if (samples_adjustment_counter > SOUNDCORE_ERROR_MAX) { + samples_adjustment_counter = SOUNDCORE_ERROR_MAX; } cycles_speaker_feedback = (int)(samples_adjustment_counter * cycles_per_sample);