1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Adds a sensible is_stereo to the MultiSpeaker.

This commit is contained in:
Thomas Harte 2020-02-16 18:50:34 -05:00
parent 545a6177bb
commit 1e4356f83a
3 changed files with 15 additions and 4 deletions

View File

@ -38,12 +38,22 @@ float MultiSpeaker::get_ideal_clock_rate_in_range(float minimum, float maximum)
} }
void MultiSpeaker::set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) { void MultiSpeaker::set_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) {
is_stereo_ = stereo; stereo_output_ = stereo;
for(const auto &speaker: speakers_) { for(const auto &speaker: speakers_) {
speaker->set_computed_output_rate(cycles_per_second, buffer_size, stereo); speaker->set_computed_output_rate(cycles_per_second, buffer_size, stereo);
} }
} }
bool MultiSpeaker::get_is_stereo() {
// Return as stereo if any subspeaker is stereo.
for(const auto &speaker: speakers_) {
if(speaker->get_is_stereo()) {
return true;
}
}
return false;
}
void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) { void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) {
delegate_ = delegate; delegate_ = delegate;
} }
@ -54,7 +64,7 @@ void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vec
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_); std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_);
if(speaker != front_speaker_) return; if(speaker != front_speaker_) return;
} }
did_complete_samples(this, buffer, is_stereo_); did_complete_samples(this, buffer, stereo_output_);
} }
void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) {

View File

@ -41,6 +41,7 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker:
float get_ideal_clock_rate_in_range(float minimum, float maximum) override; 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_computed_output_rate(float cycles_per_second, int buffer_size, bool stereo) override;
void set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) override; void set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) override;
bool get_is_stereo() override;
private: private:
void speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) final; void speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) final;
@ -52,7 +53,7 @@ class MultiSpeaker: public Outputs::Speaker::Speaker, Outputs::Speaker::Speaker:
Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr; Outputs::Speaker::Speaker::Delegate *delegate_ = nullptr;
std::mutex front_speaker_mutex_; std::mutex front_speaker_mutex_;
bool is_stereo_ = false; bool stereo_output_ = false;
}; };
} }

View File

@ -31,7 +31,7 @@ class Speaker {
/*! /*!
@returns @c true if the device would most ideally output stereo sound; @c false otherwise. @returns @c true if the device would most ideally output stereo sound; @c false otherwise.
*/ */
virtual bool get_is_stereo() { return false; }; virtual bool get_is_stereo() = 0;
/*! /*!
Sets the actual output rate; packets provided to the delegate will conform to these Sets the actual output rate; packets provided to the delegate will conform to these