From 4528b9067af1bc7bae6fa46d330bde56247bfb3f Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Thu, 25 Jan 2018 22:48:00 +0100 Subject: [PATCH] Assorted fixes -> works (module timing glitches). --- src/common/AudioQueue.cxx | 1 + src/common/SoundSDL2.cxx | 17 +++++++++-------- src/emucore/tia/AudioChannel.cxx | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/common/AudioQueue.cxx b/src/common/AudioQueue.cxx index 0f12f4244..6156f37f6 100644 --- a/src/common/AudioQueue.cxx +++ b/src/common/AudioQueue.cxx @@ -24,6 +24,7 @@ using std::lock_guard; AudioQueue::AudioQueue(uInt32 fragmentSize, uInt8 capacity, bool isStereo, uInt16 sampleRate) : myFragmentSize(fragmentSize), myIsStereo(isStereo), + mySampleRate(sampleRate), myFragmentQueue(capacity), myAllFragments(capacity + 2), mySize(0), diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index e8d27e92e..f111a86a4 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -45,7 +45,8 @@ SoundSDL2::SoundSDL2(OSystem& osystem) // This fixes a bug most prevalent with ATI video cards in Windows, // whereby sound stopped working after the first video change SDL_AudioSpec desired; - desired.freq = myOSystem.settings().getInt("freq"); + // desired.freq = myOSystem.settings().getInt("freq"); + desired.freq = 48000; desired.format = AUDIO_S16SYS; desired.channels = 2; desired.samples = myOSystem.settings().getInt("fragsize"); @@ -213,17 +214,17 @@ void SoundSDL2::processFragment(Int16* stream, uInt32 length) return; } - bool isStereoTIA = myAudioQueue->isStereo(); - bool isStereo = myHardwareSpec.channels == 2; - uInt32 sampleRateTIA = myAudioQueue->sampleRate(); - uInt32 sampleRate = myHardwareSpec.freq; - uInt32 fragmentSize = myAudioQueue->fragmentSize(); - uInt32 outputSamples = isStereo ? (length >> 1) : length; + const bool isStereoTIA = myAudioQueue->isStereo(); + const bool isStereo = myHardwareSpec.channels == 2; + const uInt32 sampleRateTIA = myAudioQueue->sampleRate(); + const uInt32 sampleRate = myHardwareSpec.freq; + const uInt32 fragmentSize = myAudioQueue->fragmentSize(); + const uInt32 outputSamples = isStereo ? (length >> 1) : length; for (uInt32 i = 0; i < outputSamples; i++) { myTimeIndex += sampleRateTIA; - if (myTimeIndex > sampleRate) { + if (myTimeIndex >= sampleRate) { myFragmentIndex += myTimeIndex / sampleRate; myTimeIndex %= sampleRate; } diff --git a/src/emucore/tia/AudioChannel.cxx b/src/emucore/tia/AudioChannel.cxx index b7e13fa30..a9fe49a5c 100644 --- a/src/emucore/tia/AudioChannel.cxx +++ b/src/emucore/tia/AudioChannel.cxx @@ -139,5 +139,5 @@ void AudioChannel::audv(uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AudioChannel::audf(uInt8 value) { - myAudc = value & 0x1f; + myAudf = value & 0x1f; }