mirror of https://github.com/mgba-emu/mgba.git
Close process cleanly
This commit is contained in:
parent
6407ad3adc
commit
6834401e67
|
@ -32,17 +32,21 @@ qint64 AudioDevice::writeData(const char*, qint64) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioDevice::Thread::Thread(QObject* parent)
|
AudioThread::AudioThread(QObject* parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
{
|
{
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDevice::Thread::setInput(GBAAudio* input) {
|
void AudioThread::setInput(GBAAudio* input) {
|
||||||
m_input = input;
|
m_input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDevice::Thread::run() {
|
void AudioThread::shutdown() {
|
||||||
|
m_audioOutput->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioThread::run() {
|
||||||
QAudioFormat format;
|
QAudioFormat format;
|
||||||
format.setSampleRate(44100);
|
format.setSampleRate(44100);
|
||||||
format.setChannelCount(2);
|
format.setChannelCount(2);
|
||||||
|
@ -52,11 +56,10 @@ void AudioDevice::Thread::run() {
|
||||||
format.setSampleType(QAudioFormat::SignedInt);
|
format.setSampleType(QAudioFormat::SignedInt);
|
||||||
|
|
||||||
AudioDevice device(m_input);
|
AudioDevice device(m_input);
|
||||||
QAudioOutput audioOutput(format);
|
m_audioOutput = new QAudioOutput(format);
|
||||||
audioOutput.setBufferSize(1024);
|
m_audioOutput->setBufferSize(1024);
|
||||||
device.setFormat(audioOutput.format());
|
device.setFormat(m_audioOutput->format());
|
||||||
|
m_audioOutput->start(&device);
|
||||||
|
|
||||||
audioOutput.start(&device);
|
|
||||||
exec();
|
exec();
|
||||||
audioOutput.stop();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,27 @@ struct GBAAudio;
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AudioThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AudioThread(QObject* parent = 0);
|
||||||
|
|
||||||
|
void setInput(GBAAudio* input);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GBAAudio* m_input;
|
||||||
|
QAudioOutput* m_audioOutput;
|
||||||
|
};
|
||||||
|
|
||||||
class AudioDevice : public QIODevice {
|
class AudioDevice : public QIODevice {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -18,19 +39,6 @@ public:
|
||||||
|
|
||||||
void setFormat(const QAudioFormat& format);
|
void setFormat(const QAudioFormat& format);
|
||||||
|
|
||||||
class Thread : public QThread {
|
|
||||||
public:
|
|
||||||
Thread(QObject* parent = 0);
|
|
||||||
|
|
||||||
void setInput(GBAAudio* input);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void run();
|
|
||||||
|
|
||||||
private:
|
|
||||||
GBAAudio* m_input;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual qint64 readData(char* data, qint64 maxSize);
|
virtual qint64 readData(char* data, qint64 maxSize);
|
||||||
virtual qint64 writeData(const char* data, qint64 maxSize);
|
virtual qint64 writeData(const char* data, qint64 maxSize);
|
||||||
|
|
|
@ -107,9 +107,10 @@ void Window::gameStarted(GBAThread* context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setupAudio(GBAAudio* audio) {
|
void Window::setupAudio(GBAAudio* audio) {
|
||||||
AudioDevice::Thread* thread = new AudioDevice::Thread(this);
|
AudioThread* thread = new AudioThread(this);
|
||||||
thread->setInput(audio);
|
thread->setInput(audio);
|
||||||
thread->start(QThread::HighPriority);
|
thread->start(QThread::HighPriority);
|
||||||
|
connect(this, SIGNAL(shutdown()), thread, SLOT(shutdown()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setupMenu(QMenuBar* menubar) {
|
void Window::setupMenu(QMenuBar* menubar) {
|
||||||
|
|
Loading…
Reference in New Issue