all repos — mgba @ 6834401e67649c3818842be1e235edac7b641eda

mGBA Game Boy Advance Emulator

Close process cleanly
Jeffrey Pfau jeffrey@endrift.com
Thu, 30 Jan 2014 04:00:52 -0800
commit

6834401e67649c3818842be1e235edac7b641eda

parent

6407ad3adcdc6d8241416a4a4a44a62a1ffeaa1c

3 files changed, 33 insertions(+), 21 deletions(-)

jump to
M src/platform/qt/AudioDevice.cppsrc/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.hsrc/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.cppsrc/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) {