From f34a9b43469aa748d00461234eac11240cb32f75 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 31 Jul 2020 18:18:19 -0400 Subject: [PATCH] Corrects audio output from the multi-speaker. Specifically: local duplication of the delegate is unnecessary, and leads to confusion. --- .../Implementation/MultiSpeaker.cpp | 17 ++++++++--------- .../Implementation/MultiSpeaker.hpp | 2 -- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp index 445036baa..af84345d1 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.cpp @@ -60,12 +60,9 @@ void MultiSpeaker::set_output_volume(float volume) { } } -void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) { - delegate_ = delegate; -} - void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector &buffer) { - if(!delegate_) return; + auto delegate = delegate_.load(std::memory_order::memory_order_relaxed); + if(!delegate) return; { std::lock_guard lock_guard(front_speaker_mutex_); if(speaker != front_speaker_) return; @@ -74,12 +71,13 @@ void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vec } void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { - if(!delegate_) return; + auto delegate = delegate_.load(std::memory_order::memory_order_relaxed); + if(!delegate) return; { std::lock_guard lock_guard(front_speaker_mutex_); if(speaker != front_speaker_) return; } - delegate_->speaker_did_change_input_clock(this); + delegate->speaker_did_change_input_clock(this); } void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { @@ -87,7 +85,8 @@ void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { std::lock_guard lock_guard(front_speaker_mutex_); front_speaker_ = machine->audio_producer()->get_speaker(); } - if(delegate_) { - delegate_->speaker_did_change_input_clock(this); + auto delegate = delegate_.load(std::memory_order::memory_order_relaxed); + if(delegate) { + delegate->speaker_did_change_input_clock(this); } } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp index f48bc639c..e5946da1a 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiSpeaker.hpp @@ -40,7 +40,6 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker: // Below is the standard Outputs::Speaker::Speaker interface; see there for documentation. float get_ideal_clock_rate_in_range(float minimum, float maximum) override; void set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) override; - void set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) override; bool get_is_stereo() override; void set_output_volume(float) override; @@ -51,7 +50,6 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker: std::vector speakers_; Outputs::Speaker::Speaker *front_speaker_ = nullptr; - Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr; std::mutex front_speaker_mutex_; bool stereo_output_ = false;