diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index a3a5b7b3c..fc06421a8 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -213,6 +213,7 @@ uint8_t Machine::VIA::get_port_input(Port port) void Machine::VIA::synchronise() { ay8910->run_for_cycles(_cycles_since_ay_update); + ay8910->flush(); _cycles_since_ay_update = 0; } diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index bceeb1d5b..f2830908f 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -12,6 +12,10 @@ #include #include #include + +#include +#include + #include "../SignalProcessing/Stepper.hpp" #include "../SignalProcessing/FIRFilter.hpp" #include "../Concurrency/AsyncTaskQueue.hpp" @@ -87,16 +91,28 @@ class Speaker { Speaker() : _buffer_in_progress_pointer(0), _requested_number_of_taps(0), _high_frequency_cut_off(-1.0), _queue(new Concurrency::AsyncTaskQueue) {} + /*! + Ensures any deferred processing occurs now. + */ + void flush() + { + std::shared_ptr>> queued_functions = _queued_functions; + _queued_functions.reset(); + _queue->enqueue([queued_functions] { + for(auto function : *queued_functions) + { + function(); + } + }); + } + protected: void enqueue(std::function function) { - function(); -// _queue->enqueue(function); - } - void flush() - { -// _queue->flush(); + if(!_queued_functions) _queued_functions.reset(new std::list>); + _queued_functions->push_back(function); } + std::shared_ptr>> _queued_functions; std::unique_ptr _buffer_in_progress; float _high_frequency_cut_off; @@ -137,7 +153,7 @@ template class Filter: public Speaker { public: ~Filter() { - flush(); + _queue->flush(); } void run_for_cycles(unsigned int input_cycles)