see, Arisotura, was it that hard?
This commit is contained in:
parent
1b40149b0a
commit
02a6fe182c
10
src/SPU.cpp
10
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()
|
void DrainOutput()
|
||||||
{
|
{
|
||||||
OutputReadOffset = 0;
|
OutputReadOffset = 0;
|
||||||
|
|
|
@ -35,6 +35,7 @@ void SetBias(u16 bias);
|
||||||
|
|
||||||
void Mix(u32 samples);
|
void Mix(u32 samples);
|
||||||
|
|
||||||
|
void TrimOutput();
|
||||||
void DrainOutput();
|
void DrainOutput();
|
||||||
void InitOutput();
|
void InitOutput();
|
||||||
int GetOutputSize();
|
int GetOutputSize();
|
||||||
|
|
|
@ -94,7 +94,7 @@ void RevertSettings()
|
||||||
if (old_vsync != Config::ScreenVSync)
|
if (old_vsync != Config::ScreenVSync)
|
||||||
{
|
{
|
||||||
Config::ScreenVSync = old_vsync;
|
Config::ScreenVSync = old_vsync;
|
||||||
ApplyNewSettings(4);
|
//ApplyNewSettings(4);
|
||||||
}
|
}
|
||||||
if (old_usegl != new_usegl)
|
if (old_usegl != new_usegl)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ void OnGLDisplayChanged(uiCheckbox* cb, void* blarg)
|
||||||
void OnVSyncChanged(uiCheckbox* cb, void* blarg)
|
void OnVSyncChanged(uiCheckbox* cb, void* blarg)
|
||||||
{
|
{
|
||||||
Config::ScreenVSync = uiCheckboxChecked(cb);
|
Config::ScreenVSync = uiCheckboxChecked(cb);
|
||||||
ApplyNewSettings(4);
|
//ApplyNewSettings(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnThreaded3DChanged(uiCheckbox* cb, void* blarg)
|
void OnThreaded3DChanged(uiCheckbox* cb, void* blarg)
|
||||||
|
|
|
@ -130,6 +130,8 @@ bool GL_ScreenSizeDirty;
|
||||||
|
|
||||||
int GL_3DScale;
|
int GL_3DScale;
|
||||||
|
|
||||||
|
bool GL_VSyncStatus;
|
||||||
|
|
||||||
int ScreenGap = 0;
|
int ScreenGap = 0;
|
||||||
int ScreenLayout = 0;
|
int ScreenLayout = 0;
|
||||||
int ScreenSizing = 0;
|
int ScreenSizing = 0;
|
||||||
|
@ -163,6 +165,9 @@ int AudioFreq;
|
||||||
float AudioSampleFrac;
|
float AudioSampleFrac;
|
||||||
SDL_AudioDeviceID AudioDevice, MicDevice;
|
SDL_AudioDeviceID AudioDevice, MicDevice;
|
||||||
|
|
||||||
|
SDL_cond* AudioSync;
|
||||||
|
SDL_mutex* AudioSyncLock;
|
||||||
|
|
||||||
u32 MicBufferLength = 2048;
|
u32 MicBufferLength = 2048;
|
||||||
s16 MicBuffer[2048];
|
s16 MicBuffer[2048];
|
||||||
u32 MicBufferReadPos, MicBufferWritePos;
|
u32 MicBufferReadPos, MicBufferWritePos;
|
||||||
|
@ -239,6 +244,8 @@ bool GLScreen_InitOSDShader(GLuint* shader)
|
||||||
|
|
||||||
bool GLScreen_Init()
|
bool GLScreen_Init()
|
||||||
{
|
{
|
||||||
|
GL_VSyncStatus = Config::ScreenVSync;
|
||||||
|
|
||||||
// TODO: consider using epoxy?
|
// TODO: consider using epoxy?
|
||||||
if (!OpenGL_Init())
|
if (!OpenGL_Init())
|
||||||
return false;
|
return false;
|
||||||
|
@ -301,6 +308,13 @@ void GLScreen_DeInit()
|
||||||
|
|
||||||
void GLScreen_DrawScreen()
|
void GLScreen_DrawScreen()
|
||||||
{
|
{
|
||||||
|
bool vsync = Config::ScreenVSync && !HotkeyDown(HK_FastForward);
|
||||||
|
if (vsync != GL_VSyncStatus)
|
||||||
|
{
|
||||||
|
GL_VSyncStatus = vsync;
|
||||||
|
uiGLSetVSync(vsync);
|
||||||
|
}
|
||||||
|
|
||||||
float scale = uiGLGetFramebufferScale(GLContext);
|
float scale = uiGLGetFramebufferScale(GLContext);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, uiGLGetFramebuffer(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_in[1024*2];
|
||||||
s16* buf_out = (s16*)stream;
|
s16* buf_out = (s16*)stream;
|
||||||
|
|
||||||
int num_in = SPU::ReadOutput(buf_in, len_in);
|
int num_in;
|
||||||
int num_out = len;
|
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)
|
if (num_in < 1)
|
||||||
{
|
{
|
||||||
memset(stream, 0, len*sizeof(s16)*2);
|
memset(stream, 0, len*sizeof(s16)*2);
|
||||||
|
@ -920,6 +939,7 @@ int EmuThreadFunc(void* burp)
|
||||||
Config::LimitFPS = !Config::LimitFPS;
|
Config::LimitFPS = !Config::LimitFPS;
|
||||||
uiQueueMain(UpdateFPSLimit, NULL);
|
uiQueueMain(UpdateFPSLimit, NULL);
|
||||||
}
|
}
|
||||||
|
// TODO: similar hotkeys for video/audio sync?
|
||||||
|
|
||||||
if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL);
|
if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL);
|
||||||
if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL);
|
if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL);
|
||||||
|
@ -988,9 +1008,23 @@ int EmuThreadFunc(void* burp)
|
||||||
}
|
}
|
||||||
uiAreaQueueRedrawAll(MainDrawArea);
|
uiAreaQueueRedrawAll(MainDrawArea);
|
||||||
|
|
||||||
bool limitfps = Config::LimitFPS && !HotkeyDown(HK_FastForward);
|
bool fastforward = HotkeyDown(HK_FastForward);
|
||||||
bool vsync = Config::ScreenVSync && Screen_UseGL;
|
|
||||||
SPU::Sync(limitfps || vsync);
|
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);
|
float framerate = (1000.0f * nlines) / (60.0f * 263.0f);
|
||||||
|
|
||||||
|
@ -998,6 +1032,7 @@ int EmuThreadFunc(void* burp)
|
||||||
u32 curtick = SDL_GetTicks();
|
u32 curtick = SDL_GetTicks();
|
||||||
u32 delay = curtick - lasttick;
|
u32 delay = curtick - lasttick;
|
||||||
|
|
||||||
|
bool limitfps = Config::LimitFPS && !fastforward;
|
||||||
if (limitfps)
|
if (limitfps)
|
||||||
{
|
{
|
||||||
float wantedtickF = starttick + (framerate * (fpslimitcount+1));
|
float wantedtickF = starttick + (framerate * (fpslimitcount+1));
|
||||||
|
@ -2269,7 +2304,7 @@ void ApplyNewSettings(int type)
|
||||||
GPU3D::InitRenderer(Screen_UseGL);
|
GPU3D::InitRenderer(Screen_UseGL);
|
||||||
if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
|
if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
|
||||||
}
|
}
|
||||||
else if (type == 4) // vsync
|
/*else if (type == 4) // vsync
|
||||||
{
|
{
|
||||||
if (Screen_UseGL)
|
if (Screen_UseGL)
|
||||||
{
|
{
|
||||||
|
@ -2281,7 +2316,7 @@ void ApplyNewSettings(int type)
|
||||||
{
|
{
|
||||||
// TODO eventually: VSync for non-GL screen?
|
// TODO eventually: VSync for non-GL screen?
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
EmuRunning = prevstatus;
|
EmuRunning = prevstatus;
|
||||||
}
|
}
|
||||||
|
@ -2704,6 +2739,9 @@ int main(int argc, char** argv)
|
||||||
uiMenuItemSetChecked(MenuItem_AudioSync, Config::AudioSync==1);
|
uiMenuItemSetChecked(MenuItem_AudioSync, Config::AudioSync==1);
|
||||||
uiMenuItemSetChecked(MenuItem_ShowOSD, Config::ShowOSD==1);
|
uiMenuItemSetChecked(MenuItem_ShowOSD, Config::ShowOSD==1);
|
||||||
|
|
||||||
|
AudioSync = SDL_CreateCond();
|
||||||
|
AudioSyncLock = SDL_CreateMutex();
|
||||||
|
|
||||||
AudioFreq = 48000; // TODO: make configurable?
|
AudioFreq = 48000; // TODO: make configurable?
|
||||||
SDL_AudioSpec whatIwant, whatIget;
|
SDL_AudioSpec whatIwant, whatIget;
|
||||||
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
||||||
|
@ -2779,6 +2817,9 @@ int main(int argc, char** argv)
|
||||||
if (AudioDevice) SDL_CloseAudioDevice(AudioDevice);
|
if (AudioDevice) SDL_CloseAudioDevice(AudioDevice);
|
||||||
if (MicDevice) SDL_CloseAudioDevice(MicDevice);
|
if (MicDevice) SDL_CloseAudioDevice(MicDevice);
|
||||||
|
|
||||||
|
SDL_DestroyCond(AudioSync);
|
||||||
|
SDL_DestroyMutex(AudioSyncLock);
|
||||||
|
|
||||||
if (MicWavBuffer) delete[] MicWavBuffer;
|
if (MicWavBuffer) delete[] MicWavBuffer;
|
||||||
|
|
||||||
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);
|
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);
|
||||||
|
|
Loading…
Reference in New Issue