1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Use std::fill; update volume with slider.

This commit is contained in:
Thomas Harte 2024-02-01 21:32:16 -05:00
parent ce0d53b277
commit fd73c24fc3
2 changed files with 6 additions and 3 deletions

View File

@ -8,19 +8,20 @@
#include "AudioToggle.hpp"
#include <algorithm>
using namespace Audio;
Audio::Toggle::Toggle(Concurrency::AsyncTaskQueue<false> &audio_queue) :
audio_queue_(audio_queue) {}
void Toggle::get_samples(std::size_t number_of_samples, std::int16_t *target) {
for(std::size_t sample = 0; sample < number_of_samples; ++sample) {
target[sample] = level_;
}
std::fill(target, target + number_of_samples, level_);
}
void Toggle::set_sample_volume_range(std::int16_t range) {
volume_ = range;
level_ = level_active_ ? volume_ : 0;
}
void Toggle::skip_samples(std::size_t) {}
@ -29,6 +30,7 @@ void Toggle::set_output(bool enabled) {
if(is_enabled_ == enabled) return;
is_enabled_ = enabled;
audio_queue_.enqueue([this, enabled] {
level_active_ = enabled;
level_ = enabled ? volume_ : 0;
});
}

View File

@ -34,6 +34,7 @@ class Toggle: public Outputs::Speaker::SampleSource {
// Accessed on the audio thread.
int16_t level_ = 0, volume_ = 0;
bool level_active_ = false;
};
}