see, Arisotura, was it that hard?

This commit is contained in:
Arisotura 2019-09-04 16:29:40 +02:00
parent 1b40149b0a
commit 02a6fe182c
4 changed files with 63 additions and 11 deletions

View File

@ -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;

View File

@ -35,6 +35,7 @@ void SetBias(u16 bias);
void Mix(u32 samples);
void TrimOutput();
void DrainOutput();
void InitOutput();
int GetOutputSize();

View File

@ -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));

View File

@ -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]);