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 GBASDLDeinitAudio(&m_audio);
24}
25
26bool AudioProcessorSDL::start() {
27 if (!input()) {
28 LOG(WARN) << tr("Can't start an audio processor without input");
29 return false;
30 }
31
32 if (m_audio.thread) {
33 GBASDLResumeAudio(&m_audio);
34 return true;
35 } else {
36 if (!m_audio.samples) {
37 m_audio.samples = input()->audioBuffers;
38 }
39 return GBASDLInitAudio(&m_audio, input());
40 }
41}
42
43void AudioProcessorSDL::pause() {
44 GBASDLPauseAudio(&m_audio);
45}
46
47void AudioProcessorSDL::setBufferSamples(int samples) {
48 AudioProcessor::setBufferSamples(samples);
49 m_audio.samples = samples;
50 if (m_audio.thread) {
51 GBASDLDeinitAudio(&m_audio);
52 GBASDLInitAudio(&m_audio, input());
53 }
54}
55
56void AudioProcessorSDL::inputParametersChanged() {
57}
58
59void AudioProcessorSDL::requestSampleRate(unsigned rate) {
60 m_audio.sampleRate = rate;
61 if (m_audio.thread) {
62 GBASDLDeinitAudio(&m_audio);
63 GBASDLInitAudio(&m_audio, input());
64 }
65}
66
67unsigned AudioProcessorSDL::sampleRate() const {
68 if (m_audio.thread) {
69 return m_audio.obtainedSpec.freq;
70 } else {
71 return 0;
72 }
73}