mirror of https://github.com/mgba-emu/mgba.git
SDL: Remove GBAThread reference
This commit is contained in:
parent
13f1ab5ab8
commit
ef68c84e76
|
@ -9,7 +9,6 @@
|
|||
|
||||
extern "C" {
|
||||
#include "core/thread.h"
|
||||
#include "gba/gba.h"
|
||||
#include "gba/audio.h"
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <QAudioOutput>
|
||||
|
||||
extern "C" {
|
||||
#include "gba/supervisor/thread.h"
|
||||
#include "core/thread.h"
|
||||
}
|
||||
|
||||
using namespace QGBA;
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
|
||||
#include "LogController.h"
|
||||
|
||||
extern "C" {
|
||||
#include "gba/supervisor/thread.h"
|
||||
}
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
AudioProcessorSDL::AudioProcessorSDL(QObject* parent)
|
||||
|
@ -23,26 +19,28 @@ AudioProcessorSDL::~AudioProcessorSDL() {
|
|||
mSDLDeinitAudio(&m_audio);
|
||||
}
|
||||
|
||||
void AudioProcessorSDL::setInput(mCoreThread* input) {
|
||||
AudioProcessor::setInput(input);
|
||||
if (m_audio.core) {
|
||||
mSDLDeinitAudio(&m_audio);
|
||||
mSDLInitAudio(&m_audio, input);
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioProcessorSDL::start() {
|
||||
if (!input()) {
|
||||
LOG(QT, WARN) << tr("Can't start an audio processor without input");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_audio.thread) {
|
||||
if (m_audio.core) {
|
||||
mSDLResumeAudio(&m_audio);
|
||||
return true;
|
||||
} else {
|
||||
if (!m_audio.samples) {
|
||||
m_audio.samples = 2048; // TODO?
|
||||
}
|
||||
if (mSDLInitAudio(&m_audio, nullptr)) {
|
||||
m_audio.core = input()->core;
|
||||
m_audio.sync = &input()->sync;
|
||||
mSDLResumeAudio(&m_audio);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return mSDLInitAudio(&m_audio, input());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,12 +51,9 @@ void AudioProcessorSDL::pause() {
|
|||
void AudioProcessorSDL::setBufferSamples(int samples) {
|
||||
AudioProcessor::setBufferSamples(samples);
|
||||
m_audio.samples = samples;
|
||||
if (m_audio.thread) {
|
||||
if (m_audio.core) {
|
||||
mSDLDeinitAudio(&m_audio);
|
||||
mSDLInitAudio(&m_audio, nullptr);
|
||||
m_audio.core = input()->core;
|
||||
m_audio.sync = &input()->sync;
|
||||
mSDLResumeAudio(&m_audio);
|
||||
mSDLInitAudio(&m_audio, input());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,17 +62,14 @@ void AudioProcessorSDL::inputParametersChanged() {
|
|||
|
||||
void AudioProcessorSDL::requestSampleRate(unsigned rate) {
|
||||
m_audio.sampleRate = rate;
|
||||
if (m_audio.thread) {
|
||||
if (m_audio.core) {
|
||||
mSDLDeinitAudio(&m_audio);
|
||||
mSDLInitAudio(&m_audio, nullptr);
|
||||
m_audio.core = input()->core;
|
||||
m_audio.sync = &input()->sync;
|
||||
mSDLResumeAudio(&m_audio);
|
||||
mSDLInitAudio(&m_audio, input());
|
||||
}
|
||||
}
|
||||
|
||||
unsigned AudioProcessorSDL::sampleRate() const {
|
||||
if (m_audio.thread) {
|
||||
if (m_audio.core) {
|
||||
return m_audio.obtainedSpec.freq;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
AudioProcessorSDL(QObject* parent = nullptr);
|
||||
~AudioProcessorSDL();
|
||||
|
||||
virtual void setInput(mCoreThread* input) override;
|
||||
virtual unsigned sampleRate() const override;
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -174,17 +174,13 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
|
|||
renderer->audio.samples = renderer->core->opts.audioBuffers;
|
||||
renderer->audio.sampleRate = 44100;
|
||||
|
||||
bool didFail = !mSDLInitAudio(&renderer->audio, 0);
|
||||
bool didFail = !mSDLInitAudio(&renderer->audio, &thread);
|
||||
if (!didFail) {
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
mSDLSetScreensaverSuspendable(&renderer->events, renderer->core->opts.suspendScreensaver);
|
||||
mSDLSuspendScreensaver(&renderer->events);
|
||||
#endif
|
||||
renderer->audio.core = renderer->core;
|
||||
renderer->audio.sync = &thread.sync;
|
||||
|
||||
if (mCoreThreadStart(&thread)) {
|
||||
mSDLResumeAudio(&renderer->audio);
|
||||
renderer->runloop(renderer, &thread);
|
||||
mCoreThreadJoin(&thread);
|
||||
} else {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
static void _mSDLAudioCallback(void* context, Uint8* data, int len);
|
||||
|
||||
bool mSDLInitAudio(struct mSDLAudio* context, struct GBAThread* threadContext) {
|
||||
bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread* threadContext) {
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
||||
GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system: %s", SDL_GetError());
|
||||
return false;
|
||||
|
@ -40,6 +40,7 @@ bool mSDLInitAudio(struct mSDLAudio* context, struct GBAThread* threadContext) {
|
|||
context->core = 0;
|
||||
|
||||
if (threadContext) {
|
||||
context->core = threadContext->core;
|
||||
context->sync = &threadContext->sync;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
|
|
@ -23,11 +23,11 @@ struct mSDLAudio {
|
|||
#endif
|
||||
|
||||
struct mCore* core;
|
||||
struct GBAThread* thread;
|
||||
struct mCoreSync* sync;
|
||||
};
|
||||
|
||||
bool mSDLInitAudio(struct mSDLAudio* context, struct GBAThread*);
|
||||
struct mCoreThread;
|
||||
bool mSDLInitAudio(struct mSDLAudio* context, struct mCoreThread*);
|
||||
void mSDLDeinitAudio(struct mSDLAudio* context);
|
||||
void mSDLPauseAudio(struct mSDLAudio* context);
|
||||
void mSDLResumeAudio(struct mSDLAudio* context);
|
||||
|
|
Loading…
Reference in New Issue