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
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Electron_SoundGenerator_hpp
|
|
|
|
#define Electron_SoundGenerator_hpp
|
|
|
|
|
2017-12-19 02:39:23 +00:00
|
|
|
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
|
2017-12-18 02:26:06 +00:00
|
|
|
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
|
|
|
|
|
|
|
namespace Electron {
|
|
|
|
|
|
|
|
class SoundGenerator: public ::Outputs::Speaker::SampleSource {
|
|
|
|
public:
|
|
|
|
SoundGenerator(Concurrency::DeferringAsyncTaskQueue &audio_queue);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// To satisfy ::SampleSource.
|
2017-12-18 02:26:06 +00:00
|
|
|
void get_samples(std::size_t number_of_samples, int16_t *target);
|
|
|
|
void skip_samples(std::size_t number_of_samples);
|
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:
|
|
|
|
Concurrency::DeferringAsyncTaskQueue &audio_queue_;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Speaker_hpp */
|