mirror of https://github.com/mgba-emu/mgba.git
Move audio initialization into thread
This commit is contained in:
parent
0ca3afa3e6
commit
98c9121ac2
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -20,16 +20,15 @@ public:
|
|||
|
||||
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:
|
||||
|
|
|
@ -24,21 +24,7 @@ void Window::selectROM() {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ private slots:
|
|||
void setupAudio(GBAAudio*);
|
||||
|
||||
private:
|
||||
QAudioOutput* m_audio;
|
||||
GameController* m_controller;
|
||||
Display* m_display;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue