2017-12-18 02:26:06 +00:00
|
|
|
//
|
|
|
|
// SoundGenerator.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 03/12/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2017-12-18 02:26:06 +00:00
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2017-12-18 02:26:06 +00:00
|
|
|
|
2024-02-09 19:25:40 +00:00
|
|
|
#include "../../Outputs/Speaker/Implementation/BufferSource.hpp"
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
|
|
|
|
|
|
|
namespace Electron {
|
|
|
|
|
2024-02-09 19:25:40 +00:00
|
|
|
class SoundGenerator: public ::Outputs::Speaker::BufferSource<SoundGenerator, false> {
|
2017-12-18 02:26:06 +00:00
|
|
|
public:
|
2022-07-16 18:41:04 +00:00
|
|
|
SoundGenerator(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
2017-12-18 02:26:06 +00:00
|
|
|
|
|
|
|
void set_divider(uint8_t divider);
|
|
|
|
|
|
|
|
void set_is_enabled(bool is_enabled);
|
|
|
|
|
2019-12-22 05:22:17 +00:00
|
|
|
static constexpr unsigned int clock_rate_divider = 8;
|
2018-03-09 18:23:18 +00:00
|
|
|
|
2024-02-12 18:59:03 +00:00
|
|
|
// For BufferSource.
|
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);
|
2018-03-09 18:23:18 +00:00
|
|
|
void set_sample_volume_range(std::int16_t range);
|
2017-12-18 02:26:06 +00:00
|
|
|
|
|
|
|
private:
|
2022-07-16 18:41:04 +00:00
|
|
|
Concurrency::AsyncTaskQueue<false> &audio_queue_;
|
2017-12-18 02:26:06 +00:00
|
|
|
unsigned int counter_ = 0;
|
|
|
|
unsigned int divider_ = 0;
|
|
|
|
bool is_enabled_ = false;
|
2018-03-09 18:23:18 +00:00
|
|
|
unsigned int volume_ = 0;
|
2017-12-18 02:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|