mirror of https://github.com/mgba-emu/mgba.git
Core: Refactor GBASync into mCoreSync
This commit is contained in:
parent
6ec99ce4e4
commit
234ecd9619
|
@ -5,7 +5,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
|
|
||||||
static void _changeVideoSync(struct GBASync* sync, bool frameOn) {
|
static void _changeVideoSync(struct mCoreSync* sync, bool frameOn) {
|
||||||
// Make sure the video thread can process events while the GBA thread is paused
|
// Make sure the video thread can process events while the GBA thread is paused
|
||||||
MutexLock(&sync->videoFrameMutex);
|
MutexLock(&sync->videoFrameMutex);
|
||||||
if (frameOn != sync->videoFrameOn) {
|
if (frameOn != sync->videoFrameOn) {
|
||||||
|
@ -15,7 +15,7 @@ static void _changeVideoSync(struct GBASync* sync, bool frameOn) {
|
||||||
MutexUnlock(&sync->videoFrameMutex);
|
MutexUnlock(&sync->videoFrameMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncPostFrame(struct GBASync* sync) {
|
void mCoreSyncPostFrame(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ void GBASyncPostFrame(struct GBASync* sync) {
|
||||||
MutexUnlock(&sync->videoFrameMutex);
|
MutexUnlock(&sync->videoFrameMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncForceFrame(struct GBASync* sync) {
|
void mCoreSyncForceFrame(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ void GBASyncForceFrame(struct GBASync* sync) {
|
||||||
MutexUnlock(&sync->videoFrameMutex);
|
MutexUnlock(&sync->videoFrameMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GBASyncWaitFrameStart(struct GBASync* sync) {
|
bool mCoreSyncWaitFrameStart(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ bool GBASyncWaitFrameStart(struct GBASync* sync) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncWaitFrameEnd(struct GBASync* sync) {
|
void mCoreSyncWaitFrameEnd(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void GBASyncWaitFrameEnd(struct GBASync* sync) {
|
||||||
MutexUnlock(&sync->videoFrameMutex);
|
MutexUnlock(&sync->videoFrameMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncSetVideoSync(struct GBASync* sync, bool wait) {
|
void mCoreSyncSetVideoSync(struct mCoreSync* sync, bool wait) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ void GBASyncSetVideoSync(struct GBASync* sync, bool wait) {
|
||||||
_changeVideoSync(sync, wait);
|
_changeVideoSync(sync, wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
void mCoreSyncProduceAudio(struct mCoreSync* sync, bool wait) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
||||||
MutexUnlock(&sync->audioBufferMutex);
|
MutexUnlock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncLockAudio(struct GBASync* sync) {
|
void mCoreSyncLockAudio(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ void GBASyncLockAudio(struct GBASync* sync) {
|
||||||
MutexLock(&sync->audioBufferMutex);
|
MutexLock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncUnlockAudio(struct GBASync* sync) {
|
void mCoreSyncUnlockAudio(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ void GBASyncUnlockAudio(struct GBASync* sync) {
|
||||||
MutexUnlock(&sync->audioBufferMutex);
|
MutexUnlock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncConsumeAudio(struct GBASync* sync) {
|
void mCoreSyncConsumeAudio(struct mCoreSync* sync) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* Copyright (c) 2013-2016 Jeffrey Pfau
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
#ifndef M_CORE_SYNC_H
|
||||||
|
#define M_CORE_SYNC_H
|
||||||
|
|
||||||
|
#include "util/common.h"
|
||||||
|
|
||||||
|
#include "util/threading.h"
|
||||||
|
|
||||||
|
struct mCoreSync {
|
||||||
|
int videoFramePending;
|
||||||
|
bool videoFrameWait;
|
||||||
|
bool videoFrameOn;
|
||||||
|
Mutex videoFrameMutex;
|
||||||
|
Condition videoFrameAvailableCond;
|
||||||
|
Condition videoFrameRequiredCond;
|
||||||
|
|
||||||
|
bool audioWait;
|
||||||
|
Condition audioRequiredCond;
|
||||||
|
Mutex audioBufferMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
void mCoreSyncPostFrame(struct mCoreSync* sync);
|
||||||
|
void mCoreSyncForceFrame(struct mCoreSync* sync);
|
||||||
|
bool mCoreSyncWaitFrameStart(struct mCoreSync* sync);
|
||||||
|
void mCoreSyncWaitFrameEnd(struct mCoreSync* sync);
|
||||||
|
void mCoreSyncSetVideoSync(struct mCoreSync* sync, bool wait);
|
||||||
|
|
||||||
|
void mCoreSyncProduceAudio(struct mCoreSync* sync, bool wait);
|
||||||
|
void mCoreSyncLockAudio(struct mCoreSync* sync);
|
||||||
|
void mCoreSyncUnlockAudio(struct mCoreSync* sync);
|
||||||
|
void mCoreSyncConsumeAudio(struct mCoreSync* sync);
|
||||||
|
|
||||||
|
#endif
|
|
@ -125,7 +125,7 @@ void GBAAudioDeinit(struct GBAAudio* audio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) {
|
void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) {
|
||||||
GBASyncLockAudio(audio->p->sync);
|
mCoreSyncLockAudio(audio->p->sync);
|
||||||
audio->samples = samples;
|
audio->samples = samples;
|
||||||
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
||||||
size_t oldCapacity = audio->left.capacity;
|
size_t oldCapacity = audio->left.capacity;
|
||||||
|
@ -161,7 +161,7 @@ void GBAAudioResizeBuffer(struct GBAAudio* audio, size_t samples) {
|
||||||
audio->clock = 0;
|
audio->clock = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GBASyncConsumeAudio(audio->p->sync);
|
mCoreSyncConsumeAudio(audio->p->sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles) {
|
int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles) {
|
||||||
|
@ -534,7 +534,7 @@ void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles) {
|
||||||
|
|
||||||
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
||||||
unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned nSamples) {
|
unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned nSamples) {
|
||||||
GBASyncLockAudio(audio->p->sync);
|
mCoreSyncLockAudio(audio->p->sync);
|
||||||
unsigned read = 0;
|
unsigned read = 0;
|
||||||
if (left) {
|
if (left) {
|
||||||
unsigned readL = CircleBufferRead(&audio->left, left, nSamples * sizeof(int16_t)) >> 1;
|
unsigned readL = CircleBufferRead(&audio->left, left, nSamples * sizeof(int16_t)) >> 1;
|
||||||
|
@ -550,7 +550,7 @@ unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned
|
||||||
}
|
}
|
||||||
read = read >= readR ? read : readR;
|
read = read >= readR ? read : readR;
|
||||||
}
|
}
|
||||||
GBASyncConsumeAudio(audio->p->sync);
|
mCoreSyncConsumeAudio(audio->p->sync);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,7 +821,7 @@ static void _sample(struct GBAAudio* audio) {
|
||||||
sampleLeft = _applyBias(audio, sampleLeft);
|
sampleLeft = _applyBias(audio, sampleLeft);
|
||||||
sampleRight = _applyBias(audio, sampleRight);
|
sampleRight = _applyBias(audio, sampleRight);
|
||||||
|
|
||||||
GBASyncLockAudio(audio->p->sync);
|
mCoreSyncLockAudio(audio->p->sync);
|
||||||
unsigned produced;
|
unsigned produced;
|
||||||
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
#if RESAMPLE_LIBRARY != RESAMPLE_BLIP_BUF
|
||||||
CircleBufferWrite16(&audio->left, sampleLeft);
|
CircleBufferWrite16(&audio->left, sampleLeft);
|
||||||
|
@ -846,7 +846,7 @@ static void _sample(struct GBAAudio* audio) {
|
||||||
audio->p->stream->postAudioFrame(audio->p->stream, sampleLeft, sampleRight);
|
audio->p->stream->postAudioFrame(audio->p->stream, sampleLeft, sampleRight);
|
||||||
}
|
}
|
||||||
bool wait = produced >= audio->samples;
|
bool wait = produced >= audio->samples;
|
||||||
GBASyncProduceAudio(audio->p->sync, wait);
|
mCoreSyncProduceAudio(audio->p->sync, wait);
|
||||||
|
|
||||||
if (wait && audio->p->stream && audio->p->stream->postAudioBuffer) {
|
if (wait && audio->p->stream && audio->p->stream->postAudioBuffer) {
|
||||||
audio->p->stream->postAudioBuffer(audio->p->stream, audio);
|
audio->p->stream->postAudioBuffer(audio->p->stream, audio);
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#include "util/common.h"
|
#include "util/common.h"
|
||||||
|
|
||||||
#include "core/directories.h"
|
#include "core/directories.h"
|
||||||
|
#include "core/sync.h"
|
||||||
#include "gba/context/config.h"
|
#include "gba/context/config.h"
|
||||||
#include "gba/context/sync.h"
|
|
||||||
#include "gba/input.h"
|
#include "gba/input.h"
|
||||||
|
|
||||||
struct GBAContext {
|
struct GBAContext {
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* Copyright (c) 2013-2015 Jeffrey Pfau
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
#ifndef GBA_SYNC_H
|
|
||||||
#define GBA_SYNC_H
|
|
||||||
|
|
||||||
#include "util/common.h"
|
|
||||||
|
|
||||||
#include "util/threading.h"
|
|
||||||
|
|
||||||
struct GBASync {
|
|
||||||
int videoFramePending;
|
|
||||||
bool videoFrameWait;
|
|
||||||
bool videoFrameOn;
|
|
||||||
Mutex videoFrameMutex;
|
|
||||||
Condition videoFrameAvailableCond;
|
|
||||||
Condition videoFrameRequiredCond;
|
|
||||||
|
|
||||||
bool audioWait;
|
|
||||||
Condition audioRequiredCond;
|
|
||||||
Mutex audioBufferMutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
void GBASyncPostFrame(struct GBASync* sync);
|
|
||||||
void GBASyncForceFrame(struct GBASync* sync);
|
|
||||||
bool GBASyncWaitFrameStart(struct GBASync* sync);
|
|
||||||
void GBASyncWaitFrameEnd(struct GBASync* sync);
|
|
||||||
void GBASyncSetVideoSync(struct GBASync* sync, bool wait);
|
|
||||||
|
|
||||||
void GBASyncProduceAudio(struct GBASync* sync, bool wait);
|
|
||||||
void GBASyncLockAudio(struct GBASync* sync);
|
|
||||||
void GBASyncUnlockAudio(struct GBASync* sync);
|
|
||||||
void GBASyncConsumeAudio(struct GBASync* sync);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -83,7 +83,7 @@ struct GBA {
|
||||||
struct GBAAudio audio;
|
struct GBAAudio audio;
|
||||||
struct GBASIO sio;
|
struct GBASIO sio;
|
||||||
|
|
||||||
struct GBASync* sync;
|
struct mCoreSync* sync;
|
||||||
|
|
||||||
struct ARMDebugger* debugger;
|
struct ARMDebugger* debugger;
|
||||||
|
|
||||||
|
|
|
@ -519,7 +519,7 @@ bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
||||||
if (flags & SAVESTATE_SCREENSHOT && GBAExtdataGet(&extdata, EXTDATA_SCREENSHOT, &item)) {
|
if (flags & SAVESTATE_SCREENSHOT && GBAExtdataGet(&extdata, EXTDATA_SCREENSHOT, &item)) {
|
||||||
if (item.size >= VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4) {
|
if (item.size >= VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4) {
|
||||||
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, item.data);
|
gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, item.data);
|
||||||
GBASyncForceFrame(gba->sync);
|
mCoreSyncForceFrame(gba->sync);
|
||||||
} else {
|
} else {
|
||||||
GBALog(gba, GBA_LOG_WARN, "Savestate includes invalid screenshot");
|
GBALog(gba, GBA_LOG_WARN, "Savestate includes invalid screenshot");
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,7 +627,7 @@ void GBAThreadPause(struct GBAThread* threadContext) {
|
||||||
}
|
}
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
|
||||||
GBASyncSetVideoSync(&threadContext->sync, frameOn);
|
mCoreSyncSetVideoSync(&threadContext->sync, frameOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAThreadUnpause(struct GBAThread* threadContext) {
|
void GBAThreadUnpause(struct GBAThread* threadContext) {
|
||||||
|
@ -641,7 +641,7 @@ void GBAThreadUnpause(struct GBAThread* threadContext) {
|
||||||
}
|
}
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
|
||||||
GBASyncSetVideoSync(&threadContext->sync, frameOn);
|
mCoreSyncSetVideoSync(&threadContext->sync, frameOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GBAThreadIsPaused(struct GBAThread* threadContext) {
|
bool GBAThreadIsPaused(struct GBAThread* threadContext) {
|
||||||
|
@ -668,7 +668,7 @@ void GBAThreadTogglePause(struct GBAThread* threadContext) {
|
||||||
}
|
}
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
|
||||||
GBASyncSetVideoSync(&threadContext->sync, frameOn);
|
mCoreSyncSetVideoSync(&threadContext->sync, frameOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAThreadPauseFromThread(struct GBAThread* threadContext) {
|
void GBAThreadPauseFromThread(struct GBAThread* threadContext) {
|
||||||
|
@ -681,7 +681,7 @@ void GBAThreadPauseFromThread(struct GBAThread* threadContext) {
|
||||||
}
|
}
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
|
||||||
GBASyncSetVideoSync(&threadContext->sync, frameOn);
|
mCoreSyncSetVideoSync(&threadContext->sync, frameOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAThreadLoadROM(struct GBAThread* threadContext, const char* fname) {
|
void GBAThreadLoadROM(struct GBAThread* threadContext, const char* fname) {
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
#include "util/common.h"
|
#include "util/common.h"
|
||||||
|
|
||||||
#include "core/directories.h"
|
#include "core/directories.h"
|
||||||
|
#include "core/sync.h"
|
||||||
#include "gba/gba.h"
|
#include "gba/gba.h"
|
||||||
#include "gba/input.h"
|
#include "gba/input.h"
|
||||||
#include "gba/context/overrides.h"
|
#include "gba/context/overrides.h"
|
||||||
#include "gba/context/sync.h"
|
|
||||||
|
|
||||||
#include "util/threading.h"
|
#include "util/threading.h"
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ struct GBAThread {
|
||||||
void* userData;
|
void* userData;
|
||||||
void (*run)(struct GBAThread*);
|
void (*run)(struct GBAThread*);
|
||||||
|
|
||||||
struct GBASync sync;
|
struct mCoreSync sync;
|
||||||
|
|
||||||
int rewindBufferSize;
|
int rewindBufferSize;
|
||||||
int rewindBufferCapacity;
|
int rewindBufferCapacity;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
|
||||||
#include "gba/context/sync.h"
|
#include "core/sync.h"
|
||||||
#include "gba/gba.h"
|
#include "gba/gba.h"
|
||||||
#include "gba/io.h"
|
#include "gba/io.h"
|
||||||
#include "gba/rr/rr.h"
|
#include "gba/rr/rr.h"
|
||||||
|
@ -160,7 +160,7 @@ int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {
|
||||||
GBAFrameEnded(video->p);
|
GBAFrameEnded(video->p);
|
||||||
--video->frameskipCounter;
|
--video->frameskipCounter;
|
||||||
if (video->frameskipCounter < 0) {
|
if (video->frameskipCounter < 0) {
|
||||||
GBASyncPostFrame(video->p->sync);
|
mCoreSyncPostFrame(video->p->sync);
|
||||||
video->frameskipCounter = video->frameskip;
|
video->frameskipCounter = video->frameskip;
|
||||||
}
|
}
|
||||||
++video->frameCounter;
|
++video->frameCounter;
|
||||||
|
|
|
@ -35,10 +35,10 @@ void AudioDevice::setFormat(const QAudioFormat& format) {
|
||||||
GBAThreadContinue(m_context);
|
GBAThreadContinue(m_context);
|
||||||
#elif RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF
|
#elif RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF
|
||||||
double fauxClock = GBAAudioCalculateRatio(1, m_context->fpsTarget, 1);
|
double fauxClock = GBAAudioCalculateRatio(1, m_context->fpsTarget, 1);
|
||||||
GBASyncLockAudio(&m_context->sync);
|
mCoreSyncLockAudio(&m_context->sync);
|
||||||
blip_set_rates(m_context->gba->audio.left, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
|
blip_set_rates(m_context->gba->audio.left, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
|
||||||
blip_set_rates(m_context->gba->audio.right, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
|
blip_set_rates(m_context->gba->audio.right, GBA_ARM7TDMI_FREQUENCY, format.sampleRate() * fauxClock);
|
||||||
GBASyncUnlockAudio(&m_context->sync);
|
mCoreSyncUnlockAudio(&m_context->sync);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,14 +59,14 @@ qint64 AudioDevice::readData(char* data, qint64 maxSize) {
|
||||||
#if RESAMPLE_LIBRARY == RESAMPLE_NN
|
#if RESAMPLE_LIBRARY == RESAMPLE_NN
|
||||||
return GBAAudioResampleNN(&m_context->gba->audio, m_ratio, &m_drift, reinterpret_cast<GBAStereoSample*>(data), maxSize / sizeof(GBAStereoSample)) * sizeof(GBAStereoSample);
|
return GBAAudioResampleNN(&m_context->gba->audio, m_ratio, &m_drift, reinterpret_cast<GBAStereoSample*>(data), maxSize / sizeof(GBAStereoSample)) * sizeof(GBAStereoSample);
|
||||||
#elif RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF
|
#elif RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF
|
||||||
GBASyncLockAudio(&m_context->sync);
|
mCoreSyncLockAudio(&m_context->sync);
|
||||||
int available = blip_samples_avail(m_context->gba->audio.left);
|
int available = blip_samples_avail(m_context->gba->audio.left);
|
||||||
if (available > maxSize / sizeof(GBAStereoSample)) {
|
if (available > maxSize / sizeof(GBAStereoSample)) {
|
||||||
available = maxSize / sizeof(GBAStereoSample);
|
available = maxSize / sizeof(GBAStereoSample);
|
||||||
}
|
}
|
||||||
blip_read_samples(m_context->gba->audio.left, &reinterpret_cast<GBAStereoSample*>(data)->left, available, true);
|
blip_read_samples(m_context->gba->audio.left, &reinterpret_cast<GBAStereoSample*>(data)->left, available, true);
|
||||||
blip_read_samples(m_context->gba->audio.right, &reinterpret_cast<GBAStereoSample*>(data)->right, available, true);
|
blip_read_samples(m_context->gba->audio.right, &reinterpret_cast<GBAStereoSample*>(data)->right, available, true);
|
||||||
GBASyncConsumeAudio(&m_context->sync);
|
mCoreSyncConsumeAudio(&m_context->sync);
|
||||||
return available * sizeof(GBAStereoSample);
|
return available * sizeof(GBAStereoSample);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ void DisplayGL::startDrawing(GBAThread* thread) {
|
||||||
m_painter->moveToThread(m_drawThread);
|
m_painter->moveToThread(m_drawThread);
|
||||||
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
|
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
|
||||||
m_drawThread->start();
|
m_drawThread->start();
|
||||||
GBASyncSetVideoSync(&m_context->sync, false);
|
mCoreSyncSetVideoSync(&m_context->sync, false);
|
||||||
|
|
||||||
lockAspectRatio(isAspectRatioLocked());
|
lockAspectRatio(isAspectRatioLocked());
|
||||||
filter(isFiltered());
|
filter(isFiltered());
|
||||||
|
@ -310,15 +310,15 @@ void PainterGL::draw() {
|
||||||
if (m_queue.isEmpty() || !GBAThreadIsActive(m_context)) {
|
if (m_queue.isEmpty() || !GBAThreadIsActive(m_context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GBASyncWaitFrameStart(&m_context->sync) || !m_queue.isEmpty()) {
|
if (mCoreSyncWaitFrameStart(&m_context->sync) || !m_queue.isEmpty()) {
|
||||||
dequeue();
|
dequeue();
|
||||||
GBASyncWaitFrameEnd(&m_context->sync);
|
mCoreSyncWaitFrameEnd(&m_context->sync);
|
||||||
m_painter.begin(m_gl->context()->device());
|
m_painter.begin(m_gl->context()->device());
|
||||||
performDraw();
|
performDraw();
|
||||||
m_painter.end();
|
m_painter.end();
|
||||||
m_backend->swap(m_backend);
|
m_backend->swap(m_backend);
|
||||||
} else {
|
} else {
|
||||||
GBASyncWaitFrameEnd(&m_context->sync);
|
mCoreSyncWaitFrameEnd(&m_context->sync);
|
||||||
}
|
}
|
||||||
if (!m_queue.isEmpty()) {
|
if (!m_queue.isEmpty()) {
|
||||||
QMetaObject::invokeMethod(this, "draw", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, "draw", Qt::QueuedConnection);
|
||||||
|
|
|
@ -79,10 +79,10 @@ void mSDLGLRunloopGBA(struct mSDLRenderer* renderer, void* user) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GBASyncWaitFrameStart(&context->sync)) {
|
if (mCoreSyncWaitFrameStart(&context->sync)) {
|
||||||
v->postFrame(v, renderer->d.outputBuffer);
|
v->postFrame(v, renderer->d.outputBuffer);
|
||||||
}
|
}
|
||||||
GBASyncWaitFrameEnd(&context->sync);
|
mCoreSyncWaitFrameEnd(&context->sync);
|
||||||
v->drawFrame(v);
|
v->drawFrame(v);
|
||||||
v->swap(v);
|
v->swap(v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,10 @@ void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user) {
|
||||||
GBASDLHandleEvent(context, &renderer->player, &event);
|
GBASDLHandleEvent(context, &renderer->player, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GBASyncWaitFrameStart(&context->sync)) {
|
if (mCoreSyncWaitFrameStart(&context->sync)) {
|
||||||
v->postFrame(v, renderer->d.outputBuffer);
|
v->postFrame(v, renderer->d.outputBuffer);
|
||||||
}
|
}
|
||||||
GBASyncWaitFrameEnd(&context->sync);
|
mCoreSyncWaitFrameEnd(&context->sync);
|
||||||
v->drawFrame(v);
|
v->drawFrame(v);
|
||||||
#ifdef BUILD_RASPI
|
#ifdef BUILD_RASPI
|
||||||
eglSwapBuffers(renderer->display, renderer->surface);
|
eglSwapBuffers(renderer->display, renderer->surface);
|
||||||
|
|
|
@ -91,7 +91,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
||||||
GBASDLHandleEvent(context, &renderer->player, &event);
|
GBASDLHandleEvent(context, &renderer->player, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GBASyncWaitFrameStart(&context->sync)) {
|
if (mCoreSyncWaitFrameStart(&context->sync)) {
|
||||||
struct fb_var_screeninfo info;
|
struct fb_var_screeninfo info;
|
||||||
ioctl(renderer->fb, FBIOGET_VSCREENINFO, &info);
|
ioctl(renderer->fb, FBIOGET_VSCREENINFO, &info);
|
||||||
info.yoffset = VIDEO_VERTICAL_PIXELS * renderer->odd;
|
info.yoffset = VIDEO_VERTICAL_PIXELS * renderer->odd;
|
||||||
|
@ -103,7 +103,7 @@ void GBASDLRunloop(struct GBAThread* context, struct SDLSoftwareRenderer* render
|
||||||
renderer->odd = !renderer->odd;
|
renderer->odd = !renderer->odd;
|
||||||
renderer->d.outputBuffer = renderer->base[renderer->odd];
|
renderer->d.outputBuffer = renderer->base[renderer->odd];
|
||||||
}
|
}
|
||||||
GBASyncWaitFrameEnd(&context->sync);
|
mCoreSyncWaitFrameEnd(&context->sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
|
||||||
double fauxClock = 1;
|
double fauxClock = 1;
|
||||||
if (audioContext->thread) {
|
if (audioContext->thread) {
|
||||||
fauxClock = GBAAudioCalculateRatio(1, audioContext->thread->fpsTarget, 1);
|
fauxClock = GBAAudioCalculateRatio(1, audioContext->thread->fpsTarget, 1);
|
||||||
GBASyncLockAudio(&audioContext->thread->sync);
|
mCoreSyncLockAudio(&audioContext->thread->sync);
|
||||||
}
|
}
|
||||||
blip_set_rates(gba->audio.left, GBA_ARM7TDMI_FREQUENCY, audioContext->obtainedSpec.freq * fauxClock);
|
blip_set_rates(gba->audio.left, GBA_ARM7TDMI_FREQUENCY, audioContext->obtainedSpec.freq * fauxClock);
|
||||||
blip_set_rates(gba->audio.right, GBA_ARM7TDMI_FREQUENCY, audioContext->obtainedSpec.freq * fauxClock);
|
blip_set_rates(gba->audio.right, GBA_ARM7TDMI_FREQUENCY, audioContext->obtainedSpec.freq * fauxClock);
|
||||||
|
@ -137,7 +137,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audioContext->thread) {
|
if (audioContext->thread) {
|
||||||
GBASyncConsumeAudio(&audioContext->thread->sync);
|
mCoreSyncConsumeAudio(&audioContext->thread->sync);
|
||||||
}
|
}
|
||||||
if (available < len) {
|
if (available < len) {
|
||||||
memset(((short*) data) + audioContext->obtainedSpec.channels * available, 0, (len - available) * audioContext->obtainedSpec.channels * sizeof(short));
|
memset(((short*) data) + audioContext->obtainedSpec.channels * available, 0, (len - available) * audioContext->obtainedSpec.channels * sizeof(short));
|
||||||
|
|
|
@ -94,7 +94,7 @@ void mSDLSWRunloopGBA(struct mSDLRenderer* renderer, void* user) {
|
||||||
GBASDLHandleEvent(context, &renderer->player, &event);
|
GBASDLHandleEvent(context, &renderer->player, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GBASyncWaitFrameStart(&context->sync)) {
|
if (mCoreSyncWaitFrameStart(&context->sync)) {
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
SDL_UnlockTexture(renderer->sdlTex);
|
SDL_UnlockTexture(renderer->sdlTex);
|
||||||
SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0);
|
SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0);
|
||||||
|
@ -129,7 +129,7 @@ void mSDLSWRunloopGBA(struct mSDLRenderer* renderer, void* user) {
|
||||||
SDL_LockSurface(surface);
|
SDL_LockSurface(surface);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
GBASyncWaitFrameEnd(&context->sync);
|
mCoreSyncWaitFrameEnd(&context->sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet)
|
||||||
*frames = 0;
|
*frames = 0;
|
||||||
int lastFrames = 0;
|
int lastFrames = 0;
|
||||||
while (context->state < THREAD_EXITING) {
|
while (context->state < THREAD_EXITING) {
|
||||||
if (GBASyncWaitFrameStart(&context->sync)) {
|
if (mCoreSyncWaitFrameStart(&context->sync)) {
|
||||||
++*frames;
|
++*frames;
|
||||||
++lastFrames;
|
++lastFrames;
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
|
@ -192,7 +192,7 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames, bool quiet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GBASyncWaitFrameEnd(&context->sync);
|
mCoreSyncWaitFrameEnd(&context->sync);
|
||||||
if (duration > 0 && *frames == duration) {
|
if (duration > 0 && *frames == duration) {
|
||||||
_GBAPerfShutdown(0);
|
_GBAPerfShutdown(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue