2018-04-18 02:28:13 +00:00
|
|
|
//
|
|
|
|
// AudioToggle.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 17/04/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-04-18 02:28:13 +00:00
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2018-04-18 02:28:13 +00:00
|
|
|
|
2024-02-09 19:25:40 +00:00
|
|
|
#include "../../Outputs/Speaker/Implementation/BufferSource.hpp"
|
2018-04-18 02:28:13 +00:00
|
|
|
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
|
|
|
|
|
|
|
namespace Audio {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a sample source that can programmatically be set to one of two values.
|
|
|
|
*/
|
2024-02-09 19:25:40 +00:00
|
|
|
class Toggle: public Outputs::Speaker::BufferSource<Toggle, false> {
|
2018-04-18 02:28:13 +00:00
|
|
|
public:
|
2022-07-16 18:41:04 +00:00
|
|
|
Toggle(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
2018-04-18 02:28:13 +00:00
|
|
|
|
2024-02-12 15:55:52 +00:00
|
|
|
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_);
|
|
|
|
}
|
2018-04-18 02:28:13 +00:00
|
|
|
void set_sample_volume_range(std::int16_t range);
|
2024-02-13 15:51:33 +00:00
|
|
|
bool is_zero_level() const {
|
|
|
|
return !level_;
|
|
|
|
}
|
2018-04-18 02:28:13 +00:00
|
|
|
|
|
|
|
void set_output(bool enabled);
|
2020-05-10 01:22:51 +00:00
|
|
|
bool get_output() const;
|
2018-04-18 02:28:13 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-21 21:56:50 +00:00
|
|
|
// Accessed on the calling thread.
|
2018-04-18 02:28:13 +00:00
|
|
|
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;
|
2024-02-02 02:32:16 +00:00
|
|
|
bool level_active_ = false;
|
2018-04-18 02:28:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|