mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-25 16:31:42 +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:
parent
f3c8c57043
commit
9c550c594a
@ -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;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
|
||||
#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<std::list<std::function<void(void)>>> queued_functions = _queued_functions;
|
||||
_queued_functions.reset();
|
||||
_queue->enqueue([queued_functions] {
|
||||
for(auto function : *queued_functions)
|
||||
{
|
||||
function();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
void enqueue(std::function<void(void)> function)
|
||||
{
|
||||
function();
|
||||
// _queue->enqueue(function);
|
||||
}
|
||||
void flush()
|
||||
{
|
||||
// _queue->flush();
|
||||
if(!_queued_functions) _queued_functions.reset(new std::list<std::function<void(void)>>);
|
||||
_queued_functions->push_back(function);
|
||||
}
|
||||
std::shared_ptr<std::list<std::function<void(void)>>> _queued_functions;
|
||||
|
||||
std::unique_ptr<int16_t> _buffer_in_progress;
|
||||
float _high_frequency_cut_off;
|
||||
@ -137,7 +153,7 @@ template <class T> class Filter: public Speaker {
|
||||
public:
|
||||
~Filter()
|
||||
{
|
||||
flush();
|
||||
_queue->flush();
|
||||
}
|
||||
|
||||
void run_for_cycles(unsigned int input_cycles)
|
||||
|
Loading…
Reference in New Issue
Block a user