all repos — mgba @ 13f1ab5ab84c83129e96ae80a9d261806b91289f

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 "gba/supervisor/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
26bool AudioProcessorSDL::start() {
27	if (!input()) {
28		LOG(QT, WARN) << tr("Can't start an audio processor without input");
29		return false;
30	}
31
32	if (m_audio.thread) {
33		mSDLResumeAudio(&m_audio);
34		return true;
35	} else {
36		if (!m_audio.samples) {
37			m_audio.samples = 2048; // TODO?
38		}
39		if (mSDLInitAudio(&m_audio, nullptr)) {
40			m_audio.core = input()->core;
41			m_audio.sync = &input()->sync;
42			mSDLResumeAudio(&m_audio);
43			return true;
44		}
45		return false;
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.thread) {
57		mSDLDeinitAudio(&m_audio);
58		mSDLInitAudio(&m_audio, nullptr);
59		m_audio.core = input()->core;
60		m_audio.sync = &input()->sync;
61		mSDLResumeAudio(&m_audio);
62	}
63}
64
65void AudioProcessorSDL::inputParametersChanged() {
66}
67
68void AudioProcessorSDL::requestSampleRate(unsigned rate) {
69	m_audio.sampleRate = rate;
70	if (m_audio.thread) {
71		mSDLDeinitAudio(&m_audio);
72		mSDLInitAudio(&m_audio, nullptr);
73		m_audio.core = input()->core;
74		m_audio.sync = &input()->sync;
75		mSDLResumeAudio(&m_audio);
76	}
77}
78
79unsigned AudioProcessorSDL::sampleRate() const {
80	if (m_audio.thread) {
81		return m_audio.obtainedSpec.freq;
82	} else {
83		return 0;
84	}
85}