1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Moved audio work back into its own thread, but this time it queues up an all happens only upon a flush. Hopefully to resolve synchronisation cost concerns.

This commit is contained in:
Thomas Harte 2016-11-09 21:17:50 -05:00
parent f3c8c57043
commit 9c550c594a
2 changed files with 24 additions and 7 deletions

View File

@ -213,6 +213,7 @@ uint8_t Machine::VIA::get_port_input(Port port)
void Machine::VIA::synchronise() void Machine::VIA::synchronise()
{ {
ay8910->run_for_cycles(_cycles_since_ay_update); ay8910->run_for_cycles(_cycles_since_ay_update);
ay8910->flush();
_cycles_since_ay_update = 0; _cycles_since_ay_update = 0;
} }

View File

@ -12,6 +12,10 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <memory>
#include <list>
#include "../SignalProcessing/Stepper.hpp" #include "../SignalProcessing/Stepper.hpp"
#include "../SignalProcessing/FIRFilter.hpp" #include "../SignalProcessing/FIRFilter.hpp"
#include "../Concurrency/AsyncTaskQueue.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) {} 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<std::list<std::function<void(void)>>> queued_functions = _queued_functions;
_queued_functions.reset();
_queue->enqueue([queued_functions] {
for(auto function : *queued_functions)
{
function();
}
});
}
protected: protected:
void enqueue(std::function<void(void)> function) void enqueue(std::function<void(void)> function)
{ {
function(); if(!_queued_functions) _queued_functions.reset(new std::list<std::function<void(void)>>);
// _queue->enqueue(function); _queued_functions->push_back(function);
}
void flush()
{
// _queue->flush();
} }
std::shared_ptr<std::list<std::function<void(void)>>> _queued_functions;
std::unique_ptr<int16_t> _buffer_in_progress; std::unique_ptr<int16_t> _buffer_in_progress;
float _high_frequency_cut_off; float _high_frequency_cut_off;
@ -137,7 +153,7 @@ template <class T> class Filter: public Speaker {
public: public:
~Filter() ~Filter()
{ {
flush(); _queue->flush();
} }
void run_for_cycles(unsigned int input_cycles) void run_for_cycles(unsigned int input_cycles)