aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-09-04 16:29:40 +0200
committerArisotura <thetotalworm@gmail.com>2019-09-04 16:29:40 +0200
commit02a6fe182c21afe68f39067318f95eacaa051484 (patch)
tree6417b14d4e19ffb37c35226514c811377abb8345 /src
parent1b40149b0a39d55ed64831050766f0b35a6f2e24 (diff)
see, Arisotura, was it that hard?
Diffstat (limited to 'src')
-rw-r--r--src/SPU.cpp10
-rw-r--r--src/SPU.h1
-rw-r--r--src/libui_sdl/DlgVideoSettings.cpp10
-rw-r--r--src/libui_sdl/main.cpp53
4 files changed, 63 insertions, 11 deletions
diff --git a/src/SPU.cpp b/src/SPU.cpp
index b36becf..9249416 100644
--- a/src/SPU.cpp
+++ b/src/SPU.cpp
@@ -738,6 +738,16 @@ void Mix(u32 samples)
}
+void TrimOutput()
+{
+ const int halflimit = (OutputBufferSize / 2);
+
+ int readpos = OutputWriteOffset - (halflimit*2);
+ if (readpos < 0) readpos += (OutputBufferSize*2);
+
+ OutputReadOffset = readpos;
+}
+
void DrainOutput()
{
OutputReadOffset = 0;
diff --git a/src/SPU.h b/src/SPU.h
index 7c99887..53a8e0a 100644
--- a/src/SPU.h
+++ b/src/SPU.h
@@ -35,6 +35,7 @@ void SetBias(u16 bias);
void Mix(u32 samples);
+void TrimOutput();
void DrainOutput();
void InitOutput();
int GetOutputSize();
diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp
index afa7357..ff88ba8 100644
--- a/src/libui_sdl/DlgVideoSettings.cpp
+++ b/src/libui_sdl/DlgVideoSettings.cpp
@@ -94,7 +94,7 @@ void RevertSettings()
if (old_vsync != Config::ScreenVSync)
{
Config::ScreenVSync = old_vsync;
- ApplyNewSettings(4);
+ //ApplyNewSettings(4);
}
if (old_usegl != new_usegl)
{
@@ -137,10 +137,10 @@ void OnRendererChanged(uiRadioButtons* rb, void* blarg)
UpdateControls();
bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
-
+
if (new_usegl) uiControlEnable(uiControl(cbVSync));
else uiControlDisable(uiControl(cbVSync));
-
+
if (new_usegl != old_usegl)
ApplyNewSettings(2);
else
@@ -161,7 +161,7 @@ void OnGLDisplayChanged(uiCheckbox* cb, void* blarg)
void OnVSyncChanged(uiCheckbox* cb, void* blarg)
{
Config::ScreenVSync = uiCheckboxChecked(cb);
- ApplyNewSettings(4);
+ //ApplyNewSettings(4);
}
void OnThreaded3DChanged(uiCheckbox* cb, void* blarg)
@@ -336,7 +336,7 @@ void Open()
uiRadioButtonsSetSelected(rbRenderer, Config::_3DRenderer);
UpdateControls();
- if (Config::ScreenUseGL || Config::_3DRenderer != 0)
+ if (Config::ScreenUseGL || Config::_3DRenderer != 0)
uiControlEnable(uiControl(cbVSync));
else
uiControlDisable(uiControl(cbVSync));
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index c4cc542..d4afa22 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -130,6 +130,8 @@ bool GL_ScreenSizeDirty;
int GL_3DScale;
+bool GL_VSyncStatus;
+
int ScreenGap = 0;
int ScreenLayout = 0;
int ScreenSizing = 0;
@@ -163,6 +165,9 @@ int AudioFreq;
float AudioSampleFrac;
SDL_AudioDeviceID AudioDevice, MicDevice;
+SDL_cond* AudioSync;
+SDL_mutex* AudioSyncLock;
+
u32 MicBufferLength = 2048;
s16 MicBuffer[2048];
u32 MicBufferReadPos, MicBufferWritePos;
@@ -239,6 +244,8 @@ bool GLScreen_InitOSDShader(GLuint* shader)
bool GLScreen_Init()
{
+ GL_VSyncStatus = Config::ScreenVSync;
+
// TODO: consider using epoxy?
if (!OpenGL_Init())
return false;
@@ -301,6 +308,13 @@ void GLScreen_DeInit()
void GLScreen_DrawScreen()
{
+ bool vsync = Config::ScreenVSync && !HotkeyDown(HK_FastForward);
+ if (vsync != GL_VSyncStatus)
+ {
+ GL_VSyncStatus = vsync;
+ uiGLSetVSync(vsync);
+ }
+
float scale = uiGLGetFramebufferScale(GLContext);
glBindFramebuffer(GL_FRAMEBUFFER, uiGLGetFramebuffer(GLContext));
@@ -575,9 +589,14 @@ void AudioCallback(void* data, Uint8* stream, int len)
s16 buf_in[1024*2];
s16* buf_out = (s16*)stream;
- int num_in = SPU::ReadOutput(buf_in, len_in);
+ int num_in;
int num_out = len;
+ SDL_LockMutex(AudioSyncLock);
+ num_in = SPU::ReadOutput(buf_in, len_in);
+ SDL_CondSignal(AudioSync);
+ SDL_UnlockMutex(AudioSyncLock);
+
if (num_in < 1)
{
memset(stream, 0, len*sizeof(s16)*2);
@@ -920,6 +939,7 @@ int EmuThreadFunc(void* burp)
Config::LimitFPS = !Config::LimitFPS;
uiQueueMain(UpdateFPSLimit, NULL);
}
+ // TODO: similar hotkeys for video/audio sync?
if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL);
if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL);
@@ -988,9 +1008,23 @@ int EmuThreadFunc(void* burp)
}
uiAreaQueueRedrawAll(MainDrawArea);
- bool limitfps = Config::LimitFPS && !HotkeyDown(HK_FastForward);
- bool vsync = Config::ScreenVSync && Screen_UseGL;
- SPU::Sync(limitfps || vsync);
+ bool fastforward = HotkeyDown(HK_FastForward);
+
+ if (Config::AudioSync && !fastforward)
+ {
+ SDL_LockMutex(AudioSyncLock);
+ while (SPU::GetOutputSize() > 1024)
+ {
+ int ret = SDL_CondWaitTimeout(AudioSync, AudioSyncLock, 500);
+ if (ret == SDL_MUTEX_TIMEDOUT) break;
+ }
+ SDL_UnlockMutex(AudioSyncLock);
+ }
+ else
+ {
+ // ensure the audio FIFO doesn't overflow
+ //SPU::TrimOutput();
+ }
float framerate = (1000.0f * nlines) / (60.0f * 263.0f);
@@ -998,6 +1032,7 @@ int EmuThreadFunc(void* burp)
u32 curtick = SDL_GetTicks();
u32 delay = curtick - lasttick;
+ bool limitfps = Config::LimitFPS && !fastforward;
if (limitfps)
{
float wantedtickF = starttick + (framerate * (fpslimitcount+1));
@@ -2269,7 +2304,7 @@ void ApplyNewSettings(int type)
GPU3D::InitRenderer(Screen_UseGL);
if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
}
- else if (type == 4) // vsync
+ /*else if (type == 4) // vsync
{
if (Screen_UseGL)
{
@@ -2281,7 +2316,7 @@ void ApplyNewSettings(int type)
{
// TODO eventually: VSync for non-GL screen?
}
- }
+ }*/
EmuRunning = prevstatus;
}
@@ -2704,6 +2739,9 @@ int main(int argc, char** argv)
uiMenuItemSetChecked(MenuItem_AudioSync, Config::AudioSync==1);
uiMenuItemSetChecked(MenuItem_ShowOSD, Config::ShowOSD==1);
+ AudioSync = SDL_CreateCond();
+ AudioSyncLock = SDL_CreateMutex();
+
AudioFreq = 48000; // TODO: make configurable?
SDL_AudioSpec whatIwant, whatIget;
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
@@ -2779,6 +2817,9 @@ int main(int argc, char** argv)
if (AudioDevice) SDL_CloseAudioDevice(AudioDevice);
if (MicDevice) SDL_CloseAudioDevice(MicDevice);
+ SDL_DestroyCond(AudioSync);
+ SDL_DestroyMutex(AudioSyncLock);
+
if (MicWavBuffer) delete[] MicWavBuffer;
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);