From b7f88e8f610de6b75ad6bfe0f1f658dd2d3929f2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 24 Jul 2017 21:29:13 -0400 Subject: [PATCH] `Filter` is now a `ClockReciever`, affecting all sound output devices. --- Components/6560/6560.hpp | 2 +- Machines/Atari2600/Bus.hpp | 2 +- Machines/Electron/Electron.cpp | 2 +- Machines/Oric/Oric.cpp | 4 ++-- Outputs/Speaker.hpp | 9 +++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index 829df3e7a..8b0c1ad4c 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -408,7 +408,7 @@ template class MOS6560 { std::shared_ptr speaker_; unsigned int cycles_since_speaker_update_; void update_audio() { - speaker_->run_for_cycles(cycles_since_speaker_update_ >> 2); + speaker_->run_for(Cycles((int)cycles_since_speaker_update_ >> 2)); cycles_since_speaker_update_ &= 3; } diff --git a/Machines/Atari2600/Bus.hpp b/Machines/Atari2600/Bus.hpp index 81e0fe5b1..0de25f9fa 100644 --- a/Machines/Atari2600/Bus.hpp +++ b/Machines/Atari2600/Bus.hpp @@ -42,7 +42,7 @@ class Bus { inline void update_audio() { unsigned int audio_cycles = cycles_since_speaker_update_ / (CPUTicksPerAudioTick * 3); cycles_since_speaker_update_ %= (CPUTicksPerAudioTick * 3); - speaker_->run_for_cycles(audio_cycles); + speaker_->run_for(Cycles((int)audio_cycles)); } // video backlog accumulation counter diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index f27e26ce6..f432e052e 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -368,7 +368,7 @@ inline void Machine::update_audio() { if(cycles_since_audio_update_) { unsigned int difference = cycles_since_audio_update_ / Speaker::clock_rate_divider; cycles_since_audio_update_ %= Speaker::clock_rate_divider; - speaker_->run_for_cycles(difference); + speaker_->run_for(Cycles((int)difference)); } } diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 3dd709834..94f70180b 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -235,7 +235,7 @@ uint8_t Machine::VIA::get_port_input(Port port) { } void Machine::VIA::flush() { - ay8910->run_for_cycles(cycles_since_ay_update_); + ay8910->run_for(Cycles((int)cycles_since_ay_update_)); ay8910->flush(); cycles_since_ay_update_ = 0; } @@ -247,7 +247,7 @@ void Machine::VIA::run_for_cycles(unsigned int number_of_cycles) { } void Machine::VIA::update_ay() { - ay8910->run_for_cycles(cycles_since_ay_update_); + ay8910->run_for(Cycles((int)cycles_since_ay_update_)); cycles_since_ay_update_ = 0; ay8910->set_control_lines( (GI::AY38910::ControlLines)((ay_bdir_ ? GI::AY38910::BCDIR : 0) | (ay_bc1_ ? GI::AY38910::BC1 : 0) | GI::AY38910::BC2)); } diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index 4827218d7..e1b263a89 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -20,6 +20,7 @@ #include "../SignalProcessing/Stepper.hpp" #include "../SignalProcessing/FIRFilter.hpp" #include "../Concurrency/AsyncTaskQueue.hpp" +#include "../Components/ClockReceiver.hpp" namespace Outputs { @@ -132,17 +133,17 @@ class Speaker { `get_samples(unsigned int quantity, int16_t *target)` and ideally also `skip_samples(unsigned int quantity)` to provide source data. - Call `run_for_cycles(n)` to request that the next n cycles of input data are collected. + Call `run_for` to request that the next period of input data is collected. */ -template class Filter: public Speaker { +template class Filter: public Speaker, public ClockReceiver> { public: ~Filter() { _queue->flush(); } - void run_for_cycles(unsigned int input_cycles) { + void run_for(const Cycles &cycles) { enqueue([=]() { - unsigned int cycles_remaining = input_cycles; + unsigned int cycles_remaining = (unsigned int)cycles.as_int(); if(coefficients_are_dirty_) update_filter_coefficients(); // if input and output rates exactly match, just accumulate results and pass on