all repos — mgba @ f6f3cb5d3d8b91dd603772ea0eebb2513562a0cf

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "AudioProcessorSDL.h"
 7
 8#include "LogController.h"
 9
10#include <mgba/core/thread.h>
11
12using namespace QGBA;
13
14AudioProcessorSDL::AudioProcessorSDL(QObject* parent)
15	: AudioProcessor(parent)
16{
17}
18
19AudioProcessorSDL::~AudioProcessorSDL() {
20	mSDLDeinitAudio(&m_audio);
21}
22
23void AudioProcessorSDL::setInput(mCoreThread* input) {
24	AudioProcessor::setInput(input);
25	if (m_audio.core && input->core != m_audio.core) {
26		mSDLDeinitAudio(&m_audio);
27		mSDLInitAudio(&m_audio, input);
28	}
29}
30
31bool AudioProcessorSDL::start() {
32	if (!input()) {
33		LOG(QT, WARN) << tr("Can't start an audio processor without input");
34		return false;
35	}
36
37	if (m_audio.core) {
38		mSDLResumeAudio(&m_audio);
39		return true;
40	} else {
41		if (!m_audio.samples) {
42			m_audio.samples = 2048; // TODO?
43		}
44		return mSDLInitAudio(&m_audio, input());
45	}
46}
47
48void AudioProcessorSDL::pause() {
49	mSDLPauseAudio(&m_audio);
50}
51
52void AudioProcessorSDL::setBufferSamples(int samples) {
53	AudioProcessor::setBufferSamples(samples);
54	m_audio.samples = samples;
55	if (m_audio.core) {
56		mSDLDeinitAudio(&m_audio);
57		mSDLInitAudio(&m_audio, input());
58	}
59}
60
61void AudioProcessorSDL::inputParametersChanged() {
62}
63
64void AudioProcessorSDL::requestSampleRate(unsigned rate) {
65	m_audio.sampleRate = rate;
66	if (m_audio.core) {
67		mSDLDeinitAudio(&m_audio);
68		mSDLInitAudio(&m_audio, input());
69	}
70}
71
72unsigned AudioProcessorSDL::sampleRate() const {
73	if (m_audio.core) {
74		return m_audio.obtainedSpec.freq;
75	} else {
76		return 0;
77	}
78}