diff options
Diffstat (limited to 'drivers/sun/sun_driver.c')
-rw-r--r-- | drivers/sun/sun_driver.c | 1326 |
1 files changed, 614 insertions, 712 deletions
diff --git a/drivers/sun/sun_driver.c b/drivers/sun/sun_driver.c index 1d1af3e..accb620 100644 --- a/drivers/sun/sun_driver.c +++ b/drivers/sun/sun_driver.c @@ -1,27 +1,27 @@ /* - Sun Audio API driver for Jack - Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org> - Based heavily on oss_driver.c which came with the following - copyright notice. + Sun Audio API driver for Jack + Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org> + Based heavily on oss_driver.c which came with the following + copyright notice. - Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net> + Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net> - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, - MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, + MA 02111-1307 USA -*/ + */ #include <config.h> @@ -60,85 +60,74 @@ #include "sun_driver.h" -#define SUN_DRIVER_N_PARAMS 11 +#define SUN_DRIVER_N_PARAMS 11 const static jack_driver_param_desc_t sun_params[SUN_DRIVER_N_PARAMS] = { { "rate", - 'r', - JackDriverParamUInt, - { .ui = SUN_DRIVER_DEF_FS }, - "sample rate", - "sample rate" - }, + 'r', + JackDriverParamUInt, + { .ui = SUN_DRIVER_DEF_FS }, + "sample rate", + "sample rate" }, { "period", - 'p', - JackDriverParamUInt, - { .ui = SUN_DRIVER_DEF_BLKSIZE }, - "period size", - "period size" - }, + 'p', + JackDriverParamUInt, + { .ui = SUN_DRIVER_DEF_BLKSIZE }, + "period size", + "period size" }, { "nperiods", - 'n', - JackDriverParamUInt, - { .ui = SUN_DRIVER_DEF_NPERIODS }, - "number of periods in buffer", - "number of periods in buffer" - }, + 'n', + JackDriverParamUInt, + { .ui = SUN_DRIVER_DEF_NPERIODS }, + "number of periods in buffer", + "number of periods in buffer" }, { "wordlength", - 'w', - JackDriverParamInt, - { .i = SUN_DRIVER_DEF_BITS }, - "word length", - "word length" - }, + 'w', + JackDriverParamInt, + { .i = SUN_DRIVER_DEF_BITS }, + "word length", + "word length" }, { "inchannels", - 'i', - JackDriverParamUInt, - { .ui = SUN_DRIVER_DEF_INS }, - "capture channels", - "capture channels" - }, + 'i', + JackDriverParamUInt, + { .ui = SUN_DRIVER_DEF_INS }, + "capture channels", + "capture channels" }, { "outchannels", - 'o', - JackDriverParamUInt, - { .ui = SUN_DRIVER_DEF_OUTS }, - "playback channels", - "playback channels" - }, + 'o', + JackDriverParamUInt, + { .ui = SUN_DRIVER_DEF_OUTS }, + "playback channels", + "playback channels" }, { "capture", - 'C', - JackDriverParamString, - { .str = SUN_DRIVER_DEF_DEV }, - "input device", - "input device" - }, + 'C', + JackDriverParamString, + { .str = SUN_DRIVER_DEF_DEV }, + "input device", + "input device" }, { "playback", - 'P', - JackDriverParamString, - { .str = SUN_DRIVER_DEF_DEV }, - "output device", - "output device" - }, + 'P', + JackDriverParamString, + { .str = SUN_DRIVER_DEF_DEV }, + "output device", + "output device" }, { "ignorehwbuf", - 'b', - JackDriverParamBool, - { }, - "ignore hardware period size", - "ignore hardware period size" - }, + 'b', + JackDriverParamBool, + { }, + "ignore hardware period size", + "ignore hardware period size" }, { "input latency", - 'I', - JackDriverParamUInt, - { .ui = 0 }, - "system input latency", - "system input latency" - }, + 'I', + JackDriverParamUInt, + { .ui = 0 }, + "system input latency", + "system input latency" }, { "output latency", - 'O', - JackDriverParamUInt, - { .ui = 0 }, - "system output latency", - "system output latency" - } + 'O', + JackDriverParamUInt, + { .ui = 0 }, + "system output latency", + "system output latency" } }; @@ -150,9 +139,9 @@ set_period_size (sun_driver_t *driver, jack_nframes_t new_period_size) { driver->period_size = new_period_size; - driver->period_usecs = - ((double) driver->period_size / - (double) driver->sample_rate) * 1e6; + driver->period_usecs = + ((double)driver->period_size / + (double)driver->sample_rate) * 1e6; driver->last_wait_ust = 0; driver->iodelay = 0.0F; driver->poll_timeout = (int)(driver->period_usecs / 666); @@ -167,23 +156,21 @@ sun_driver_write_silence (sun_driver_t *driver, jack_nframes_t nframes) void *localbuf; localsize = nframes * driver->sample_bytes * driver->playback_channels; - localbuf = malloc(localsize); - if (localbuf == NULL) - { - jack_error("sun_driver: malloc() failed: %s@%i", - __FILE__, __LINE__); + localbuf = malloc (localsize); + if (localbuf == NULL) { + jack_error ("sun_driver: malloc() failed: %s@%i", + __FILE__, __LINE__); return; } - bzero(localbuf, localsize); - io_res = write(driver->outfd, localbuf, localsize); - if (io_res < (ssize_t) localsize) - { - jack_error("sun_driver: write() failed: %s: " - "count=%d/%d: %s@%i", strerror(errno), io_res, - localsize, __FILE__, __LINE__); + bzero (localbuf, localsize); + io_res = write (driver->outfd, localbuf, localsize); + if (io_res < (ssize_t)localsize) { + jack_error ("sun_driver: write() failed: %s: " + "count=%d/%d: %s@%i", strerror (errno), io_res, + localsize, __FILE__, __LINE__); } - free(localbuf); + free (localbuf); } @@ -195,22 +182,20 @@ sun_driver_read_silence (sun_driver_t *driver, jack_nframes_t nframes) void *localbuf; localsize = nframes * driver->sample_bytes * driver->capture_channels; - localbuf = malloc(localsize); - if (localbuf == NULL) - { - jack_error("sun_driver: malloc() failed: %s@%i", - __FILE__, __LINE__); + localbuf = malloc (localsize); + if (localbuf == NULL) { + jack_error ("sun_driver: malloc() failed: %s@%i", + __FILE__, __LINE__); return; } - io_res = read(driver->infd, localbuf, localsize); - if (io_res < (ssize_t) localsize) - { - jack_error("sun_driver: read() failed: %s: " - "count=%d/%d: %s@%i", strerror(errno), io_res, - localsize, __FILE__, __LINE__); + io_res = read (driver->infd, localbuf, localsize); + if (io_res < (ssize_t)localsize) { + jack_error ("sun_driver: read() failed: %s: " + "count=%d/%d: %s@%i", strerror (errno), io_res, + localsize, __FILE__, __LINE__); } - free(localbuf); + free (localbuf); } @@ -235,63 +220,60 @@ sun_driver_wait (sun_driver_t *driver, int *status, float *iodelay) pfd[0].fd = driver->infd; pfd[0].events = POLLIN; - if (driver->infd >= 0) + if (driver->infd >= 0) { need_capture = 1; + } pfd[1].fd = driver->outfd; pfd[1].events = POLLOUT; - if (driver->outfd >= 0) + if (driver->outfd >= 0) { need_playback = 1; + } - poll_enter = driver->engine->get_microseconds(); - if (poll_enter > driver->poll_next) - { + poll_enter = driver->engine->get_microseconds (); + if (poll_enter > driver->poll_next) { /* late. don't count as wakeup delay. */ driver->poll_next = 0; } - while (need_capture || need_playback) - { - nfds = poll(pfd, 2, driver->poll_timeout); + while (need_capture || need_playback) { + nfds = poll (pfd, 2, driver->poll_timeout); if ( nfds == -1 || - ((pfd[0].revents | pfd[1].revents) & - (POLLERR | POLLHUP | POLLNVAL)) ) - { - jack_error("sun_driver: poll() error: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + ((pfd[0].revents | pfd[1].revents) & + (POLLERR | POLLHUP | POLLNVAL)) ) { + jack_error ("sun_driver: poll() error: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); *status = -3; return 0; } - if (nfds == 0) - { - jack_error("sun_driver: poll() timeout: %s@%i", - __FILE__, __LINE__); + if (nfds == 0) { + jack_error ("sun_driver: poll() timeout: %s@%i", + __FILE__, __LINE__); *status = -5; return 0; } - if (need_capture && (pfd[0].revents & POLLIN)) - { + if (need_capture && (pfd[0].revents & POLLIN)) { need_capture = 0; pfd[0].fd = -1; } - if (need_playback && (pfd[1].revents & POLLOUT)) - { + if (need_playback && (pfd[1].revents & POLLOUT)) { need_playback = 0; pfd[1].fd = -1; } } - poll_ret = driver->engine->get_microseconds(); + poll_ret = driver->engine->get_microseconds (); - if (driver->poll_next && poll_ret > driver->poll_next) + if (driver->poll_next && poll_ret > driver->poll_next) { *iodelay = poll_ret - driver->poll_next; + } driver->poll_last = poll_ret; driver->poll_next = poll_ret + driver->period_usecs; - driver->engine->transport_cycle_start(driver->engine, poll_ret); + driver->engine->transport_cycle_start (driver->engine, poll_ret); #if defined(AUDIO_RERROR) && defined(AUDIO_PERROR) @@ -304,95 +286,82 @@ sun_driver_wait (sun_driver_t *driver, int *status, float *iodelay) * before we can write enough playback data to catch up. */ - if (driver->infd >= 0) - { - if (ioctl(driver->infd, AUDIO_RERROR, &capture_errors) < 0) - { - jack_error("sun_driver: AUDIO_RERROR failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + if (driver->infd >= 0) { + if (ioctl (driver->infd, AUDIO_RERROR, &capture_errors) < 0) { + jack_error ("sun_driver: AUDIO_RERROR failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); return 0; } capture_errors -= driver->capture_drops; driver->capture_drops += capture_errors; } - if (capture_errors > 0) - { + if (capture_errors > 0) { delay = (capture_errors * 1000.0) / driver->sample_rate; - printf("sun_driver: capture xrun of %d frames (%f msec)\n", + printf ("sun_driver: capture xrun of %d frames (%f msec)\n", capture_errors, delay); } - if (driver->outfd >= 0) - { - if (ioctl(driver->outfd, AUDIO_PERROR, &playback_errors) < 0) - { - jack_error("sun_driver: AUDIO_PERROR failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + if (driver->outfd >= 0) { + if (ioctl (driver->outfd, AUDIO_PERROR, &playback_errors) < 0) { + jack_error ("sun_driver: AUDIO_PERROR failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); return 0; } playback_errors -= driver->playback_drops; driver->playback_drops += playback_errors; } - if (playback_errors > 0) - { + if (playback_errors > 0) { delay = (playback_errors * 1000.0) / driver->sample_rate; - printf("sun_driver: playback xrun of %d frames (%f msec)\n", + printf ("sun_driver: playback xrun of %d frames (%f msec)\n", playback_errors, delay); } if ((driver->outfd >= 0 && driver->infd >= 0) && - (capture_errors || playback_errors)) - { - if (ioctl(driver->infd, AUDIO_GETINFO, &auinfo) < 0) - { - jack_error("sun_driver: AUDIO_GETINFO failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + (capture_errors || playback_errors)) { + if (ioctl (driver->infd, AUDIO_GETINFO, &auinfo) < 0) { + jack_error ("sun_driver: AUDIO_GETINFO failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return 0; } capture_seek = auinfo.record.seek; - if (driver->infd == driver->outfd) + if (driver->infd == driver->outfd) { playback_seek = auinfo.play.seek; - else - { - if (ioctl(driver->outfd, AUDIO_GETINFO, &auinfo) < 0) - { - jack_error("sun_driver: AUDIO_GETINFO failed: " - "%s: %s@%i", strerror(errno), - __FILE__, __LINE__); + } else { + if (ioctl (driver->outfd, AUDIO_GETINFO, &auinfo) < 0) { + jack_error ("sun_driver: AUDIO_GETINFO failed: " + "%s: %s@%i", strerror (errno), + __FILE__, __LINE__); return 0; } playback_seek = auinfo.play.seek; } capture_seek /= driver->capture_channels * - driver->sample_bytes; + driver->sample_bytes; playback_seek /= driver->playback_channels * - driver->sample_bytes; + driver->sample_bytes; if (playback_seek == driver->period_size && - capture_seek == driver->period_size && - playback_errors) - { + capture_seek == driver->period_size && + playback_errors) { /* normally, 1 period in each buffer is exactly * what we want, but if there was an error then * we effectively have 0 periods in the playback * buffer, because the period in the buffer will * be used to catch up to realtime. */ - printf("sun_driver: writing %d frames of silence " + printf ("sun_driver: writing %d frames of silence " "to correct I/O sync\n", driver->period_size); - sun_driver_write_silence(driver, driver->period_size); - } - else if (capture_errors && playback_errors) - { + sun_driver_write_silence (driver, driver->period_size); + } else if (capture_errors && playback_errors) { /* serious delay. we've lost the ability to * write capture_errors frames to catch up on * playback. */ - printf("sun_driver: writing %d frames of silence " + printf ("sun_driver: writing %d frames of silence " "to correct I/O sync\n", capture_errors); - sun_driver_write_silence(driver, capture_errors); + sun_driver_write_silence (driver, capture_errors); } } @@ -416,22 +385,19 @@ sun_driver_run_cycle (sun_driver_t *driver) nframes = sun_driver_wait (driver, &wait_status, &iodelay); - if (wait_status < 0) - { - switch (wait_status) - { + if (wait_status < 0) { + switch (wait_status) { case -3: /* poll() error */ return -1; case -5: /* poll() timeout */ - now = driver->engine->get_microseconds(); - if (now > driver->poll_next) - { + now = driver->engine->get_microseconds (); + if (now > driver->poll_next) { iodelay = now - driver->poll_next; driver->poll_next = now + driver->period_usecs; - driver->engine->delay(driver->engine, iodelay); - printf("sun_driver: iodelay = %f\n", iodelay); + driver->engine->delay (driver->engine, iodelay); + printf ("sun_driver: iodelay = %f\n", iodelay); } break; default: @@ -440,116 +406,106 @@ sun_driver_run_cycle (sun_driver_t *driver) } } - return driver->engine->run_cycle(driver->engine, nframes, iodelay); + return driver->engine->run_cycle (driver->engine, nframes, iodelay); } static void -copy_and_convert_in (jack_sample_t *dst, void *src, - size_t nframes, int channel, int chcount, int bits) +copy_and_convert_in (jack_sample_t *dst, void *src, + size_t nframes, int channel, int chcount, int bits) { int srcidx; int dstidx; - signed short *s16src = (signed short *) src; - signed int *s32src = (signed int *) src; - double *f64src = (double *) src; + signed short *s16src = (signed short*)src; + signed int *s32src = (signed int*)src; + double *f64src = (double*)src; jack_sample_t scale; srcidx = channel; - switch (bits) - { - case 16: - scale = 1.0f / 0x7fff; - for (dstidx = 0; dstidx < nframes; dstidx++) - { - dst[dstidx] = (jack_sample_t) - s16src[srcidx] * scale; - srcidx += chcount; - } - break; - case 24: - scale = 1.0f / 0x7fffff; - for (dstidx = 0; dstidx < nframes; dstidx++) - { - dst[dstidx] = (jack_sample_t) - s32src[srcidx] * scale; - srcidx += chcount; - } - break; - case 32: - scale = 1.0f / 0x7fffffff; - for (dstidx = 0; dstidx < nframes; dstidx++) - { - dst[dstidx] = (jack_sample_t) - s32src[srcidx] * scale; - srcidx += chcount; - } - break; - case 64: - for (dstidx = 0; dstidx < nframes; dstidx++) - { - dst[dstidx] = (jack_sample_t) f64src[srcidx]; - srcidx += chcount; - } - break; + switch (bits) { + case 16: + scale = 1.0f / 0x7fff; + for (dstidx = 0; dstidx < nframes; dstidx++) { + dst[dstidx] = (jack_sample_t) + s16src[srcidx] * scale; + srcidx += chcount; + } + break; + case 24: + scale = 1.0f / 0x7fffff; + for (dstidx = 0; dstidx < nframes; dstidx++) { + dst[dstidx] = (jack_sample_t) + s32src[srcidx] * scale; + srcidx += chcount; + } + break; + case 32: + scale = 1.0f / 0x7fffffff; + for (dstidx = 0; dstidx < nframes; dstidx++) { + dst[dstidx] = (jack_sample_t) + s32src[srcidx] * scale; + srcidx += chcount; + } + break; + case 64: + for (dstidx = 0; dstidx < nframes; dstidx++) { + dst[dstidx] = (jack_sample_t)f64src[srcidx]; + srcidx += chcount; + } + break; } } static void -copy_and_convert_out (void *dst, jack_sample_t *src, - size_t nframes, int channel, int chcount, int bits) +copy_and_convert_out (void *dst, jack_sample_t *src, + size_t nframes, int channel, int chcount, int bits) { int srcidx; int dstidx; - signed short *s16dst = (signed short *) dst; - signed int *s32dst = (signed int *) dst; - double *f64dst = (double *) dst; + signed short *s16dst = (signed short*)dst; + signed int *s32dst = (signed int*)dst; + double *f64dst = (double*)dst; jack_sample_t scale; dstidx = channel; - switch (bits) - { - case 16: - scale = 0x7fff; - for (srcidx = 0; srcidx < nframes; srcidx++) - { - s16dst[dstidx] = (signed short) - (src[srcidx] >= 0.0f) ? - (src[srcidx] * scale + 0.5f) : - (src[srcidx] * scale - 0.5f); - dstidx += chcount; - } - break; - case 24: - scale = 0x7fffff; - for (srcidx = 0; srcidx < nframes; srcidx++) - { - s32dst[dstidx] = (signed int) - (src[srcidx] >= 0.0f) ? - (src[srcidx] * scale + 0.5f) : - (src[srcidx] * scale - 0.5f); - dstidx += chcount; - } - break; - case 32: - scale = 0x7fffffff; - for (srcidx = 0; srcidx < nframes; srcidx++) - { - s32dst[dstidx] = (signed int) - (src[srcidx] >= 0.0f) ? - (src[srcidx] * scale + 0.5f) : - (src[srcidx] * scale - 0.5f); - dstidx += chcount; - } - break; - case 64: - for (srcidx = 0; srcidx < nframes; srcidx++) - { - f64dst[dstidx] = (double) src[srcidx]; - dstidx += chcount; - } - break; + switch (bits) { + case 16: + scale = 0x7fff; + for (srcidx = 0; srcidx < nframes; srcidx++) { + s16dst[dstidx] = (signed short) + (src[srcidx] >= 0.0f) ? + (src[srcidx] * scale + 0.5f) : + (src[srcidx] * scale - 0.5f); + dstidx += chcount; + } + break; + case 24: + scale = 0x7fffff; + for (srcidx = 0; srcidx < nframes; srcidx++) { + s32dst[dstidx] = (signed int) + (src[srcidx] >= 0.0f) ? + (src[srcidx] * scale + 0.5f) : + (src[srcidx] * scale - 0.5f); + dstidx += chcount; + } + break; + case 32: + scale = 0x7fffffff; + for (srcidx = 0; srcidx < nframes; srcidx++) { + s32dst[dstidx] = (signed int) + (src[srcidx] >= 0.0f) ? + (src[srcidx] * scale + 0.5f) : + (src[srcidx] * scale - 0.5f); + dstidx += chcount; + } + break; + case 64: + for (srcidx = 0; srcidx < nframes; srcidx++) { + f64dst[dstidx] = (double)src[srcidx]; + dstidx += chcount; + } + break; } } @@ -566,53 +522,49 @@ sun_driver_attach (sun_driver_t *driver) jack_port_t *port; jack_latency_range_t range; - if (driver->engine->set_buffer_size(driver->engine, driver->period_size)) { + if (driver->engine->set_buffer_size (driver->engine, driver->period_size)) { jack_error ("sun_driver: cannot set engine buffer size to %d (check MIDI)", driver->period_size); return -1; } - driver->engine->set_sample_rate(driver->engine, driver->sample_rate); - - port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal; - - for (channel = 0; channel < driver->capture_channels; channel++) - { - snprintf(channel_name, sizeof(channel_name), - "capture_%u", channel + 1); - port = jack_port_register(driver->client, channel_name, - JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); - if (port == NULL) - { - jack_error("sun_driver: cannot register port for %s: " - "%s@%i", channel_name, __FILE__, __LINE__); + driver->engine->set_sample_rate (driver->engine, driver->sample_rate); + + port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal; + + for (channel = 0; channel < driver->capture_channels; channel++) { + snprintf (channel_name, sizeof(channel_name), + "capture_%u", channel + 1); + port = jack_port_register (driver->client, channel_name, + JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); + if (port == NULL) { + jack_error ("sun_driver: cannot register port for %s: " + "%s@%i", channel_name, __FILE__, __LINE__); break; } range.min = range.max = driver->period_size + driver->sys_in_latency; - jack_port_set_latency_range(port, JackCaptureLatency, &range); - driver->capture_ports = - jack_slist_append(driver->capture_ports, port); - } - - port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal; - for (channel = 0; channel < driver->playback_channels; channel++) - { - snprintf(channel_name, sizeof(channel_name), - "playback_%u", channel + 1); - port = jack_port_register(driver->client, channel_name, - JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); - if (port == NULL) - { - jack_error("sun_driver: cannot register port for " - "%s: %s@%i", channel_name, __FILE__, __LINE__); + jack_port_set_latency_range (port, JackCaptureLatency, &range); + driver->capture_ports = + jack_slist_append (driver->capture_ports, port); + } + + port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal; + for (channel = 0; channel < driver->playback_channels; channel++) { + snprintf (channel_name, sizeof(channel_name), + "playback_%u", channel + 1); + port = jack_port_register (driver->client, channel_name, + JACK_DEFAULT_AUDIO_TYPE, port_flags, 0); + if (port == NULL) { + jack_error ("sun_driver: cannot register port for " + "%s: %s@%i", channel_name, __FILE__, __LINE__); break; } range.min = range.max = driver->period_size + driver->sys_out_latency; - jack_port_set_latency_range(port, JackPlaybackLatency, &range); + jack_port_set_latency_range (port, JackPlaybackLatency, &range); driver->playback_ports = - jack_slist_append(driver->playback_ports, port); + jack_slist_append (driver->playback_ports, port); } - return jack_activate(driver->client); + return jack_activate (driver->client); } @@ -621,27 +573,26 @@ sun_driver_detach (sun_driver_t *driver) { JSList *node; - if (driver->engine == NULL) + if (driver->engine == NULL) { return 0; + } node = driver->capture_ports; - while (node != NULL) - { - jack_port_unregister(driver->client, - ((jack_port_t *) node->data)); - node = jack_slist_next(node); + while (node != NULL) { + jack_port_unregister (driver->client, + ((jack_port_t*)node->data)); + node = jack_slist_next (node); } - jack_slist_free(driver->capture_ports); + jack_slist_free (driver->capture_ports); driver->capture_ports = NULL; node = driver->playback_ports; - while (node != NULL) - { - jack_port_unregister(driver->client, - ((jack_port_t *) node->data)); - node = jack_slist_next(node); + while (node != NULL) { + jack_port_unregister (driver->client, + ((jack_port_t*)node->data)); + node = jack_slist_next (node); } - jack_slist_free(driver->playback_ports); + jack_slist_free (driver->playback_ports); driver->playback_ports = NULL; return 0; @@ -653,43 +604,38 @@ sun_driver_start (sun_driver_t *driver) { audio_info_t audio_if; - if (driver->infd >= 0) - { + if (driver->infd >= 0) { #if defined(AUDIO_FLUSH) - if (ioctl(driver->infd, AUDIO_FLUSH, NULL) < 0) - { - jack_error("sun_driver: capture flush failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (ioctl (driver->infd, AUDIO_FLUSH, NULL) < 0) { + jack_error ("sun_driver: capture flush failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } #endif - AUDIO_INITINFO(&audio_if); + AUDIO_INITINFO (&audio_if); audio_if.record.pause = 1; - if (driver->outfd == driver->infd) + if (driver->outfd == driver->infd) { audio_if.play.pause = 1; - if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: pause capture failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + } + if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: pause capture failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } - if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) - { + if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) { #if defined(AUDIO_FLUSH) - if (ioctl(driver->outfd, AUDIO_FLUSH, NULL) < 0) - { - jack_error("sun_driver: playback flush failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (ioctl (driver->outfd, AUDIO_FLUSH, NULL) < 0) { + jack_error ("sun_driver: playback flush failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } #endif - AUDIO_INITINFO(&audio_if); + AUDIO_INITINFO (&audio_if); audio_if.play.pause = 1; - if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: pause playback failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: pause playback failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } @@ -697,39 +643,35 @@ sun_driver_start (sun_driver_t *driver) /* AUDIO_FLUSH resets the counters these work with */ driver->playback_drops = driver->capture_drops = 0; - if (driver->outfd >= 0) - { + if (driver->outfd >= 0) { /* "prime" the playback buffer. if we don't do this, we'll * end up underrunning. it would get really ugly in duplex * mode, for example, where we have to wait for a period to * be available to read before we can write. also helps to * keep constant latency from the beginning. */ - sun_driver_write_silence(driver, - driver->nperiods * driver->period_size); + sun_driver_write_silence (driver, + driver->nperiods * driver->period_size); } - if (driver->infd >= 0) - { - AUDIO_INITINFO(&audio_if); + if (driver->infd >= 0) { + AUDIO_INITINFO (&audio_if); audio_if.record.pause = 0; - if (driver->outfd == driver->infd) + if (driver->outfd == driver->infd) { audio_if.play.pause = 0; - if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: start capture failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + } + if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: start capture failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } - if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) - { - AUDIO_INITINFO(&audio_if); + if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) { + AUDIO_INITINFO (&audio_if); audio_if.play.pause = 0; - if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: trigger playback failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: trigger playback failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } @@ -739,24 +681,27 @@ sun_driver_start (sun_driver_t *driver) static int -enc_equal(int a, int b) +enc_equal (int a, int b) { - if (a == b) + if (a == b) { return 1; + } -#if defined(AUDIO_ENCODING_SLINEAR) +#if defined(AUDIO_ENCODING_SLINEAR) #if BYTE_ORDER == LITTLE_ENDIAN if ((a == AUDIO_ENCODING_SLINEAR && b == AUDIO_ENCODING_SLINEAR_LE) || (a == AUDIO_ENCODING_SLINEAR_LE && b == AUDIO_ENCODING_SLINEAR) || (a == AUDIO_ENCODING_ULINEAR && b == AUDIO_ENCODING_ULINEAR_LE) || - (a == AUDIO_ENCODING_ULINEAR_LE && b == AUDIO_ENCODING_ULINEAR)) + (a == AUDIO_ENCODING_ULINEAR_LE && b == AUDIO_ENCODING_ULINEAR)) { return 1; + } #elif BYTE_ORDER == BIG_ENDIAN if ((a == AUDIO_ENCODING_SLINEAR && b == AUDIO_ENCODING_SLINEAR_BE) || (a == AUDIO_ENCODING_SLINEAR_BE && b == AUDIO_ENCODING_SLINEAR) || (a == AUDIO_ENCODING_ULINEAR && b == AUDIO_ENCODING_ULINEAR_BE) || - (a == AUDIO_ENCODING_ULINEAR_BE && b == AUDIO_ENCODING_ULINEAR)) + (a == AUDIO_ENCODING_ULINEAR_BE && b == AUDIO_ENCODING_ULINEAR)) { return 1; + } #endif #endif // AUDIO_ENCODING_SLINEAR return 0; @@ -778,75 +723,63 @@ sun_driver_set_parameters (sun_driver_t *driver) driver->outdevbuf = NULL; driver->sample_bytes = driver->bits / 8; - if ((strcmp(indev, outdev) == 0) && - ((driver->capture_channels > 0) && (driver->playback_channels > 0))) - { - infd = outfd = open(indev, O_RDWR); - if (infd < 0) - { - jack_error("sun_driver: failed to open duplex device " - "%s: %s: %s@%i", indev, strerror(errno), - __FILE__, __LINE__); + if ((strcmp (indev, outdev) == 0) && + ((driver->capture_channels > 0) && (driver->playback_channels > 0))) { + infd = outfd = open (indev, O_RDWR); + if (infd < 0) { + jack_error ("sun_driver: failed to open duplex device " + "%s: %s: %s@%i", indev, strerror (errno), + __FILE__, __LINE__); return -1; } #if defined(AUDIO_SETFD) - if (ioctl(infd, AUDIO_SETFD, &s) < 0) - { - jack_error("sun_driver: failed to enable full duplex: " - "%s: %s@%i", strerror(errno), - __FILE__, __LINE__); + if (ioctl (infd, AUDIO_SETFD, &s) < 0) { + jack_error ("sun_driver: failed to enable full duplex: " + "%s: %s@%i", strerror (errno), + __FILE__, __LINE__); return -1; } #endif - } - else - { - if (driver->capture_channels > 0) - { - infd = open(indev, O_RDONLY); - if (infd < 0) - { - jack_error("sun_driver: failed to open input " - "device %s: %s: %s@%i", indev, - strerror(errno), __FILE__, __LINE__); + } else { + if (driver->capture_channels > 0) { + infd = open (indev, O_RDONLY); + if (infd < 0) { + jack_error ("sun_driver: failed to open input " + "device %s: %s: %s@%i", indev, + strerror (errno), __FILE__, __LINE__); return -1; } } - if (driver->playback_channels > 0) - { - outfd = open(outdev, O_WRONLY); - if (outfd < 0) - { - jack_error("sun_driver: failed to open output " - "device %s: %s: %s@%i", outdev, - strerror(errno), __FILE__, __LINE__); + if (driver->playback_channels > 0) { + outfd = open (outdev, O_WRONLY); + if (outfd < 0) { + jack_error ("sun_driver: failed to open output " + "device %s: %s: %s@%i", outdev, + strerror (errno), __FILE__, __LINE__); return -1; } } } - if (infd == -1 && outfd == -1) - { - jack_error("sun_driver: no device was opened: %s@%i", - __FILE__, __LINE__); + if (infd == -1 && outfd == -1) { + jack_error ("sun_driver: no device was opened: %s@%i", + __FILE__, __LINE__); return -1; } driver->infd = infd; driver->outfd = outfd; - - AUDIO_INITINFO(&audio_if_in); - AUDIO_INITINFO(&audio_if_out); - if (infd >= 0) - { + AUDIO_INITINFO (&audio_if_in); + AUDIO_INITINFO (&audio_if_out); + + if (infd >= 0) { audio_if_in.record.encoding = driver->format; audio_if_in.record.precision = driver->bits; audio_if_in.record.channels = driver->capture_channels; audio_if_in.record.sample_rate = driver->sample_rate; audio_if_in.record.pause = 1; } - if (outfd >= 0) - { + if (outfd >= 0) { audio_if_out.play.encoding = driver->format; audio_if_out.play.precision = driver->bits; audio_if_out.play.channels = driver->playback_channels; @@ -856,22 +789,27 @@ sun_driver_set_parameters (sun_driver_t *driver) #if defined(__OpenBSD__) || defined(__NetBSD__) #if defined(__OpenBSD__) - if (driver->infd >= 0) + if (driver->infd >= 0) { audio_if_in.record.block_size = driver->capture_channels * - driver->period_size * driver->sample_bytes; - if (driver->outfd >= 0) + driver->period_size * driver->sample_bytes; + } + if (driver->outfd >= 0) { audio_if_out.play.block_size = driver->playback_channels * - driver->period_size * driver->sample_bytes; + driver->period_size * driver->sample_bytes; + } #else - if (driver->infd >= 0) + if (driver->infd >= 0) { audio_if_in.blocksize = driver->capture_channels * - driver->period_size * driver->sample_bytes; - if (driver->outfd >= 0) + driver->period_size * driver->sample_bytes; + } + if (driver->outfd >= 0) { audio_if_out.blocksize = driver->playback_channels * - driver->period_size * driver->sample_bytes; + driver->period_size * driver->sample_bytes; + } #endif - if (infd == outfd) + if (infd == outfd) { audio_if_in.play = audio_if_out.play; + } /* this only affects playback. the capture buffer is * always the max (64k on OpenBSD). @@ -882,177 +820,155 @@ sun_driver_set_parameters (sun_driver_t *driver) * playback. that means, if we are N frames late, the next * N frames written will be discarded. this keeps playback * time from expanding with each underrun. - */ - if (infd == outfd) - { + */ + if (infd == outfd) { audio_if_in.mode = AUMODE_PLAY | AUMODE_RECORD; - } - else - { - if (infd >= 0) + } else { + if (infd >= 0) { audio_if_in.mode = AUMODE_RECORD; + } - if (outfd >= 0) + if (outfd >= 0) { audio_if_out.mode = AUMODE_PLAY; + } } #endif // OpenBSD || NetBSD - if (infd >= 0) - { - if (ioctl(infd, AUDIO_SETINFO, &audio_if_in) < 0) - { - jack_error("sun_driver: failed to set parameters for " - "%s: %s: %s@%i", indev, strerror(errno), - __FILE__, __LINE__); + if (infd >= 0) { + if (ioctl (infd, AUDIO_SETINFO, &audio_if_in) < 0) { + jack_error ("sun_driver: failed to set parameters for " + "%s: %s: %s@%i", indev, strerror (errno), + __FILE__, __LINE__); return -1; } } - if (outfd >= 0 && outfd != infd) - { - if (ioctl(outfd, AUDIO_SETINFO, &audio_if_out) < 0) - { - jack_error("sun_driver: failed to set parameters for " - "%s: %s: %s@%i", outdev, strerror(errno), - __FILE__, __LINE__); + if (outfd >= 0 && outfd != infd) { + if (ioctl (outfd, AUDIO_SETINFO, &audio_if_out) < 0) { + jack_error ("sun_driver: failed to set parameters for " + "%s: %s: %s@%i", outdev, strerror (errno), + __FILE__, __LINE__); return -1; } } - if (infd >= 0) - { - if (ioctl(infd, AUDIO_GETINFO, &audio_if_in) < 0) - { - jack_error("sun_driver: AUDIO_GETINFO failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (infd >= 0) { + if (ioctl (infd, AUDIO_GETINFO, &audio_if_in) < 0) { + jack_error ("sun_driver: AUDIO_GETINFO failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } - if (!enc_equal(audio_if_in.record.encoding, driver->format) || + if (!enc_equal (audio_if_in.record.encoding, driver->format) || audio_if_in.record.precision != driver->bits || audio_if_in.record.channels != driver->capture_channels || - audio_if_in.record.sample_rate != driver->sample_rate) - { - jack_error("sun_driver: setting capture parameters " - "failed: %s@%i", __FILE__, __LINE__); + audio_if_in.record.sample_rate != driver->sample_rate) { + jack_error ("sun_driver: setting capture parameters " + "failed: %s@%i", __FILE__, __LINE__); return -1; } #if defined(__OpenBSD__) cap_period = audio_if_in.record.block_size / - driver->capture_channels / driver->sample_bytes; + driver->capture_channels / driver->sample_bytes; #elif defined(__NetBSD__) cap_period = audio_if_in.blocksize / - driver->capture_channels / driver->sample_bytes; + driver->capture_channels / driver->sample_bytes; #else /* how is this done on Solaris? */ cap_period = driver->period_size; #endif } - if (outfd >= 0) - { - if (outfd == infd) - { + if (outfd >= 0) { + if (outfd == infd) { audio_if_out.play = audio_if_in.play; - } - else - { - if (ioctl(outfd, AUDIO_GETINFO, &audio_if_out) < 0) - { - jack_error("sun_driver: AUDIO_GETINFO failed: " - "%s: %s@%i", strerror(errno), - __FILE__, __LINE__); + } else { + if (ioctl (outfd, AUDIO_GETINFO, &audio_if_out) < 0) { + jack_error ("sun_driver: AUDIO_GETINFO failed: " + "%s: %s@%i", strerror (errno), + __FILE__, __LINE__); return -1; } } - if (!enc_equal(audio_if_out.play.encoding, driver->format) || + if (!enc_equal (audio_if_out.play.encoding, driver->format) || audio_if_out.play.precision != driver->bits || audio_if_out.play.channels != driver->playback_channels || - audio_if_out.play.sample_rate != driver->sample_rate) - { - jack_error("sun_driver: playback settings failed: " - "%s@%i", __FILE__, __LINE__); + audio_if_out.play.sample_rate != driver->sample_rate) { + jack_error ("sun_driver: playback settings failed: " + "%s@%i", __FILE__, __LINE__); return -1; } #if defined(__OpenBSD__) play_period = audio_if_out.play.block_size / - driver->playback_channels / driver->sample_bytes; + driver->playback_channels / driver->sample_bytes; #elif defined(__NetBSD__) play_period = audio_if_out.blocksize / - driver->playback_channels / driver->sample_bytes; + driver->playback_channels / driver->sample_bytes; #else /* how is this done on Solaris? */ play_period = driver->period_size; #endif } - if (infd >= 0 && outfd >= 0 && play_period != cap_period) - { - jack_error("sun_driver: play and capture periods differ: " - "%s@%i", __FILE__, __LINE__); + if (infd >= 0 && outfd >= 0 && play_period != cap_period) { + jack_error ("sun_driver: play and capture periods differ: " + "%s@%i", __FILE__, __LINE__); return -1; } - if (infd >= 0) + if (infd >= 0) { period_size = cap_period; - else if (outfd >= 0) + } else if (outfd >= 0) { period_size = play_period; + } - if (period_size != 0 && period_size != driver->period_size && - !driver->ignorehwbuf) - { - printf("sun_driver: period size update: %u\n", period_size); + if (period_size != 0 && period_size != driver->period_size && + !driver->ignorehwbuf) { + printf ("sun_driver: period size update: %u\n", period_size); set_period_size (driver, period_size); - if (driver->engine) - if (driver->engine->set_buffer_size(driver->engine, - driver->period_size)) { + if (driver->engine) { + if (driver->engine->set_buffer_size (driver->engine, + driver->period_size)) { jack_error ("sun_driver: cannot set engine buffer size to %d (check MIDI)", driver->period_size); return -1; } + } } - if (driver->infd >= 0 && driver->capture_channels > 0) - { - driver->indevbufsize = driver->period_size * - driver->capture_channels * driver->sample_bytes; - driver->indevbuf = malloc(driver->indevbufsize); - if (driver->indevbuf == NULL) - { - jack_error( "sun_driver: malloc() failed: %s@%i", - __FILE__, __LINE__); + if (driver->infd >= 0 && driver->capture_channels > 0) { + driver->indevbufsize = driver->period_size * + driver->capture_channels * driver->sample_bytes; + driver->indevbuf = malloc (driver->indevbufsize); + if (driver->indevbuf == NULL) { + jack_error ( "sun_driver: malloc() failed: %s@%i", + __FILE__, __LINE__); return -1; } - bzero(driver->indevbuf, driver->indevbufsize); - } - else - { + bzero (driver->indevbuf, driver->indevbufsize); + } else { driver->indevbufsize = 0; driver->indevbuf = NULL; } - if (driver->outfd >= 0 && driver->playback_channels > 0) - { - driver->outdevbufsize = driver->period_size * - driver->playback_channels * driver->sample_bytes; - driver->outdevbuf = malloc(driver->outdevbufsize); - if (driver->outdevbuf == NULL) - { - jack_error("sun_driver: malloc() failed: %s@%i", - __FILE__, __LINE__); + if (driver->outfd >= 0 && driver->playback_channels > 0) { + driver->outdevbufsize = driver->period_size * + driver->playback_channels * driver->sample_bytes; + driver->outdevbuf = malloc (driver->outdevbufsize); + if (driver->outdevbuf == NULL) { + jack_error ("sun_driver: malloc() failed: %s@%i", + __FILE__, __LINE__); return -1; } - bzero(driver->outdevbuf, driver->outdevbufsize); - } - else - { + bzero (driver->outdevbuf, driver->outdevbufsize); + } else { driver->outdevbufsize = 0; driver->outdevbuf = NULL; } - printf("sun_driver: indevbuf %zd B, outdevbuf %zd B\n", + printf ("sun_driver: indevbuf %zd B, outdevbuf %zd B\n", driver->indevbufsize, driver->outdevbufsize); return 0; @@ -1064,28 +980,25 @@ sun_driver_stop (sun_driver_t *driver) { audio_info_t audio_if; - if (driver->infd >= 0) - { - AUDIO_INITINFO(&audio_if); + if (driver->infd >= 0) { + AUDIO_INITINFO (&audio_if); audio_if.record.pause = 1; - if (driver->outfd == driver->infd) + if (driver->outfd == driver->infd) { audio_if.play.pause = 1; - if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: capture pause failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + } + if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: capture pause failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } - if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) - { - AUDIO_INITINFO(&audio_if); + if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) { + AUDIO_INITINFO (&audio_if); audio_if.play.pause = 1; - if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0) - { - jack_error("sun_driver: playback pause failed: %s: " - "%s@%i", strerror(errno), __FILE__, __LINE__); + if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) { + jack_error ("sun_driver: playback pause failed: %s: " + "%s@%i", strerror (errno), __FILE__, __LINE__); return -1; } } @@ -1104,49 +1017,45 @@ sun_driver_read (sun_driver_t *driver, jack_nframes_t nframes) JSList *node; jack_port_t *port; - if (driver->engine->freewheeling || driver->infd < 0) + if (driver->engine->freewheeling || driver->infd < 0) { return 0; + } - if (nframes > driver->period_size) - { - jack_error("sun_driver: read failed: nframes > period_size: " - "(%u/%u): %s@%i", nframes, driver->period_size, - __FILE__, __LINE__); + if (nframes > driver->period_size) { + jack_error ("sun_driver: read failed: nframes > period_size: " + "(%u/%u): %s@%i", nframes, driver->period_size, + __FILE__, __LINE__); return -1; } node = driver->capture_ports; channel = 0; - while (node != NULL) - { - port = (jack_port_t *) node->data; - - if (jack_port_connected(port)) - { - portbuf = jack_port_get_buffer(port, nframes); - copy_and_convert_in(portbuf, driver->indevbuf, - nframes, channel, - driver->capture_channels, - driver->bits); + while (node != NULL) { + port = (jack_port_t*)node->data; + + if (jack_port_connected (port)) { + portbuf = jack_port_get_buffer (port, nframes); + copy_and_convert_in (portbuf, driver->indevbuf, + nframes, channel, + driver->capture_channels, + driver->bits); } - node = jack_slist_next(node); + node = jack_slist_next (node); channel++; } nbytes = nframes * driver->capture_channels * driver->sample_bytes; io_res = 0; - while (nbytes) - { - io_res = read(driver->infd, driver->indevbuf, nbytes); - if (io_res < 0) - { - jack_error("sun_driver: read() failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + while (nbytes) { + io_res = read (driver->infd, driver->indevbuf, nbytes); + if (io_res < 0) { + jack_error ("sun_driver: read() failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); break; - } - else + } else { nbytes -= io_res; + } } return 0; @@ -1164,51 +1073,47 @@ sun_driver_write (sun_driver_t *driver, jack_nframes_t nframes) jack_port_t *port; - if (driver->engine->freewheeling || driver->outfd < 0) + if (driver->engine->freewheeling || driver->outfd < 0) { return 0; + } - if (nframes > driver->period_size) - { - jack_error("sun_driver: write failed: nframes > period_size " - "(%u/%u): %s@%i", nframes, driver->period_size, - __FILE__, __LINE__); + if (nframes > driver->period_size) { + jack_error ("sun_driver: write failed: nframes > period_size " + "(%u/%u): %s@%i", nframes, driver->period_size, + __FILE__, __LINE__); return -1; } - bzero(driver->outdevbuf, driver->outdevbufsize); + bzero (driver->outdevbuf, driver->outdevbufsize); node = driver->playback_ports; channel = 0; - while (node != NULL) - { - port = (jack_port_t *) node->data; - - if (jack_port_connected(port)) - { - portbuf = jack_port_get_buffer(port, nframes); - copy_and_convert_out(driver->outdevbuf, portbuf, - nframes, channel, - driver->playback_channels, - driver->bits); + while (node != NULL) { + port = (jack_port_t*)node->data; + + if (jack_port_connected (port)) { + portbuf = jack_port_get_buffer (port, nframes); + copy_and_convert_out (driver->outdevbuf, portbuf, + nframes, channel, + driver->playback_channels, + driver->bits); } - node = jack_slist_next(node); + node = jack_slist_next (node); channel++; } nbytes = nframes * driver->playback_channels * driver->sample_bytes; io_res = 0; - while (nbytes) - { - io_res = write(driver->outfd, driver->outdevbuf, nbytes); - if (io_res < 0) - { - jack_error("sun_driver: write() failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + while (nbytes) { + io_res = write (driver->outfd, driver->outdevbuf, nbytes); + if (io_res < 0) { + jack_error ("sun_driver: write() failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); break; - } - else + } else { nbytes -= io_res; + } } return 0; @@ -1218,21 +1123,22 @@ sun_driver_write (sun_driver_t *driver, jack_nframes_t nframes) static int sun_driver_null_cycle (sun_driver_t *driver, jack_nframes_t nframes) { - if (nframes > driver->period_size) - { - jack_error("sun_driver: null cycle failed: " - "nframes > period_size (%u/%u): %s@%i", nframes, - driver->period_size, __FILE__, __LINE__); + if (nframes > driver->period_size) { + jack_error ("sun_driver: null cycle failed: " + "nframes > period_size (%u/%u): %s@%i", nframes, + driver->period_size, __FILE__, __LINE__); return -1; } - printf("sun_driver: running null cycle\n"); + printf ("sun_driver: running null cycle\n"); - if (driver->outfd >= 0) + if (driver->outfd >= 0) { sun_driver_write_silence (driver, nframes); + } - if (driver->infd >= 0) + if (driver->infd >= 0) { sun_driver_read_silence (driver, nframes); + } return 0; } @@ -1241,89 +1147,88 @@ sun_driver_null_cycle (sun_driver_t *driver, jack_nframes_t nframes) static int sun_driver_bufsize (sun_driver_t *driver, jack_nframes_t nframes) { - return sun_driver_set_parameters(driver); + return sun_driver_set_parameters (driver); } static void sun_driver_delete (sun_driver_t *driver) { - if (driver->outfd >= 0 && driver->outfd != driver->infd) - { - close(driver->outfd); + if (driver->outfd >= 0 && driver->outfd != driver->infd) { + close (driver->outfd); driver->outfd = -1; } - if (driver->infd >= 0) - { - close(driver->infd); + if (driver->infd >= 0) { + close (driver->infd); driver->infd = -1; } - if (driver->indevbuf != NULL) - { - free(driver->indevbuf); + if (driver->indevbuf != NULL) { + free (driver->indevbuf); driver->indevbuf = NULL; } - if (driver->outdevbuf != NULL) - { - free(driver->outdevbuf); + if (driver->outdevbuf != NULL) { + free (driver->outdevbuf); driver->outdevbuf = NULL; } - if (driver->indev != NULL) - free(driver->indev); + if (driver->indev != NULL) { + free (driver->indev); + } - if (driver->outdev != NULL) - free(driver->outdev); + if (driver->outdev != NULL) { + free (driver->outdev); + } - jack_driver_nt_finish((jack_driver_nt_t *) driver); + jack_driver_nt_finish ((jack_driver_nt_t*)driver); - free(driver); + free (driver); } void driver_finish (jack_driver_t *driver) { - sun_driver_delete ((sun_driver_t *)driver); + sun_driver_delete ((sun_driver_t*)driver); } static jack_driver_t * sun_driver_new (char *indev, char *outdev, jack_client_t *client, - jack_nframes_t sample_rate, jack_nframes_t period_size, - jack_nframes_t nperiods, int bits, - int capture_channels, int playback_channels, - jack_nframes_t in_latency, jack_nframes_t out_latency, - int ignorehwbuf) + jack_nframes_t sample_rate, jack_nframes_t period_size, + jack_nframes_t nperiods, int bits, + int capture_channels, int playback_channels, + jack_nframes_t in_latency, jack_nframes_t out_latency, + int ignorehwbuf) { sun_driver_t *driver; - driver = (sun_driver_t *) malloc(sizeof(sun_driver_t)); - if (driver == NULL) - { - jack_error("sun_driver: malloc() failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + driver = (sun_driver_t*)malloc (sizeof(sun_driver_t)); + if (driver == NULL) { + jack_error ("sun_driver: malloc() failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); return NULL; } driver->engine = NULL; - jack_driver_nt_init((jack_driver_nt_t *) driver); - - driver->nt_attach = (JackDriverNTAttachFunction) sun_driver_attach; - driver->nt_detach = (JackDriverNTDetachFunction) sun_driver_detach; - driver->read = (JackDriverReadFunction) sun_driver_read; - driver->write = (JackDriverWriteFunction) sun_driver_write; - driver->null_cycle = (JackDriverNullCycleFunction) - sun_driver_null_cycle; - driver->nt_bufsize = (JackDriverNTBufSizeFunction) sun_driver_bufsize; - driver->nt_start = (JackDriverNTStartFunction) sun_driver_start; - driver->nt_stop = (JackDriverNTStopFunction) sun_driver_stop; - driver->nt_run_cycle = (JackDriverNTRunCycleFunction) sun_driver_run_cycle; - - if (indev != NULL) - driver->indev = strdup(indev); - if (outdev != NULL) - driver->outdev = strdup(outdev); + jack_driver_nt_init ((jack_driver_nt_t*)driver); + + driver->nt_attach = (JackDriverNTAttachFunction)sun_driver_attach; + driver->nt_detach = (JackDriverNTDetachFunction)sun_driver_detach; + driver->read = (JackDriverReadFunction)sun_driver_read; + driver->write = (JackDriverWriteFunction)sun_driver_write; + driver->null_cycle = (JackDriverNullCycleFunction) + sun_driver_null_cycle; + driver->nt_bufsize = (JackDriverNTBufSizeFunction)sun_driver_bufsize; + driver->nt_start = (JackDriverNTStartFunction)sun_driver_start; + driver->nt_stop = (JackDriverNTStopFunction)sun_driver_stop; + driver->nt_run_cycle = (JackDriverNTRunCycleFunction)sun_driver_run_cycle; + + if (indev != NULL) { + driver->indev = strdup (indev); + } + if (outdev != NULL) { + driver->outdev = strdup (outdev); + } driver->ignorehwbuf = ignorehwbuf; @@ -1336,12 +1241,14 @@ sun_driver_new (char *indev, char *outdev, jack_client_t *client, driver->sys_in_latency = in_latency; driver->sys_out_latency = out_latency; - set_period_size(driver, period_size); - - if (driver->indev == NULL) - driver->indev = strdup(SUN_DRIVER_DEF_DEV); - if (driver->outdev == NULL) - driver->outdev = strdup(SUN_DRIVER_DEF_DEV); + set_period_size (driver, period_size); + + if (driver->indev == NULL) { + driver->indev = strdup (SUN_DRIVER_DEF_DEV); + } + if (driver->outdev == NULL) { + driver->outdev = strdup (SUN_DRIVER_DEF_DEV); + } driver->infd = -1; driver->outfd = -1; #if defined(AUDIO_ENCODING_SLINEAR) @@ -1357,15 +1264,14 @@ sun_driver_new (char *indev, char *outdev, jack_client_t *client, driver->iodelay = 0.0F; driver->poll_last = driver->poll_next = 0; - if (sun_driver_set_parameters (driver) < 0) - { - free(driver); + if (sun_driver_set_parameters (driver) < 0) { + free (driver); return NULL; } driver->client = client; - return (jack_driver_t *) driver; + return (jack_driver_t*)driver; } @@ -1381,24 +1287,22 @@ driver_get_descriptor () jack_driver_desc_t *desc; jack_driver_param_desc_t *params; - desc = (jack_driver_desc_t *) calloc(1, sizeof(jack_driver_desc_t)); - if (desc == NULL) - { - jack_error("sun_driver: calloc() failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + desc = (jack_driver_desc_t*)calloc (1, sizeof(jack_driver_desc_t)); + if (desc == NULL) { + jack_error ("sun_driver: calloc() failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); return NULL; } - strcpy(desc->name, driver_client_name); + strcpy (desc->name, driver_client_name); desc->nparams = SUN_DRIVER_N_PARAMS; - params = calloc(desc->nparams, sizeof(jack_driver_param_desc_t)); - if (params == NULL) - { - jack_error("sun_driver: calloc() failed: %s: %s@%i", - strerror(errno), __FILE__, __LINE__); + params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t)); + if (params == NULL) { + jack_error ("sun_driver: calloc() failed: %s: %s@%i", + strerror (errno), __FILE__, __LINE__); return NULL; } - memcpy(params, sun_params, + memcpy (params, sun_params, desc->nparams * sizeof(jack_driver_param_desc_t)); desc->params = params; @@ -1423,54 +1327,52 @@ driver_initialize (jack_client_t *client, JSList * params) char *outdev; int ignorehwbuf = 0; - indev = strdup(SUN_DRIVER_DEF_DEV); - outdev = strdup(SUN_DRIVER_DEF_DEV); + indev = strdup (SUN_DRIVER_DEF_DEV); + outdev = strdup (SUN_DRIVER_DEF_DEV); pnode = params; - while (pnode != NULL) - { - param = (const jack_driver_param_t *) pnode->data; - - switch (param->character) - { - case 'r': - sample_rate = param->value.ui; - break; - case 'p': - period_size = param->value.ui; - break; - case 'n': - nperiods = param->value.ui; - break; - case 'w': - bits = param->value.i; - break; - case 'i': - capture_channels = param->value.ui; - break; - case 'o': - playback_channels = param->value.ui; - break; - case 'C': - indev = strdup(param->value.str); - break; - case 'P': - outdev = strdup(param->value.str); - break; - case 'b': - ignorehwbuf = 1; - break; - case 'I': - in_latency = param->value.ui; - break; - case 'O': - out_latency = param->value.ui; - break; + while (pnode != NULL) { + param = (const jack_driver_param_t*)pnode->data; + + switch (param->character) { + case 'r': + sample_rate = param->value.ui; + break; + case 'p': + period_size = param->value.ui; + break; + case 'n': + nperiods = param->value.ui; + break; + case 'w': + bits = param->value.i; + break; + case 'i': + capture_channels = param->value.ui; + break; + case 'o': + playback_channels = param->value.ui; + break; + case 'C': + indev = strdup (param->value.str); + break; + case 'P': + outdev = strdup (param->value.str); + break; + case 'b': + ignorehwbuf = 1; + break; + case 'I': + in_latency = param->value.ui; + break; + case 'O': + out_latency = param->value.ui; + break; } - pnode = jack_slist_next(pnode); + pnode = jack_slist_next (pnode); } - + return sun_driver_new (indev, outdev, client, sample_rate, period_size, - nperiods, bits, capture_channels, playback_channels, in_latency, - out_latency, ignorehwbuf); + nperiods, bits, capture_channels, playback_channels, in_latency, + out_latency, ignorehwbuf); } |