Skip to content

Commit

Permalink
Work on audio config panel
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Feb 16, 2025
1 parent 62acf8a commit da93067
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Emulator/VAmiga/Components/Amiga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ Amiga::checkOption(Opt opt, i64 value)

case Opt::AMIGA_RUN_AHEAD:

if (value < 0 || value > 12) {
throw CoreException(CoreError::OPT_INV_ARG, "0...12");
if (value < -7 || value > 7) {
throw CoreException(CoreError::OPT_INV_ARG, "-7...7");
}
return;

Expand Down
4 changes: 2 additions & 2 deletions Emulator/VAmiga/Components/Denise/PixelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ PixelEngine::adjustRGB(u8 &r, u8 &g, u8 &b)
}

const FrameBuffer &
PixelEngine::getStableBuffer(isize delayedFrames) const
PixelEngine::getStableBuffer(isize offset) const
{
auto nr = activeBuffer - delayedFrames - 1;
auto nr = activeBuffer + offset - 1;
return emuTexture[(nr + NUM_TEXTURES) % NUM_TEXTURES];
}

Expand Down
4 changes: 2 additions & 2 deletions Emulator/VAmiga/Components/Denise/PixelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PixelEngine final : public SubComponent {

private:

static constexpr isize NUM_TEXTURES = 2;
static constexpr isize NUM_TEXTURES = 8;

/* The emulator manages textures in a ring buffer to allow access to older
* frames ("run-behind" feature). At any time, one texture serves as the
Expand Down Expand Up @@ -215,7 +215,7 @@ class PixelEngine final : public SubComponent {

// Returns the working buffer or the stable buffer
FrameBuffer &getWorkingBuffer();
const FrameBuffer &getStableBuffer(isize delayedFrames = 0) const;
const FrameBuffer &getStableBuffer(isize offset = 0) const;

// Return a pointer into the pixel storage
Texel *workingPtr(isize row = 0, isize col = 0);
Expand Down
19 changes: 13 additions & 6 deletions Emulator/VAmiga/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,21 @@ Emulator::missingFrames() const
const FrameBuffer &
Emulator::getTexture() const
{
// If paused, display the most recent texture from the main instance
if (!isRunning()) ahead.videoPort.getTexture();
if (isRunning()) {

if (main.config.runAhead > 0) {
return ahead.videoPort.getTexture();
} else {
return main.videoPort.getTexture();
// In run-ahead mode, return the texture from the run-ahead instance
if (main.config.runAhead > 0) {
return ahead.videoPort.getTexture();
}

// In run-behind mode, return a texture from the texture buffer
if (main.config.runAhead < 0) {
return main.videoPort.getTexture(main.config.runAhead);
}
}

// Return the most recent texture from the main instance
return main.videoPort.getTexture();
}

void
Expand Down
4 changes: 2 additions & 2 deletions Emulator/VAmiga/Ports/VideoPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ VideoPort::cacheStats(VideoPortStats &result) const
}

const FrameBuffer &
VideoPort::getTexture() const
VideoPort::getTexture(isize offset) const
{
if (isPoweredOn()) {

auto &result = denise.pixelEngine.getStableBuffer();
auto &result = denise.pixelEngine.getStableBuffer(offset);
info.latestGrabbedFrame = result.nr;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Emulator/VAmiga/Ports/VideoPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VideoPort final : public SubComponent, public Inspectable<VideoPortInfo, V
public:

// Returns a pointer to the stable emulator texture
const class FrameBuffer &getTexture() const;
const class FrameBuffer &getTexture(isize offset = 0) const;

// Informs the video port about a buffer swap
void buffersWillSwap();
Expand Down
14 changes: 11 additions & 3 deletions GUI/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1263,12 +1263,14 @@ extension DefaultsProxy {
remove(.AUD_VOL3)
remove(.AUD_VOLL)
remove(.AUD_VOLR)
remove(.AUD_SAMPLING_METHOD)
remove(.DRIVE_STEP_VOLUME, [0, 1, 2, 3])
remove(.DRIVE_POLL_VOLUME, [0, 1, 2, 3])
remove(.DRIVE_INSERT_VOLUME, [0, 1, 2, 3])
remove(.DRIVE_EJECT_VOLUME, [0, 1, 2, 3])
remove(.AUD_FILTER_TYPE)
remove(.AUD_SAMPLING_METHOD)
remove(.AUD_BUFFER_SIZE)
remove(.AUD_ASR)
}
}

Expand All @@ -1292,7 +1294,6 @@ extension Configuration {
defaults.set(.AUD_PAN3, pan3)
defaults.set(.AUD_VOLL, volL)
defaults.set(.AUD_VOLR, volR)
defaults.set(.AUD_SAMPLING_METHOD, samplingMethod)
defaults.set(.DRIVE_PAN, 0, df0Pan)
defaults.set(.DRIVE_PAN, 1, df1Pan)
defaults.set(.DRIVE_PAN, 2, df2Pan)
Expand All @@ -1306,6 +1307,10 @@ extension Configuration {
defaults.set(.DRIVE_INSERT_VOLUME, [0, 1, 2, 3], insertVolume)
defaults.set(.DRIVE_EJECT_VOLUME, [0, 1, 2, 3], ejectVolume)
defaults.set(.AUD_FILTER_TYPE, filterType)
defaults.set(.AUD_SAMPLING_METHOD, samplingMethod)
defaults.set(.AUD_BUFFER_SIZE, audioBufferSize)
defaults.set(.AUD_ASR, asr)

defaults.save()

amiga.resume()
Expand Down Expand Up @@ -1340,12 +1345,15 @@ extension Configuration {

volL = defaults.get(.AUD_VOLL)
volR = defaults.get(.AUD_VOLR)
samplingMethod = defaults.get(.AUD_SAMPLING_METHOD)
stepVolume = defaults.get(.DRIVE_STEP_VOLUME, 0)
pollVolume = defaults.get(.DRIVE_POLL_VOLUME, 0)
insertVolume = defaults.get(.DRIVE_INSERT_VOLUME, 0)
ejectVolume = defaults.get(.DRIVE_EJECT_VOLUME, 0)
filterType = defaults.get(.AUD_FILTER_TYPE)

samplingMethod = defaults.get(.AUD_SAMPLING_METHOD)
audioBufferSize = defaults.get(.AUD_BUFFER_SIZE, audioBufferSize)
asr = defaults.get(.AUD_ASR, asr)

amiga.resume()
}
Expand Down
29 changes: 23 additions & 6 deletions GUI/Dialogs/Configuration/AudioConf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
extension ConfigurationController {

func refreshAudioTab() {

//
// Mixer
//
Expand All @@ -25,11 +25,11 @@ extension ConfigurationController {
audPan1.integerValue = config.pan1
audPan2.integerValue = config.pan2
audPan3.integerValue = config.pan3

// Out
audVolL.integerValue = config.volL
audVolR.integerValue = config.volR

// Drives
audStepVolume.integerValue = config.stepVolume
audPollVolume.integerValue = config.pollVolume
Expand All @@ -43,10 +43,10 @@ extension ConfigurationController {
audHd1Pan.integerValue = config.hd1Pan
audHd2Pan.integerValue = config.hd2Pan
audHd3Pan.integerValue = config.hd3Pan

// Audio filter
audFilterType.selectItem(withTag: config.filterType)

//
// Sampler
//
Expand All @@ -56,7 +56,24 @@ extension ConfigurationController {
audCapacity.integerValue = config.audioBufferSize
audCapacityText.stringValue = "\(config.audioBufferSize) samples"


switch SamplingMethod(rawValue: Int32(config.samplingMethod)) {
case .NONE:
audSamplingMethodText.stringValue = "Instructs the sampler to select the most recent sample from the ring buffer. This minimizes latency but may introduce jitter when the sample rate fluctuates."
case .NEAREST:
audSamplingMethodText.stringValue = "Instructs the sampler to pick the sample closest to the target timestamp. It improves timing accuracy over the latest-sample method but may still have minor mismatches."
case .LINEAR:
audSamplingMethodText.stringValue = "Instructs the sampler to compute a value between two neighboring samples for smoother output. Increases computation slightly but reduces artifacts and improves fidelity."
default:
break
}

switch (config.asr) {
case 0:
audASRText.stringValue = "Audio samples are synthesized at a constant sampling rate, ignoring drift between emulated and real-time playback rates. This may cause buffer underflows and overflows over time, leading to audio stutter or glitches."
default:
audASRText.stringValue = "ASR (Adaptive Sample Rate) dynamically adjusts the sampling rate to maintain audio sync. This prevents buffer underflows and overflows by adapting to slight drift between emulated and real-time playback rates."
}

//
// Commons
//
Expand Down
2 changes: 2 additions & 0 deletions GUI/Dialogs/Configuration/ConfigurationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ class ConfigurationController: DialogController {

// Mixer
@IBOutlet weak var audSamplingMethod: NSPopUpButton!
@IBOutlet weak var audSamplingMethodText: NSTextField!
@IBOutlet weak var audASR: NSPopUpButton!
@IBOutlet weak var audASRText: NSTextField!
@IBOutlet weak var audCapacity: NSSlider!
@IBOutlet weak var audCapacityText: NSTextField!

Expand Down
Loading

0 comments on commit da93067

Please sign in to comment.