From 06b6f85d5512d3ca6edad32856e9ef97fc4addf2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 2 Dec 2021 11:15:29 -0500 Subject: [PATCH] Correct stereo. --- Machines/Amiga/Audio.cpp | 18 +++++++++++------- Machines/Amiga/Audio.hpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Machines/Amiga/Audio.cpp b/Machines/Amiga/Audio.cpp index 4ee065e24..68a5ec48b 100644 --- a/Machines/Amiga/Audio.cpp +++ b/Machines/Amiga/Audio.cpp @@ -93,21 +93,25 @@ void Audio::output() { } } - // TEMPORARY: just fill the audio buffer with silence. + // Spin until the next buffer is available if just entering it for the first time. + // Contention here should be essentially non-existent. if(!sample_pointer_) { while(!buffer_available_[buffer_pointer_].load(std::memory_order::memory_order_relaxed)); } + // Left. buffer_[buffer_pointer_][sample_pointer_] = int16_t( ( - int8_t(channels_[0].output_level) * channels_[0].output_enabled + - int8_t(channels_[2].output_level) * channels_[2].output_enabled + channels_[1].output_level * channels_[1].output_enabled + + channels_[2].output_level * channels_[2].output_enabled ) << 7 ); + + // Right. buffer_[buffer_pointer_][sample_pointer_+1] = int16_t( ( - int8_t(channels_[1].output_level) * channels_[1].output_enabled + - int8_t(channels_[3].output_level) * channels_[3].output_enabled + channels_[0].output_level * channels_[0].output_enabled + + channels_[3].output_level * channels_[3].output_enabled ) << 7 ); sample_pointer_ += 2; @@ -445,7 +449,7 @@ template <> bool Audio::Channel::output() { } // Output high byte. - output_level = data_latch >> 8; + output_level = int8_t(data_latch >> 8); return false; } @@ -490,7 +494,7 @@ template <> bool Audio::Channel::output() { } // Output low byte. - output_level = data_latch & 0xff; + output_level = int8_t(data_latch & 0xff); return false; } diff --git a/Machines/Amiga/Audio.hpp b/Machines/Amiga/Audio.hpp index 84b2562bd..06db57965 100644 --- a/Machines/Amiga/Audio.hpp +++ b/Machines/Amiga/Audio.hpp @@ -105,7 +105,7 @@ class Audio: public DMADevice<4> { template bool transit(); // Output state. - uint8_t output_level = 0; + int8_t output_level = 0; uint8_t output_phase = 0; bool output_enabled = false; } channels_[4];