all repos — mgba @ 67905d281bfecbb06f51f2ca5ac939df378734a5

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
10extern "C" {
11#include "core/thread.h"
12}
13
14using namespace QGBA;
15
16AudioProcessorSDL::AudioProcessorSDL(QObject* parent)
17	: AudioProcessor(parent)
18	, m_audio{ 2048, 44100 }
19{
20}
21
22AudioProcessorSDL::~AudioProcessorSDL() {
23	mSDLDeinitAudio(&m_audio);
24}
25
26void AudioProcessorSDL::setInput(mCoreThread* input) {
27	AudioProcessor::setInput(input);
28	if (m_audio.core && input->core != m_audio.core) {
29		mSDLDeinitAudio(&m_audio);
30		mSDLInitAudio(&m_audio, input);
31	}
32}
33
34bool AudioProcessorSDL::start() {
35	if (!input()) {
36		LOG(QT, WARN) << tr("Can't start an audio processor without input");
37		return false;
38	}
39
40	if (m_audio.core) {
41		mSDLResumeAudio(&m_audio);
42		return true;
43	} else {
44		if (!m_audio.samples) {
45			m_audio.samples = 2048; // TODO?
46		}
47		return mSDLInitAudio(&m_audio, input());
48	}
49}
50
51void AudioProcessorSDL::pause() {
52	mSDLPauseAudio(&m_audio);
53}
54
55void AudioProcessorSDL::setBufferSamples(int samples) {
56	AudioProcessor::setBufferSamples(samples);
57	m_audio.samples = samples;
58	if (m_audio.core) {
59		mSDLDeinitAudio(&m_audio);
60		mSDLInitAudio(&m_audio, input());
61	}
62}
63
64void AudioProcessorSDL::inputParametersChanged() {
65}
66
67void AudioProcessorSDL::requestSampleRate(unsigned rate) {
68	m_audio.sampleRate = rate;
69	if (m_audio.core) {
70		mSDLDeinitAudio(&m_audio);
71		mSDLInitAudio(&m_audio, input());
72	}
73}
74
75unsigned AudioProcessorSDL::sampleRate() const {
76	if (m_audio.core) {
77		return m_audio.obtainedSpec.freq;
78	} else {
79		return 0;
80	}
81}