1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00
CLK/Components/AudioToggle/AudioToggle.hpp

46 lines
1.1 KiB
C++
Raw Normal View History

//
// AudioToggle.hpp
// Clock Signal
//
// Created by Thomas Harte on 17/04/2018.
// Copyright 2018 Thomas Harte. All rights reserved.
//
#pragma once
#include "../../Outputs/Speaker/Implementation/BufferSource.hpp"
#include "../../Concurrency/AsyncTaskQueue.hpp"
namespace Audio {
/*!
Provides a sample source that can programmatically be set to one of two values.
*/
class Toggle: public Outputs::Speaker::BufferSource<Toggle, false> {
public:
2022-07-16 18:41:04 +00:00
Toggle(Concurrency::AsyncTaskQueue<false> &audio_queue);
template <Outputs::Speaker::Action action>
void apply_samples(std::size_t number_of_samples, Outputs::Speaker::MonoSample *target) {
Outputs::Speaker::fill<action>(target, target + number_of_samples, level_);
}
void set_sample_volume_range(std::int16_t range);
bool is_zero_level() const {
return !level_;
}
void set_output(bool enabled);
2020-05-10 01:22:51 +00:00
bool get_output() const;
private:
2018-04-21 21:56:50 +00:00
// Accessed on the calling thread.
bool is_enabled_ = false;
2022-07-16 18:41:04 +00:00
Concurrency::AsyncTaskQueue<false> &audio_queue_;
2018-04-21 21:56:50 +00:00
// Accessed on the audio thread.
int16_t level_ = 0, volume_ = 0;
bool level_active_ = false;
};
}