From ec2bb3a329d4fe4bdc9991039bf9cd105c5d9350 Mon Sep 17 00:00:00 2001 From: letz Date: Tue, 30 Nov 2004 09:34:51 +0000 Subject: [PATCH] Clear to avoid playing dirty buffers when the client does not produce output anymore git-svn-id: svn+ssh://jackaudio.org/trunk/jack@809 0c269be4-1314-0410-8aa9-9f06e86f4224 --- drivers/coreaudio/coreaudio_driver.c | 8 +++++++- drivers/portaudio/portaudio_driver.c | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/coreaudio/coreaudio_driver.c b/drivers/coreaudio/coreaudio_driver.c index 3d2ae9f..f0655b2 100755 --- a/drivers/coreaudio/coreaudio_driver.c +++ b/drivers/coreaudio/coreaudio_driver.c @@ -29,6 +29,8 @@ Feb 04, 2004: Johnny Petrantoni: now the driver supports interfaces with multiple interleaved streams (such as the MOTU 828). Nov 05, 2004: S.Letz: correct management of -I option for use with JackPilot. Nov 15, 2004: S.Letz: Set a default value for deviceID. + Nov 30, 2004: S.Letz: In coreaudio_driver_write : clear to avoid playing dirty buffers when the client does not produce output anymore. + TODO: - fix cpu load behavior. @@ -262,7 +264,7 @@ coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes) channel_t chn; jack_port_t *port; JSList *node; - int i; + int i,bytes = nframes*sizeof(float); int b = 0; @@ -277,6 +279,8 @@ coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes) float *out = driver->outcoreaudio[chn]; buf = jack_port_get_buffer(port, nframes); memcpy(out, buf, sizeof(float) * nframes); + /* clear to avoid playing dirty buffers when the client does not produce output anymore */ + memset(buf, 0, bytes); } } else { if (jack_port_connected(port) @@ -296,6 +300,8 @@ coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes) buf = jack_port_get_buffer(port, nframes); for (i = 0; i < nframes; i++) out[channels * i + chn] = buf[i]; + /* clear to avoid playing dirty buffers when the client does not produce output anymore */ + memset(buf, 0, bytes); } } } diff --git a/drivers/portaudio/portaudio_driver.c b/drivers/portaudio/portaudio_driver.c index 6eea685..60660cf 100644 --- a/drivers/portaudio/portaudio_driver.c +++ b/drivers/portaudio/portaudio_driver.c @@ -236,10 +236,10 @@ portaudio_driver_write (portaudio_driver_t *driver, jack_nframes_t nframes) channel_t chn; jack_port_t *port; JSList *node; - int i; + int i,bytes = nframes*sizeof(float); /* Clear in case of nothing is connected */ - memset(driver->outPortAudio, 0, (driver->playback_nchannels * nframes * sizeof(float))); + memset(driver->outPortAudio, 0, driver->playback_nchannels*bytes); for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) { @@ -250,6 +250,8 @@ portaudio_driver_write (portaudio_driver_t *driver, jack_nframes_t nframes) float* out = driver->outPortAudio; buf = jack_port_get_buffer (port, nframes); for (i = 0; i< nframes; i++) out[channels*i+chn] = buf[i]; + /* clear to avoid playing dirty buffers when the client does not produce output anymore */ + memset(buf, 0, bytes); } }