13
0

replace gettimeofday() with g_get_monotonic_time()

This commit is contained in:
Robin Gareus 2014-05-16 18:13:08 +02:00
parent 51d0792f14
commit 4ece16be8e
2 changed files with 13 additions and 13 deletions

View File

@ -336,9 +336,9 @@ void* gui_event_loop (void* ptr)
VSTState* vstfx; VSTState* vstfx;
int LXVST_sched_timer_interval = 40; //ms, 25fps int LXVST_sched_timer_interval = 40; //ms, 25fps
XEvent event; XEvent event;
struct timeval clock1, clock2; uint64_t clock1, clock2;
gettimeofday(&clock1, NULL); clock1 = g_get_monotonic_time();
/*The 'Forever' loop - runs the plugin UIs etc - based on the FST gui event loop*/ /*The 'Forever' loop - runs the plugin UIs etc - based on the FST gui event loop*/
while (!gui_quit) while (!gui_quit)
@ -382,12 +382,12 @@ void* gui_event_loop (void* ptr)
/*See if its time for us to do a scheduled event pass on all the plugins*/ /*See if its time for us to do a scheduled event pass on all the plugins*/
gettimeofday(&clock2, NULL); clock2 = g_get_monotonic_time();
const int elapsed_time = (clock2.tv_sec - clock1.tv_sec) * 1000 + (clock2.tv_usec - clock1.tv_usec) / 1000; const int64_t elapsed_time_ms = (clock2 - clock1) / 1000;
if((LXVST_sched_timer_interval != 0) && elapsed_time >= LXVST_sched_timer_interval) if((LXVST_sched_timer_interval != 0) && elapsed_time_ms >= LXVST_sched_timer_interval)
{ {
//printf("elapsed %d ms ^= %.2f Hz\n", elapsed_time, 1000.0/(double)elapsed_time); // DEBUG //printf("elapsed %d ms ^= %.2f Hz\n", elapsed_time_ms, 1000.0/(double)elapsed_time_ms); // DEBUG
pthread_mutex_lock (&plugin_mutex); pthread_mutex_lock (&plugin_mutex);
again: again:
@ -463,7 +463,7 @@ again:
} }
pthread_mutex_unlock (&plugin_mutex); pthread_mutex_unlock (&plugin_mutex);
gettimeofday(&clock1, NULL); clock1 = g_get_monotonic_time();
} }
} }

View File

@ -1001,17 +1001,17 @@ DummyAudioBackend::main_process_thread ()
_running = true; _running = true;
_processed_samples = 0; _processed_samples = 0;
struct timeval clock1, clock2; uint64_t clock1, clock2;
::gettimeofday (&clock1, NULL); clock1 = g_get_monotonic_time();
while (_running) { while (_running) {
if (engine.process_callback (_samples_per_period)) { if (engine.process_callback (_samples_per_period)) {
return 0; return 0;
} }
_processed_samples += _samples_per_period; _processed_samples += _samples_per_period;
if (!_freewheeling) { if (!_freewheeling) {
::gettimeofday (&clock2, NULL); clock2 = g_get_monotonic_time();
const int elapsed_time = (clock2.tv_sec - clock1.tv_sec) * 1000000 + (clock2.tv_usec - clock1.tv_usec); const int64_t elapsed_time = clock2 - clock1;
const int nomial_time = 1000000 * _samples_per_period / _samplerate; const int64_t nomial_time = 1e6 * _samples_per_period / _samplerate;
_dsp_load = elapsed_time / (float) nomial_time; _dsp_load = elapsed_time / (float) nomial_time;
if (elapsed_time < nomial_time) { if (elapsed_time < nomial_time) {
::usleep (nomial_time - elapsed_time); ::usleep (nomial_time - elapsed_time);
@ -1022,7 +1022,7 @@ DummyAudioBackend::main_process_thread ()
_dsp_load = 1.0; _dsp_load = 1.0;
::usleep (100); // don't hog cpu ::usleep (100); // don't hog cpu
} }
::gettimeofday (&clock1, NULL); clock1 = g_get_monotonic_time();
} }
_running = false; _running = false;
return 0; return 0;