Close process cleanly
Jeffrey Pfau jeffrey@endrift.com
Thu, 30 Jan 2014 04:00:52 -0800
3 files changed,
33 insertions(+),
21 deletions(-)
M
src/platform/qt/AudioDevice.cpp
→
src/platform/qt/AudioDevice.cpp
@@ -32,17 +32,21 @@ qint64 AudioDevice::writeData(const char*, qint64) {
return 0; } -AudioDevice::Thread::Thread(QObject* parent) +AudioThread::AudioThread(QObject* parent) : QThread(parent) { // Nothing to do } -void AudioDevice::Thread::setInput(GBAAudio* input) { +void AudioThread::setInput(GBAAudio* input) { m_input = input; } -void AudioDevice::Thread::run() { +void AudioThread::shutdown() { + m_audioOutput->stop(); +} + +void AudioThread::run() { QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(2);@@ -52,11 +56,10 @@ format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt); AudioDevice device(m_input); - QAudioOutput audioOutput(format); - audioOutput.setBufferSize(1024); - device.setFormat(audioOutput.format()); + m_audioOutput = new QAudioOutput(format); + m_audioOutput->setBufferSize(1024); + device.setFormat(m_audioOutput->format()); + m_audioOutput->start(&device); - audioOutput.start(&device); exec(); - audioOutput.stop(); }
M
src/platform/qt/AudioDevice.h
→
src/platform/qt/AudioDevice.h
@@ -10,26 +10,34 @@ struct GBAAudio;
namespace QGBA { -class AudioDevice : public QIODevice { + + +class AudioThread : public QThread { Q_OBJECT public: - AudioDevice(GBAAudio* audio, QObject* parent = 0); + AudioThread(QObject* parent = 0); - void setFormat(const QAudioFormat& format); + void setInput(GBAAudio* input); - class Thread : public QThread { - public: - Thread(QObject* parent = 0); +public slots: + void shutdown(); - void setInput(GBAAudio* input); +protected: + void run(); - protected: - void run(); +private: + GBAAudio* m_input; + QAudioOutput* m_audioOutput; +}; - private: - GBAAudio* m_input; - }; +class AudioDevice : public QIODevice { +Q_OBJECT + +public: + AudioDevice(GBAAudio* audio, QObject* parent = 0); + + void setFormat(const QAudioFormat& format); protected: virtual qint64 readData(char* data, qint64 maxSize);
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -107,9 +107,10 @@ }
} void Window::setupAudio(GBAAudio* audio) { - AudioDevice::Thread* thread = new AudioDevice::Thread(this); + AudioThread* thread = new AudioThread(this); thread->setInput(audio); thread->start(QThread::HighPriority); + connect(this, SIGNAL(shutdown()), thread, SLOT(shutdown())); } void Window::setupMenu(QMenuBar* menubar) {