mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-09 00:37:27 +00:00
Adopt CRTP for SampleSource.
This commit is contained in:
parent
3827929a15
commit
c6c9be0b08
@ -17,7 +17,7 @@
|
||||
namespace MOS::MOS6560 {
|
||||
|
||||
// audio state
|
||||
class AudioGenerator: public ::Outputs::Speaker::SampleSource {
|
||||
class AudioGenerator: public ::Outputs::Speaker::SampleSource<AudioGenerator> {
|
||||
public:
|
||||
AudioGenerator(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
|
@ -66,7 +66,7 @@ enum class Personality {
|
||||
|
||||
This AY has an attached mono or stereo mixer.
|
||||
*/
|
||||
template <bool stereo> class AY38910: public ::Outputs::Speaker::SampleSource {
|
||||
template <bool stereo> class AY38910: public ::Outputs::Speaker::SampleSource<AY38910<stereo>> {
|
||||
public:
|
||||
/// Creates a new AY38910.
|
||||
AY38910(Personality, Concurrency::AsyncTaskQueue<false> &);
|
||||
|
@ -16,13 +16,14 @@ namespace Audio {
|
||||
/*!
|
||||
Provides a sample source that can programmatically be set to one of two values.
|
||||
*/
|
||||
class Toggle: public Outputs::Speaker::SampleSource {
|
||||
class Toggle: public Outputs::Speaker::SampleSource<Toggle> {
|
||||
public:
|
||||
Toggle(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
void get_samples(std::size_t number_of_samples, std::int16_t *target);
|
||||
void set_sample_volume_range(std::int16_t range);
|
||||
void skip_samples(const std::size_t number_of_samples);
|
||||
static constexpr bool is_stereo = false;
|
||||
|
||||
void set_output(bool enabled);
|
||||
bool get_output() const;
|
||||
|
@ -20,7 +20,7 @@ namespace Konami {
|
||||
and five channels of output. The original SCC uses the same wave for channels
|
||||
four and five, the SCC+ supports different waves for the two channels.
|
||||
*/
|
||||
class SCC: public ::Outputs::Speaker::SampleSource {
|
||||
class SCC: public ::Outputs::Speaker::SampleSource<SCC> {
|
||||
public:
|
||||
/// Creates a new SCC.
|
||||
SCC(Concurrency::AsyncTaskQueue<false> &task_queue);
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
namespace Yamaha::OPL {
|
||||
|
||||
template <typename Child> class OPLBase: public ::Outputs::Speaker::SampleSource {
|
||||
template <typename Child> class OPLBase: public ::Outputs::Speaker::SampleSource<Child> {
|
||||
public:
|
||||
void write(uint16_t address, uint8_t value) {
|
||||
if(address & 1) {
|
||||
|
@ -27,6 +27,7 @@ class OPLL: public OPLBase<OPLL> {
|
||||
/// As per ::SampleSource; provides audio output.
|
||||
void get_samples(std::size_t number_of_samples, std::int16_t *target);
|
||||
void set_sample_volume_range(std::int16_t range);
|
||||
static constexpr bool is_stereo = false;
|
||||
|
||||
// The OPLL is generally 'half' as loud as it's told to be. This won't strictly be true in
|
||||
// rhythm mode, but it's correct for melodic output.
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
namespace TI {
|
||||
|
||||
class SN76489: public Outputs::Speaker::SampleSource {
|
||||
class SN76489: public Outputs::Speaker::SampleSource<SN76489> {
|
||||
public:
|
||||
enum class Personality {
|
||||
SN76489,
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
namespace Apple::IIgs::Sound {
|
||||
|
||||
class GLU: public Outputs::Speaker::SampleSource {
|
||||
class GLU: public Outputs::Speaker::SampleSource<GLU> {
|
||||
public:
|
||||
GLU(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
@ -37,6 +37,7 @@ class GLU: public Outputs::Speaker::SampleSource {
|
||||
void get_samples(std::size_t number_of_samples, std::int16_t *target);
|
||||
void set_sample_volume_range(std::int16_t range);
|
||||
void skip_samples(const std::size_t number_of_samples);
|
||||
static constexpr bool is_stereo = false;
|
||||
|
||||
private:
|
||||
Concurrency::AsyncTaskQueue<false> &audio_queue_;
|
||||
|
@ -23,7 +23,7 @@ namespace Apple::Macintosh {
|
||||
Designed to be clocked at half the rate of the real hardware — i.e.
|
||||
a shade less than 4Mhz.
|
||||
*/
|
||||
class Audio: public ::Outputs::Speaker::SampleSource {
|
||||
class Audio: public ::Outputs::Speaker::SampleSource<Audio> {
|
||||
public:
|
||||
Audio(Concurrency::AsyncTaskQueue<false> &task_queue);
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace Atari2600 {
|
||||
// will give greater resolution to changes in audio state. 1, 2 and 19 are the only divisors of 38.
|
||||
constexpr int CPUTicksPerAudioTick = 2;
|
||||
|
||||
class TIASound: public Outputs::Speaker::SampleSource {
|
||||
class TIASound: public Outputs::Speaker::SampleSource<TIASound> {
|
||||
public:
|
||||
TIASound(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
namespace Electron {
|
||||
|
||||
class SoundGenerator: public ::Outputs::Speaker::SampleSource {
|
||||
class SoundGenerator: public ::Outputs::Speaker::SampleSource<SoundGenerator> {
|
||||
public:
|
||||
SoundGenerator(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
|
@ -26,7 +26,7 @@ enum class Interrupt: uint8_t {
|
||||
/*!
|
||||
Models the audio-production subset of Dave's behaviour.
|
||||
*/
|
||||
class Audio: public Outputs::Speaker::SampleSource {
|
||||
class Audio: public Outputs::Speaker::SampleSource<Audio> {
|
||||
public:
|
||||
Audio(Concurrency::AsyncTaskQueue<false> &audio_queue);
|
||||
|
||||
|
@ -21,9 +21,9 @@ namespace Outputs::Speaker {
|
||||
An owner may optionally assign relative volumes.
|
||||
*/
|
||||
template <typename... T> class CompoundSource:
|
||||
public Outputs::Speaker::SampleSource {
|
||||
public Outputs::Speaker::SampleSource<CompoundSource<T...>> {
|
||||
private:
|
||||
template <typename... S> class CompoundSourceHolder: public Outputs::Speaker::SampleSource {
|
||||
template <typename... S> class CompoundSourceHolder: public Outputs::Speaker::SampleSource<CompoundSourceHolder<S...>> {
|
||||
public:
|
||||
template <bool output_stereo> void get_samples(std::size_t number_of_samples, std::int16_t *target) {
|
||||
std::memset(target, 0, sizeof(std::int16_t) * number_of_samples);
|
||||
|
@ -8,16 +8,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Outputs::Speaker {
|
||||
|
||||
template <bool stereo> struct SampleT;
|
||||
template <> struct SampleT<true> { using type = std::array<std::uint16_t, 2>; };
|
||||
template <> struct SampleT<false> { using type = std::uint16_t; };
|
||||
|
||||
/*!
|
||||
A sample source is something that can provide a stream of audio.
|
||||
This optional base class provides the interface expected to be exposed
|
||||
by the template parameter to LowpassSpeaker.
|
||||
*/
|
||||
template <typename SourceT>
|
||||
class SampleSource {
|
||||
public:
|
||||
/*!
|
||||
@ -54,7 +60,7 @@ class SampleSource {
|
||||
/*!
|
||||
Indicates whether this component will write stereo samples.
|
||||
*/
|
||||
static constexpr bool is_stereo = false;
|
||||
static constexpr bool is_stereo = SourceT::is_stereo;
|
||||
|
||||
/*!
|
||||
Permits a sample source to declare that, averaged over time, it will use only
|
||||
|
Loading…
x
Reference in New Issue
Block a user