aboutsummaryrefslogtreecommitdiff
path: root/plat_sdl.c
diff options
context:
space:
mode:
authorneonloop2023-01-08 22:29:59 +0000
committerneonloop2023-01-08 22:29:59 +0000
commit50d426b6d2c84d4ddc32009268d99047e83ced7f (patch)
treeee836e28086304fdcd33f8fa52ad6ab5e2fa346c /plat_sdl.c
parent22d451f5c51695194d7a67c468a449e49097a6d3 (diff)
downloadpicoarch-50d426b6d2c84d4ddc32009268d99047e83ced7f.tar.gz
picoarch-50d426b6d2c84d4ddc32009268d99047e83ced7f.tar.bz2
picoarch-50d426b6d2c84d4ddc32009268d99047e83ced7f.zip
Uses eggs' fixes for dynamic audio rate control
Diffstat (limited to 'plat_sdl.c')
-rw-r--r--plat_sdl.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/plat_sdl.c b/plat_sdl.c
index af2d6bf..d938341 100644
--- a/plat_sdl.c
+++ b/plat_sdl.c
@@ -1,5 +1,6 @@
#include <SDL/SDL.h>
#include <unistd.h>
+#include <sys/time.h>
#include "core.h"
#include "libpicofe/fonts.h"
#include "libpicofe/plat.h"
@@ -38,6 +39,18 @@ static unsigned msg_expire = 0;
static bool frame_dirty = false;
static int frame_time = 1000000 / 60;
+static uint64_t plat_get_ticks_us_u64(void) {
+ uint64_t ret;
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ ret = (uint64_t)tv.tv_sec * 1000000;
+ ret += (uint64_t)tv.tv_usec;
+
+ return ret;
+}
+
static void video_expire_msg(void)
{
msg[0] = '\0';
@@ -240,26 +253,39 @@ void plat_video_process(const void *data, unsigned width, unsigned height, size_
void plat_video_flip(void)
{
- static unsigned int next_frame_time_us = 0;
+ static uint64_t next_frame_time_us = 0;
if (frame_dirty) {
- unsigned int time = plat_get_ticks_us();
+ if (enable_drc) {
+ uint64_t time = plat_get_ticks_us_u64();
- if (limit_frames && enable_drc && time < next_frame_time_us) {
- usleep(next_frame_time_us - time);
- }
+ if (limit_frames && time < next_frame_time_us) {
+ uint32_t delaytime = (next_frame_time_us - time - 1) / 1000 + 1;
- if (!next_frame_time_us)
- next_frame_time_us = time;
+ if (delaytime < 1000)
+ SDL_Delay(delaytime);
+ else
+ next_frame_time_us = 0;
- fb_flip();
+ time = plat_get_ticks_us_u64();
+ }
- do {
- next_frame_time_us += frame_time;
- } while (next_frame_time_us < time);
- }
+ if (!next_frame_time_us || !limit_frames) {
+ next_frame_time_us = time;
+ }
+
+ fb_flip();
+
+ do {
+ next_frame_time_us += frame_time;
+ } while (next_frame_time_us < time);
+ } else {
+ fb_flip();
+ next_frame_time_us = 0;
+ }
- frame_dirty = false;
+ frame_dirty = false;
+ }
}
void plat_video_close(void)