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