all repos — mgba @ 686380b6c4d8acf219a704a8932668b11efc47c2

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