From 4bc7fbd0977a21ae995295d2f6206989306daf0a Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Aug 2010 19:49:54 +0200 Subject: [PATCH] FPS checking. --- alsa.c | 6 ++++-- config.h | 2 +- gl.c | 32 ++++++++++++++++++++++++++++++++ oss.c | 7 +++++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/alsa.c b/alsa.c index 6161b79454..07d8c631f8 100644 --- a/alsa.c +++ b/alsa.c @@ -142,8 +142,10 @@ static bool __alsa_stop(void *data) static void __alsa_set_nonblock_state(void *data, bool state) { alsa_t *alsa = data; - snd_pcm_nonblock(alsa->pcm, state); - alsa->nonblock = state; + if (snd_pcm_nonblock(alsa->pcm, state) < 0) + fprintf(stderr, "SSNES [ERROR]: Could not set PCM to non-blocking. Will not be able to fast-forward.\n"); + else + alsa->nonblock = state; } static bool __alsa_start(void *data) diff --git a/config.h b/config.h index 0ebed708cf..1ae612f814 100644 --- a/config.h +++ b/config.h @@ -92,7 +92,7 @@ static const char* audio_device = NULL; static const int out_latency = 64; // Defines the quality (and cpu reqirements) of samplerate conversion. -#define SAMPLERATE_QUALITY SRC_SINC_FASTEST +#define SAMPLERATE_QUALITY SRC_LINEAR diff --git a/gl.c b/gl.c index c81c3f3032..3e25b8e5fd 100644 --- a/gl.c +++ b/gl.c @@ -21,6 +21,7 @@ #include #include "libsnes.hpp" #include +#include static GLuint texture; static uint8_t *gl_buffer; @@ -143,6 +144,12 @@ static void GLFWCALL resize(int width, int height) glLoadIdentity(); } +static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames) +{ + float time = new_tv->tv_sec - tv->tv_sec + (new_tv->tv_usec - tv->tv_usec)/1000000.0; + return frames/time; +} + static bool gl_frame(void *data, const uint16_t* frame, int width, int height) { (void)data; @@ -175,6 +182,31 @@ static bool gl_frame(void *data, const uint16_t* frame, int width, int height) glEnd(); + // Shows FPS in taskbar. + static int frames = 0; + static struct timeval tv; + struct timeval new_tv; + + if (frames == 0) + gettimeofday(&tv, NULL); + + if ((frames % 60) == 0 && frames > 0) + { + gettimeofday(&new_tv, NULL); + struct timeval tmp_tv = { + .tv_sec = tv.tv_sec, + .tv_usec = tv.tv_usec + }; + gettimeofday(&tv, NULL); + char tmpstr[256] = {0}; + + float fps = tv_to_fps(&tmp_tv, &new_tv, 60); + + snprintf(tmpstr, sizeof(tmpstr) - 1, "SSNES || FPS: %6.1f || Frames: %d", fps, frames); + glfwSetWindowTitle(tmpstr); + } + frames++; + glfwSwapBuffers(); return true; diff --git a/oss.c b/oss.c index 6e23067614..fe5c51b4e5 100644 --- a/oss.c +++ b/oss.c @@ -111,10 +111,13 @@ static bool __oss_start(void *data) static void __oss_set_nonblock_state(void *data, bool state) { int *fd = data; + int rc; if (state) - fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK); + rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK); else - fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) & (~O_NONBLOCK)); + rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) & (~O_NONBLOCK)); + if (rc != 0) + fprintf(stderr, "SSNES [ERROR]: Could not set nonblocking on OSS file descriptor. Will not be able to fast-forward.\n"); } static void __oss_free(void *data)