Qt: Remove audio thread

This commit is contained in:
Vicki Pfau 2017-03-24 13:24:02 -07:00
parent cca3a94617
commit 03f96911bb
3 changed files with 7 additions and 19 deletions

View File

@ -73,6 +73,7 @@ Misc:
- GBA Video: Optimize when BLD* registers are written frequently - GBA Video: Optimize when BLD* registers are written frequently
- Core: Cores can now have multiple sets of callbacks - Core: Cores can now have multiple sets of callbacks
- GBA: Ignore invalid opcodes used by the Wii U VC emulator - GBA: Ignore invalid opcodes used by the Wii U VC emulator
- Qt: Remove audio thread
0.5.2: (2016-12-31) 0.5.2: (2016-12-31)
Bugfixes: Bugfixes:

View File

@ -13,7 +13,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDateTime> #include <QDateTime>
#include <QThread>
#include <ctime> #include <ctime>
@ -48,7 +47,6 @@ GameController::GameController(QObject* parent)
, m_gameOpen(false) , m_gameOpen(false)
, m_vf(nullptr) , m_vf(nullptr)
, m_useBios(false) , m_useBios(false)
, m_audioThread(new QThread(this))
, m_audioProcessor(AudioProcessor::create()) , m_audioProcessor(AudioProcessor::create())
, m_pauseAfterFrame(false) , m_pauseAfterFrame(false)
, m_sync(true) , m_sync(true)
@ -176,7 +174,7 @@ GameController::GameController(QObject* parent)
controller->m_patch = QString(); controller->m_patch = QString();
controller->clearOverride(); controller->clearOverride();
QMetaObject::invokeMethod(controller->m_audioProcessor, "pause", Qt::BlockingQueuedConnection); controller->m_audioProcessor->pause();
QMetaObject::invokeMethod(controller, "gameStopped", Q_ARG(mCoreThread*, context)); QMetaObject::invokeMethod(controller, "gameStopped", Q_ARG(mCoreThread*, context));
QMetaObject::invokeMethod(controller, "cleanGame"); QMetaObject::invokeMethod(controller, "cleanGame");
@ -294,9 +292,6 @@ GameController::GameController(QObject* parent)
m_threadContext.userData = this; m_threadContext.userData = this;
m_audioThread->setObjectName("Audio Thread");
m_audioThread->start(QThread::TimeCriticalPriority);
m_audioProcessor->moveToThread(m_audioThread);
connect(this, SIGNAL(gamePaused(mCoreThread*)), m_audioProcessor, SLOT(pause())); connect(this, SIGNAL(gamePaused(mCoreThread*)), m_audioProcessor, SLOT(pause()));
connect(this, SIGNAL(gameStarted(mCoreThread*, const QString&)), m_audioProcessor, SLOT(setInput(mCoreThread*))); connect(this, SIGNAL(gameStarted(mCoreThread*, const QString&)), m_audioProcessor, SLOT(setInput(mCoreThread*)));
connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(pollEvents())); connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(pollEvents()));
@ -306,8 +301,6 @@ GameController::GameController(QObject* parent)
GameController::~GameController() { GameController::~GameController() {
disconnect(); disconnect();
closeGame(); closeGame();
m_audioThread->quit();
m_audioThread->wait();
clearMultiplayerController(); clearMultiplayerController();
delete m_backupLoadState; delete m_backupLoadState;
} }
@ -850,7 +843,7 @@ void GameController::setAudioBufferSamples(int samples) {
threadInterrupt(); threadInterrupt();
redoSamples(samples); redoSamples(samples);
threadContinue(); threadContinue();
QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Qt::BlockingQueuedConnection, Q_ARG(int, samples)); m_audioProcessor->setBufferSamples(samples);
} }
} }
@ -862,7 +855,7 @@ void GameController::setAudioSampleRate(unsigned rate) {
threadInterrupt(); threadInterrupt();
redoSamples(m_audioProcessor->getBufferSamples()); redoSamples(m_audioProcessor->getBufferSamples());
threadContinue(); threadContinue();
QMetaObject::invokeMethod(m_audioProcessor, "requestSampleRate", Q_ARG(unsigned, rate)); m_audioProcessor->requestSampleRate(rate);
} }
} }
@ -915,9 +908,7 @@ void GameController::setAudioChannelEnabled(int channel, bool enable) {
} }
void GameController::startAudio() { void GameController::startAudio() {
bool started = false; if (!m_audioProcessor->start()) {
QMetaObject::invokeMethod(m_audioProcessor, "start", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, started));
if (!started) {
LOG(QT, ERROR) << tr("Failed to start audio processor"); LOG(QT, ERROR) << tr("Failed to start audio processor");
// Don't freeze! // Don't freeze!
m_audioSync = false; m_audioSync = false;
@ -1135,7 +1126,7 @@ void GameController::reloadAudioDriver() {
int samples = 0; int samples = 0;
unsigned sampleRate = 0; unsigned sampleRate = 0;
if (m_audioProcessor) { if (m_audioProcessor) {
QMetaObject::invokeMethod(m_audioProcessor, "pause", Qt::BlockingQueuedConnection); m_audioProcessor->pause();
samples = m_audioProcessor->getBufferSamples(); samples = m_audioProcessor->getBufferSamples();
sampleRate = m_audioProcessor->sampleRate(); sampleRate = m_audioProcessor->sampleRate();
delete m_audioProcessor; delete m_audioProcessor;
@ -1147,7 +1138,6 @@ void GameController::reloadAudioDriver() {
if (sampleRate) { if (sampleRate) {
m_audioProcessor->requestSampleRate(sampleRate); m_audioProcessor->requestSampleRate(sampleRate);
} }
m_audioProcessor->moveToThread(m_audioThread);
connect(this, SIGNAL(gamePaused(mCoreThread*)), m_audioProcessor, SLOT(pause())); connect(this, SIGNAL(gamePaused(mCoreThread*)), m_audioProcessor, SLOT(pause()));
connect(this, SIGNAL(gameStarted(mCoreThread*, const QString&)), m_audioProcessor, SLOT(setInput(mCoreThread*))); connect(this, SIGNAL(gameStarted(mCoreThread*, const QString&)), m_audioProcessor, SLOT(setInput(mCoreThread*)));
if (isLoaded()) { if (isLoaded()) {
@ -1222,7 +1212,7 @@ void GameController::redoSamples(int samples) {
if (m_threadContext.core) { if (m_threadContext.core) {
m_threadContext.core->setAudioBufferSize(m_threadContext.core, samples); m_threadContext.core->setAudioBufferSize(m_threadContext.core, samples);
} }
QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); m_audioProcessor->inputParametersChanged();
} }
void GameController::setLogLevel(int levels) { void GameController::setLogLevel(int levels) {

View File

@ -30,8 +30,6 @@ struct mCoreConfig;
struct mDebugger; struct mDebugger;
struct mTileCache; struct mTileCache;
class QThread;
namespace QGBA { namespace QGBA {
class AudioProcessor; class AudioProcessor;
@ -206,7 +204,6 @@ private:
QString m_patch; QString m_patch;
Override* m_override; Override* m_override;
QThread* m_audioThread;
AudioProcessor* m_audioProcessor; AudioProcessor* m_audioProcessor;
QAtomicInt m_pauseAfterFrame; QAtomicInt m_pauseAfterFrame;