1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-17 13:29:02 +00:00
CLK/OSBindings/Qt/mainwindow.h
Thomas Harte d9f02aecdf Adds an additional buffer. To reduce latency. No, really.
Specifically: there's no way to guarantee no overbuffering due to the startup race, other than having QAudioOutput obtain data by pull rather than push. But if it's pulling then that implies an extra buffer. And since the sizes it may pull are not explicit, there's guesswork involved there.

So: no extra buffer => uncontrollable risk of over-buffering. Extra buffer => a controllable risk of over-buffering.
2020-06-09 00:01:22 -04:00

65 lines
1.5 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QAudioOutput>
#include <QMainWindow>
#include <memory>
#include "audiobuffer.h"
#include "timer.h"
#include "ui_mainwindow.h"
#include "../../Analyser/Static/StaticAnalyser.hpp"
#include "../../Machines/Utility/MachineForTarget.hpp"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegate {
Q_OBJECT
void createActions();
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<Timer> timer;
// Initial setup stuff.
Analyser::Static::TargetList targets;
enum class UIPhase {
NoFileSelected, RequestingROMs, RunningMachine
} uiPhase = UIPhase::NoFileSelected;
void launchMachine();
QString romRequestBaseText;
std::vector<ROMMachine::ROM> missingRoms;
// File drag and drop is supported.
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
// Ongoing state.
std::unique_ptr<Machine::DynamicMachine> machine;
std::mutex machineMutex;
std::unique_ptr<QAudioOutput> audioOutput;
bool audioIs8bit = false, audioIsStereo = false;
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) override;
AudioBuffer audioBuffer;
bool processEvent(QKeyEvent *);
private slots:
void open();
};
#endif // MAINWINDOW_H