diff options
-rw-r--r-- | apps/plugins/fft/fft.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c index 23c37fb72c..dc118ec0c1 100644 --- a/apps/plugins/fft/fft.c +++ b/apps/plugins/fft/fft.c | |||
@@ -1294,7 +1294,7 @@ static void fft_close_fft(void) | |||
1294 | * target uses IRAM */ | 1294 | * target uses IRAM */ |
1295 | static bool fft_have_fft(void) | 1295 | static bool fft_have_fft(void) |
1296 | { | 1296 | { |
1297 | return fft_get_fft(); | 1297 | return rb->pcm_is_playing() && fft_get_fft(); |
1298 | } | 1298 | } |
1299 | 1299 | ||
1300 | static inline void fft_free_fft_output(void) | 1300 | static inline void fft_free_fft_output(void) |
@@ -1355,6 +1355,9 @@ enum plugin_status plugin_start(const void* parameter) | |||
1355 | 1355 | ||
1356 | while (run) | 1356 | while (run) |
1357 | { | 1357 | { |
1358 | /* Unless otherwise specified, HZ/50 is around the window length | ||
1359 | * and quite fast. We want to be done with drawing by this time. */ | ||
1360 | long next_frame_tick = *rb->current_tick + HZ/50; | ||
1358 | int button; | 1361 | int button; |
1359 | 1362 | ||
1360 | while (!fft_have_fft()) | 1363 | while (!fft_have_fft()) |
@@ -1378,13 +1381,13 @@ enum plugin_status plugin_start(const void* parameter) | |||
1378 | lcd_(update)(); | 1381 | lcd_(update)(); |
1379 | } | 1382 | } |
1380 | 1383 | ||
1381 | timeout = HZ/100; | 1384 | timeout = HZ/100; /* 'till end of curent tick, don't use 100% CPU */ |
1382 | } | 1385 | } |
1383 | 1386 | ||
1384 | /* Make sure the input thread has produced something before doing | 1387 | /* Make sure the FFT has produced something before doing anything |
1385 | * anything but watching for buttons. Music might not be playing | 1388 | * but watching for buttons. Music might not be playing or things |
1386 | * or things just aren't going well for picking up buffers so keys | 1389 | * just aren't going well for picking up buffers so keys are |
1387 | * are scanned to avoid lockup. */ | 1390 | * scanned to avoid lockup. */ |
1388 | button = rb->button_get_w_tmo(timeout); | 1391 | button = rb->button_get_w_tmo(timeout); |
1389 | if (button != BUTTON_NONE) | 1392 | if (button != BUTTON_NONE) |
1390 | goto read_button; | 1393 | goto read_button; |
@@ -1394,9 +1397,18 @@ enum plugin_status plugin_start(const void* parameter) | |||
1394 | 1397 | ||
1395 | fft_free_fft_output(); /* COP only */ | 1398 | fft_free_fft_output(); /* COP only */ |
1396 | 1399 | ||
1397 | rb->yield(); | 1400 | long tick = *rb->current_tick; |
1401 | if(TIME_BEFORE(tick, next_frame_tick)) | ||
1402 | { | ||
1403 | tick = next_frame_tick - tick; | ||
1404 | } | ||
1405 | else | ||
1406 | { | ||
1407 | rb->yield(); /* tmo = 0 won't yield */ | ||
1408 | tick = 0; | ||
1409 | } | ||
1398 | 1410 | ||
1399 | button = rb->button_get(false); | 1411 | button = rb->button_get_w_tmo(tick); |
1400 | read_button: | 1412 | read_button: |
1401 | switch (button) | 1413 | switch (button) |
1402 | { | 1414 | { |