From b103d7c810fa11cf3ea70ef289885ae57cde8f77 Mon Sep 17 00:00:00 2001 From: joq Date: Tue, 4 Jul 2006 03:14:01 +0000 Subject: [PATCH] r3403@lithium: joq | 2006-07-03 21:04:52 -0500 Committed dummy backend timing improvements. git-svn-id: svn+ssh://jackaudio.org/trunk/jack@980 0c269be4-1314-0410-8aa9-9f06e86f4224 --- configure.ac | 3 ++- drivers/dummy/dummy_driver.c | 44 +++++++++++++++++++++++------------- drivers/dummy/dummy_driver.h | 1 + 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index f644fed..0a81a5a 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ dnl changes are made dnl --- JACK_MAJOR_VERSION=0 JACK_MINOR_VERSION=102 -JACK_MICRO_VERSION=18 +JACK_MICRO_VERSION=19 dnl --- dnl HOWTO: updating the jack protocol version @@ -699,6 +699,7 @@ echo \| Build with FreeBob support............................ : $HAVE_FREEBOB echo \| Build with OSS support................................ : $HAVE_OSS echo \| Build with CoreAudio support.......................... : $HAVE_COREAUDIO echo \| Build with PortAudio support.......................... : $HAVE_PA +echo \| Install prefix........................................ : $prefix echo \| Compiler optimization flags........................... : $JACK_OPT_CFLAGS echo \| Compiler full flags................................... : $CFLAGS echo \| Install dir for libjack + backends.................... : $libdir/jack diff --git a/drivers/dummy/dummy_driver.c b/drivers/dummy/dummy_driver.c index 76a3a39..897735a 100644 --- a/drivers/dummy/dummy_driver.c +++ b/drivers/dummy/dummy_driver.c @@ -38,19 +38,38 @@ #undef DEBUG_WAKEUP +/* this is used for calculate what counts as an xrun */ +#define PRETEND_BUFFER_SIZE 4096 static jack_nframes_t dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status, float *delayed_usecs) { - jack_time_t starting_time = jack_get_microseconds(); - jack_time_t processing_time = (driver->last_wait_ust? - starting_time - driver->last_wait_ust: - 0); - - /* wait until time for next cycle */ - if (driver->wait_time > processing_time) - usleep (driver->wait_time - processing_time); + jack_time_t now = jack_get_microseconds(); + + if (driver->next_time < now) { + if (driver->next_time == 0) { + /* first time through */ + driver->next_time = now + driver->wait_time; + } else if (now - driver->next_time + > (PRETEND_BUFFER_SIZE * 1000000LL + / driver->sample_rate)) { + /* xrun */ + fprintf(stderr,"**** dummy: xrun of %ju usec\n", + (uintmax_t)now - driver->next_time); + driver->next_time = now + driver->wait_time; + } else { + /* late, but handled by our "buffer"; try to + * get back on track */ + driver->next_time += driver->wait_time; + } + } else { + jack_time_t wait = driver->next_time - now; + struct timespec ts = { .tv_sec = wait / 1000000, + .tv_nsec = (wait % 1000000) * 1000 }; + nanosleep(&ts,NULL); + driver->next_time += driver->wait_time; + } driver->last_wait_ust = jack_get_microseconds (); driver->engine->transport_cycle_start (driver->engine, @@ -96,14 +115,6 @@ dummy_driver_null_cycle (dummy_driver_t* driver, jack_nframes_t nframes) static int dummy_driver_bufsize (dummy_driver_t* driver, jack_nframes_t nframes) { - /* This is a somewhat arbitrary size restriction. The dummy - * driver doesn't work well with smaller buffer sizes, - * apparantly due to usleep() inaccuracy under Linux 2.4. If - * you can get it working with smaller buffers, lower the - * limit. (JOQ) */ - if (nframes < 128) - return EINVAL; - driver->period_size = nframes; driver->period_usecs = driver->wait_time = (jack_time_t) floor ((((float) nframes) / driver->sample_rate) @@ -243,6 +254,7 @@ dummy_driver_new (jack_client_t * client, driver->sample_rate = sample_rate; driver->period_size = period_size; driver->wait_time = wait_time; + driver->next_time = 0; driver->last_wait_ust = 0; driver->capture_channels = capture_ports; diff --git a/drivers/dummy/dummy_driver.h b/drivers/dummy/dummy_driver.h index 57f6e48..7fd9d22 100644 --- a/drivers/dummy/dummy_driver.h +++ b/drivers/dummy/dummy_driver.h @@ -36,6 +36,7 @@ struct _dummy_driver jack_nframes_t sample_rate; jack_nframes_t period_size; unsigned long wait_time; + jack_time_t next_time; unsigned int capture_channels; unsigned int playback_channels;