Skip to content

Commit

Permalink
Predict sample rate when OPT_HOST_SAMPLE_RATE is not set by the GUI (…
Browse files Browse the repository at this point in the history
…using the SampleRateDetector)
  • Loading branch information
dirkwhoffmann committed Aug 14, 2024
1 parent a9821b6 commit e651e74
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
30 changes: 19 additions & 11 deletions Emulator/Components/Ports/AudioPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion Emulator/Components/Ports/AudioPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class AudioPort : public SubComponent {
void setOption(Option option, i64 value) override;

void setSampleRate(double hz);
// void updateSampleRate();


//
Expand Down
1 change: 1 addition & 0 deletions Emulator/Utilities/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "BasicTypes.h"
#include <utility>
#include <vector>

namespace vamiga::util {

Expand Down
4 changes: 0 additions & 4 deletions Emulator/VAmiga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }));
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e651e74

Please sign in to comment.