Move audio initialization into thread
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jan 2014 02:34:58 -0800
4 files changed,
24 insertions(+),
27 deletions(-)
M
src/platform/qt/AudioDevice.cpp
→
src/platform/qt/AudioDevice.cpp
@@ -32,18 +32,31 @@ qint64 AudioDevice::writeData(const char*, qint64) {
return 0; } -AudioDevice::Thread::Thread(AudioDevice* device, QObject* parent) +AudioDevice::Thread::Thread(QObject* parent) : QThread(parent) - , m_device(device) { // Nothing to do } -void AudioDevice::Thread::setOutput(QAudioOutput* output) { - m_audio = output; +void AudioDevice::Thread::setInput(GBAAudio* input) { + m_input = input; } void AudioDevice::Thread::run() { - m_audio->start(m_device); + QAudioFormat format; + format.setSampleRate(44100); + format.setChannelCount(2); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::SignedInt); + + AudioDevice device(m_input); + QAudioOutput audioOutput(format); + audioOutput.setBufferSize(1024); + device.setFormat(audioOutput.format()); + + audioOutput.start(&device); exec(); + audioOutput.stop(); }
M
src/platform/qt/AudioDevice.h
→
src/platform/qt/AudioDevice.h
@@ -20,16 +20,15 @@ void setFormat(const QAudioFormat& format);
class Thread : public QThread { public: - Thread(AudioDevice* device, QObject* parent = 0); + Thread(QObject* parent = 0); - void setOutput(QAudioOutput* output); + void setInput(GBAAudio* input); protected: void run(); private: - QAudioOutput* m_audio; - AudioDevice* m_device; + GBAAudio* m_input; }; protected:
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -24,21 +24,7 @@ }
} void Window::setupAudio(GBAAudio* audio) { - AudioDevice* device = new AudioDevice(audio, this); - AudioDevice::Thread* thread = new AudioDevice::Thread(device, this); - if (!m_audio) { - QAudioFormat format; - format.setSampleRate(44100); - format.setChannelCount(2); - format.setSampleSize(16); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - - m_audio = new QAudioOutput(format, this); - m_audio->setBufferSize(1024); - } - device->setFormat(m_audio->format()); - thread->setOutput(m_audio); - thread->start(); + AudioDevice::Thread* thread = new AudioDevice::Thread(this); + thread->setInput(audio); + thread->start(QThread::HighPriority); }
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -24,7 +24,6 @@ private slots:
void setupAudio(GBAAudio*); private: - QAudioOutput* m_audio; GameController* m_controller; Display* m_display; };