diff -ur jack-audio-connection-kit-0.100.7/config/os/generic/time.h jack/config/os/generic/time.h --- jack-audio-connection-kit-0.100.7/config/os/generic/time.h 2004-04-07 07:52:58.000000000 +0300 +++ jack/config/os/generic/time.h 2005-12-06 12:24:03.000000000 +0200 @@ -1,5 +1,6 @@ /* Copyright (C) 2001-2004 Paul Davis, Tilman Linneweh + Copyright (C) 2005 Jussi Laako Generic version, overridden by OS-specific definition when needed. @@ -23,48 +24,24 @@ #define __jack_time_h__ #include +#include #include -#include - -/* This is a kludge. We need one global instantiation of this - * variable in each address space. So, libjack/client.c declares the - * actual storage. Other source files will see it as an extern. */ -#define JACK_TIME_GLOBAL_DECL jack_time_t __jack_cpu_mhz -extern JACK_TIME_GLOBAL_DECL; static inline jack_time_t jack_get_microseconds (void) { - return get_cycles() / __jack_cpu_mhz; -} + jack_time_t jackTime; + struct timeval time; -/* This function is inspired by similar code in MPLayer. - * It should be quite portable - */ -static inline jack_time_t -jack_get_mhz (void) -{ - jack_time_t tsc_start, tsc_end; - struct timeval tv_start, tv_end; - long usec_delay; - jack_time_t mhz; - - tsc_start = get_cycles(); - gettimeofday(&tv_start, NULL); - usleep(100000); - tsc_end = get_cycles(); - gettimeofday(&tv_end, NULL); - - usec_delay = 1000000 * (tv_end.tv_sec - tv_start.tv_sec) - + (tv_end.tv_usec - tv_start.tv_usec); - mhz = (tsc_end - tsc_start) / usec_delay; - return mhz; + gettimeofday(&time, NULL); + jackTime = (jack_time_t) time.tv_sec * 1e6 + + (jack_time_t) time.tv_usec; + return jackTime; } /* This should only be called ONCE per process. */ static inline void jack_init_time () { - __jack_cpu_mhz = jack_get_mhz (); } #endif /* __jack_time_h__ */ diff -ur jack-audio-connection-kit-0.100.7/config/os/gnu-linux/time.h jack/config/os/gnu-linux/time.h --- jack-audio-connection-kit-0.100.7/config/os/gnu-linux/time.h 2004-03-25 21:31:44.000000000 +0200 +++ jack/config/os/gnu-linux/time.h 2005-12-06 16:30:20.000000000 +0200 @@ -1,5 +1,6 @@ /* Copyright (C) 2001-2003 Paul Davis + Copyright (C) 2005 Jussi Laako This is the GNU/Linux version. @@ -23,18 +24,35 @@ #define __jack_time_h__ #include +#include +#include #include #include -/* This is a kludge. We need one global instantiation of this - * variable in each address space. So, libjack/client.c declares the - * actual storage. Other source files will see it as an extern. */ +/* This is a kludge. We need one global instantiation of these + * variables in each address space. So, libjack/client.c declares the + * actual storage. Other source files will see those as an externs. */ #define JACK_TIME_GLOBAL_DECL jack_time_t __jack_cpu_mhz +#define JACK_TIME_SOURCE_DECL int __jack_clock_source +#define JACK_TIME_FUNC_DECL jack_time_t (*jack_get_microseconds) (void) extern JACK_TIME_GLOBAL_DECL; +extern JACK_TIME_SOURCE_DECL; +extern JACK_TIME_FUNC_DECL; -static inline jack_time_t -jack_get_microseconds (void) { - return get_cycles() / __jack_cpu_mhz; +static jack_time_t +jack_get_microseconds0 (void) { + jack_time_t jackTime; + struct timespec time; + + clock_gettime(CLOCK_MONOTONIC, &time); + jackTime = (jack_time_t) time.tv_sec * 1e6 + + (jack_time_t) time.tv_nsec / 1e3; + return jackTime; +} + +static jack_time_t +jack_get_microseconds1 (void) { + return get_cycles() / __jack_cpu_mhz; } /* @@ -94,4 +112,21 @@ __jack_cpu_mhz = jack_get_mhz (); } +/* Set time function. */ +static inline void +jack_set_clock_source (int clocksrc) +{ + __jack_clock_source = clocksrc; + switch (__jack_clock_source) + { + case 1: + jack_get_microseconds = jack_get_microseconds1; + break; + case 0: + default: + jack_get_microseconds = jack_get_microseconds0; + break; + } +} + #endif /* __jack_time_h__ */ diff -ur jack-audio-connection-kit-0.100.7/configure.ac jack/configure.ac --- jack-audio-connection-kit-0.100.7/configure.ac 2005-10-30 13:01:31.000000000 +0200 +++ jack/configure.ac 2005-12-06 14:13:09.000000000 +0200 @@ -126,6 +126,7 @@ AC_CHECK_FUNCS(on_exit atexit) AC_CHECK_FUNCS(posix_memalign) AC_CHECK_LIB(m, sin) +AC_CHECK_FUNC(clock_gettime, [], AC_CHECK_LIB(rt, clock_gettime)) # should we use mlockall() on this platform? if test "x$JACK_DO_NOT_MLOCK" = "x"; then diff -ur jack-audio-connection-kit-0.100.7/jack/engine.h jack/jack/engine.h --- jack-audio-connection-kit-0.100.7/jack/engine.h 2004-12-19 20:41:28.000000000 +0200 +++ jack/jack/engine.h 2005-12-06 13:47:39.000000000 +0200 @@ -169,6 +169,8 @@ int jack_get_fifo_fd (jack_engine_t *engine, unsigned int which_fifo); +extern int clock_source; + extern jack_client_internal_t * jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id); diff -ur jack-audio-connection-kit-0.100.7/jack/internal.h jack/jack/internal.h --- jack-audio-connection-kit-0.100.7/jack/internal.h 2005-08-22 23:48:24.000000000 +0300 +++ jack/jack/internal.h 2005-12-06 13:50:48.000000000 +0200 @@ -130,6 +130,7 @@ jack_time_t sync_time_left; jack_frame_timer_t frame_timer; int32_t internal; + int clock_source; pid_t engine_pid; jack_nframes_t buffer_size; int8_t real_time; diff -ur jack-audio-connection-kit-0.100.7/jackd/engine.c jack/jackd/engine.c --- jack-audio-connection-kit-0.100.7/jackd/engine.c 2005-06-15 12:18:40.000000000 +0300 +++ jack/jackd/engine.c 2005-12-06 16:21:50.000000000 +0200 @@ -78,6 +78,8 @@ dlhandle handle; } jack_driver_info_t; +int clock_source = 0; + static int jack_port_assign_buffer (jack_engine_t *, jack_port_internal_t *); static jack_port_internal_t *jack_get_port_by_name (jack_engine_t *, @@ -1679,6 +1681,13 @@ engine->control->xrun_delayed_usecs = 0; engine->control->max_delayed_usecs = 0; +#ifdef JACK_TIME_FUNC_DECL + jack_set_clock_source(clock_source); +#else + __jack_clock_source = clock_source; +#endif + engine->control->clock_source = clock_source; + engine->control->frame_timer.frames = 0; engine->control->frame_timer.reset_pending = 0; engine->control->frame_timer.current_wakeup = 0; diff -ur jack-audio-connection-kit-0.100.7/jackd/jackd.c jack/jackd/jackd.c --- jack-audio-connection-kit-0.100.7/jackd/jackd.c 2005-06-15 12:18:40.000000000 +0300 +++ jack/jackd/jackd.c 2005-12-06 13:52:15.000000000 +0200 @@ -368,6 +368,7 @@ " [ --verbose OR -v ]\n" " [ --silent OR -s ]\n" " [ --version OR -V ]\n" +" [ --clock-source OR -c ]\n" " -d driver [ ... driver args ... ]\n" " where driver can be `alsa', `coreaudio', `dummy',\n" " `oss' or `portaudio'\n\n" @@ -463,7 +464,7 @@ { jack_driver_desc_t * desc; - const char *options = "-ad:P:uvshVRTFl:t:mn:p:"; + const char *options = "-ad:P:uvshVRTFl:t:mn:p:c:"; struct option long_options[] = { { "driver", 1, 0, 'd' }, @@ -479,6 +480,7 @@ { "temporary", 0, 0, 'T' }, { "version", 0, 0, 'V' }, { "silent", 0, 0, 's' }, + { "clock-source", 1, 0, 'c' }, { 0, 0, 0, 0 } }; int opt = 0; @@ -586,6 +588,10 @@ show_version = 1; break; + case 'c': + clock_source = atoi (optarg); + break; + default: fprintf (stderr, "unknown option character %c\n", optopt); diff -ur jack-audio-connection-kit-0.100.7/libjack/client.c jack/libjack/client.c --- jack-audio-connection-kit-0.100.7/libjack/client.c 2005-09-11 02:58:43.000000000 +0300 +++ jack/libjack/client.c 2005-12-06 16:21:12.000000000 +0200 @@ -51,6 +51,10 @@ #include JACK_TIME_GLOBAL_DECL; /* One instance per process. */ +JACK_TIME_SOURCE_DECL; /* One instance per process. */ +#ifdef JACK_TIME_FUNC_DECL +JACK_TIME_FUNC_DECL; +#endif #include "local.h" @@ -959,6 +963,13 @@ client->engine = (jack_control_t *) jack_shm_addr (&client->engine_shm); + /* initialize clock source as early as possible */ +#ifdef JACK_TIME_FUNC_DECL + jack_set_clock_source(client->engine->clock_source); +#else + __jack_clock_source = client->engine->clock_source; +#endif + /* now attach the client control block */ client->control_shm = res.client_shm; if (jack_attach_shm (&client->control_shm)) {