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 12 using namespace QGBA; 13 AudioProcessorSDL(QObject * parent)14AudioProcessorSDL::AudioProcessorSDL(QObject* parent) 15 : AudioProcessor(parent) 16 { 17 } 18 setInput(std::shared_ptr<CoreController> controller)19void AudioProcessorSDL::setInput(std::shared_ptr<CoreController> controller) { 20 AudioProcessor::setInput(controller); 21 if (m_audio.core && input()->core != m_audio.core) { 22 mSDLDeinitAudio(&m_audio); 23 mSDLInitAudio(&m_audio, input()); 24 } 25 } 26 stop()27void AudioProcessorSDL::stop() { 28 mSDLDeinitAudio(&m_audio); 29 AudioProcessor::stop(); 30 } 31 start()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 pause()49void AudioProcessorSDL::pause() { 50 mSDLPauseAudio(&m_audio); 51 } 52 setBufferSamples(int samples)53void AudioProcessorSDL::setBufferSamples(int samples) { 54 AudioProcessor::setBufferSamples(samples); 55 if (m_audio.samples != static_cast<size_t>(samples)) { 56 m_audio.samples = samples; 57 if (m_audio.core) { 58 mSDLDeinitAudio(&m_audio); 59 mSDLInitAudio(&m_audio, input()); 60 } 61 } 62 } 63 inputParametersChanged()64void AudioProcessorSDL::inputParametersChanged() { 65 } 66 requestSampleRate(unsigned rate)67void AudioProcessorSDL::requestSampleRate(unsigned rate) { 68 if (m_audio.sampleRate != rate) { 69 m_audio.sampleRate = rate; 70 if (m_audio.core) { 71 mSDLDeinitAudio(&m_audio); 72 mSDLInitAudio(&m_audio, input()); 73 } 74 } 75 } 76 sampleRate() const77unsigned AudioProcessorSDL::sampleRate() const { 78 if (m_audio.core) { 79 return m_audio.obtainedSpec.freq; 80 } else { 81 return 0; 82 } 83 } 84