diff --git a/Emulator/Components/Ports/AudioPort.cpp b/Emulator/Components/Ports/AudioPort.cpp index c8ca01577..231545657 100644 --- a/Emulator/Components/Ports/AudioPort.cpp +++ b/Emulator/Components/Ports/AudioPort.cpp @@ -255,10 +255,20 @@ AudioPort::setOption(Option option, i64 value) void AudioPort::setSampleRate(double hz) { - trace(AUD_DEBUG, "setSampleRate(%f)\n", hz); + // Set the sample rate or get it from the detector if none is provided + if (hz != 0.0) { - sampleRate = hz; - filter.setup(hz); + sampleRate = hz; + trace(AUD_DEBUG, "setSampleRate(%.2f)\n", sampleRate); + + } else { + + sampleRate = detector.sampleRate(); + trace(AUD_DEBUG, "setSampleRate(%.2f) (predicted)\n", sampleRate); + } + + // Inform the audio filter about the new sample rate + filter.setup(sampleRate); } void @@ -437,15 +447,14 @@ AudioPort::handleBufferUnderflow() lastAlignment = util::Time::now(); // Adjust the sample rate, if condition (1) holds - // if (elapsedTime.asSeconds() > 10.0) { if (emulator.isRunning() && !emulator.isWarping()) { stats.bufferUnderflows++; warn("Audio buffer underflow after %f seconds\n", elapsedTime.asSeconds()); - // Adjust the sample rate to what we have measured - setSampleRate(detector.sampleRate()); - warn("Ajusted sample rate to %.2f\n", sampleRate); + // Adjust the sample rate + setSampleRate(host.getConfig().sampleRate); + msg("New sample rate = %.2f\n", sampleRate); } } @@ -467,15 +476,14 @@ AudioPort::handleBufferOverflow() lastAlignment = util::Time::now(); // Adjust the sample rate, if condition (1) holds - // if (elapsedTime.asSeconds() > 10.0) { if (emulator.isRunning() && !emulator.isWarping()) { stats.bufferOverflows++; warn("Audio buffer overflow after %f seconds\n", elapsedTime.asSeconds()); - // Adjust the sample rate to what we have measured - setSampleRate(detector.sampleRate()); - warn("Ajusted sample rate to %.2f\n", sampleRate); + // Adjust the sample rate + setSampleRate(host.getConfig().sampleRate); + msg("New sample rate = %.2f\n", sampleRate); } } diff --git a/Emulator/Components/Ports/AudioPort.h b/Emulator/Components/Ports/AudioPort.h index f3dd9884c..738e3f6e9 100644 --- a/Emulator/Components/Ports/AudioPort.h +++ b/Emulator/Components/Ports/AudioPort.h @@ -222,7 +222,6 @@ class AudioPort : public SubComponent { void setOption(Option option, i64 value) override; void setSampleRate(double hz); - // void updateSampleRate(); // diff --git a/Emulator/Utilities/RingBuffer.h b/Emulator/Utilities/RingBuffer.h index 4b7d0185d..e76e6511b 100644 --- a/Emulator/Utilities/RingBuffer.h +++ b/Emulator/Utilities/RingBuffer.h @@ -11,6 +11,7 @@ #include "BasicTypes.h" #include +#include namespace vamiga::util { diff --git a/Emulator/VAmiga.cpp b/Emulator/VAmiga.cpp index 54067f2ce..505439511 100644 --- a/Emulator/VAmiga.cpp +++ b/Emulator/VAmiga.cpp @@ -855,8 +855,6 @@ KeyboardAPI::isPressed(KeyCode key) const void KeyboardAPI::press(KeyCode key, double delay, double duration) { - printf("press(%d) delay: %f duration: %f\n", key, delay, duration); - emu->put(Cmd(CMD_KEY_PRESS, KeyCmd { .keycode = key, .delay = delay })); if (duration != 0.0) { @@ -867,8 +865,6 @@ KeyboardAPI::press(KeyCode key, double delay, double duration) void KeyboardAPI::release(KeyCode key, double delay) { - printf("release(%d) delay: %f\n", key, delay); - emu->put(Cmd(CMD_KEY_RELEASE, KeyCmd { .keycode = key, .delay = delay })); } diff --git a/Emulator/config.cpp b/Emulator/config.cpp index 42caefe6a..c62e83d4a 100644 --- a/Emulator/config.cpp +++ b/Emulator/config.cpp @@ -100,7 +100,7 @@ debugflag WT_DEBUG = 0; // Audio debugflag AUDREG_DEBUG = 0; -debugflag AUD_DEBUG = 0; +debugflag AUD_DEBUG = 1; debugflag AUDBUF_DEBUG = 0; debugflag AUDVOL_DEBUG = 0; debugflag DISABLE_AUDIRQ = 0;