diff --git a/src/libespeak-ng/event.c b/src/libespeak-ng/event.c index 488b47b7..9cbbc40c 100644 --- a/src/libespeak-ng/event.c +++ b/src/libespeak-ng/event.c @@ -478,3 +478,30 @@ void event_terminate() thread_inited = 0; } } + +enum { ONE_BILLION = 1000000000 }; + +void clock_gettime2(struct timespec *ts) +{ + struct timeval tv; + + if (!ts) + return; + + assert(gettimeofday(&tv, NULL) != -1); + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec*1000; +} + +void add_time_in_ms(struct timespec *ts, int time_in_ms) +{ + if (!ts) + return; + + uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; + while (t_ns >= ONE_BILLION) { + ts->tv_sec += 1; + t_ns -= ONE_BILLION; + } + ts->tv_nsec = (long int)t_ns; +} diff --git a/src/libespeak-ng/wave.c b/src/libespeak-ng/wave.c index 9d19895c..dc76cb14 100644 --- a/src/libespeak-ng/wave.c +++ b/src/libespeak-ng/wave.c @@ -46,8 +46,6 @@ struct timespec { }; #endif -enum { ONE_BILLION = 1000000000 }; - #ifdef USE_PORTAUDIO #include "portaudio.h" @@ -905,28 +903,3 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time) } #endif - -void clock_gettime2(struct timespec *ts) -{ - struct timeval tv; - - if (!ts) - return; - - assert(gettimeofday(&tv, NULL) != -1); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec*1000; -} - -void add_time_in_ms(struct timespec *ts, int time_in_ms) -{ - if (!ts) - return; - - uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; - while (t_ns >= ONE_BILLION) { - ts->tv_sec += 1; - t_ns -= ONE_BILLION; - } - ts->tv_nsec = (long int)t_ns; -} diff --git a/src/libespeak-ng/wave_pulse.c b/src/libespeak-ng/wave_pulse.c index cb3a1e19..96d1a92f 100644 --- a/src/libespeak-ng/wave_pulse.c +++ b/src/libespeak-ng/wave_pulse.c @@ -44,8 +44,6 @@ #endif #include "wave.h" -enum { ONE_BILLION = 1000000000 }; - enum { /* return value */ PULSE_OK = 0, @@ -669,32 +667,3 @@ void *wave_test_get_write_buffer() } #endif - -#ifndef USE_PORTAUDIO - -void clock_gettime2(struct timespec *ts) -{ - struct timeval tv; - - if (!ts) - return; - - assert(gettimeofday(&tv, NULL) != -1); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec*1000; -} - -void add_time_in_ms(struct timespec *ts, int time_in_ms) -{ - if (!ts) - return; - - uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; - while (t_ns >= ONE_BILLION) { - ts->tv_sec += 1; - t_ns -= ONE_BILLION; - } - ts->tv_nsec = (long int)t_ns; -} - -#endif diff --git a/src/libespeak-ng/wave_sada.c b/src/libespeak-ng/wave_sada.c index 452fb6e9..5d416407 100644 --- a/src/libespeak-ng/wave_sada.c +++ b/src/libespeak-ng/wave_sada.c @@ -32,7 +32,6 @@ #include "wave.h" -enum { ONE_BILLION = 1000000000 }; #define SAMPLE_RATE 22050 #define SAMPLE_SIZE 16 @@ -422,28 +421,3 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time) } #endif - -void clock_gettime2(struct timespec *ts) -{ - struct timeval tv; - - if (!ts) - return; - - assert(gettimeofday(&tv, NULL) != -1); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec*1000; -} - -void add_time_in_ms(struct timespec *ts, int time_in_ms) -{ - if (!ts) - return; - - uint64_t t_ns = (uint64_t)ts->tv_nsec + 1000000 * (uint64_t)time_in_ms; - while (t_ns >= ONE_BILLION) { - ts->tv_sec += 1; - t_ns -= ONE_BILLION; - } - ts->tv_nsec = (long int)t_ns; -}