all repos — mgba @ e6ea94d2296eae963a48a18d009217a38d92bf9b

mGBA Game Boy Advance Emulator

src/platform/qt/AudioProcessorQt.cpp (view raw)

 1#include "AudioProcessorQt.h"
 2
 3#include "AudioDevice.h"
 4
 5#include <QAudioOutput>
 6
 7extern "C" {
 8#include "gba-thread.h"
 9}
10
11using namespace QGBA;
12
13AudioProcessorQt::AudioProcessorQt(QObject* parent)
14	: AudioProcessor(parent)
15	, m_audioOutput(nullptr)
16	, m_device(nullptr)
17{
18}
19
20void AudioProcessorQt::setInput(GBAThread* input) {
21	AudioProcessor::setInput(input);
22	if (m_device) {
23		m_device->setInput(input);
24		if (m_audioOutput) {
25			m_device->setFormat(m_audioOutput->format());
26		}
27	}
28}
29
30void AudioProcessorQt::start() {
31	if (!m_device) {
32		m_device = new AudioDevice(this);
33	}
34
35	if (!m_audioOutput) {
36		QAudioFormat format;
37		format.setSampleRate(44100);
38		format.setChannelCount(2);
39		format.setSampleSize(16);
40		format.setCodec("audio/pcm");
41		format.setByteOrder(QAudioFormat::LittleEndian);
42		format.setSampleType(QAudioFormat::SignedInt);
43
44		m_audioOutput = new QAudioOutput(format, this);
45	}
46
47	m_device->setInput(input());
48	m_device->setFormat(m_audioOutput->format());
49	m_audioOutput->setBufferSize(input()->audioBuffers * 4);
50
51	m_audioOutput->start(m_device);
52}
53
54void AudioProcessorQt::pause() {
55	if (m_audioOutput) {
56		m_audioOutput->stop();
57	}
58}
59
60void AudioProcessorQt::setBufferSamples(int samples) {
61	if (m_audioOutput) {
62		m_audioOutput->stop();
63		m_audioOutput->setBufferSize(samples * 4);
64		m_audioOutput->start(m_device);
65	}
66}
67
68void AudioProcessorQt::inputParametersChanged() {
69	if (m_device) {
70		m_device->setFormat(m_audioOutput->format());
71	}
72}