Audio Glitch in Matlab (Patrick Zurek )


Subject: Audio Glitch in Matlab
From:    Patrick Zurek  <pat@xxxxxxxx>
Date:    Mon, 17 Oct 2011 09:57:17 -0400
List-Archive:<http://lists.mcgill.ca/scripts/wa.exe?LIST=AUDITORY>

This is a multi-part message in MIME format. --------------030103020706040808060701 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I'm writing to notify list readers of a problem playing audio using Matlab. The problem is that brief signals are truncated, and it happens using any of the common commands for playing audio (wavplay, sound, and the play method of the audioplayer object). I can't specify the exact conditions under which the truncation occurs. However, with a sample rate of 44.1 kHz, signals shorter than about 500 msec are truncated. I haven't looked much at other sample rates. A simple work-around for the problem is to pad the end of the signal with a sufficient number of zeros that truncation occurs during the zero segment. I've found that at least 2000 zeros need to be added to assure no truncation of a 10-msec signal (with a sample rate of 44.1kHz). I've brought this problem to the attention of The Mathworks. They confirmed the problem, which they attribute to a bug in their driver. The Mathworks also informed me that the problem has been solved in their latest release (R2011b) for playing using audioplayer, but not necessarily for the other audio commands. I've confirmed this in very limited tests. The following is a piece of code that you can use to observe the truncation. It creates a 100-msec, 1-kHz sine wave, applies a hanning window, and then plays it first with zero-padding and then without. You should be able to hear the click at the end of the second tone, which is not present on the first. If not, you can see it on an oscilloscope. %%%%%%%%%%%%%%%%%%%% fs = 44100; f = 1000; T = 0.1; nPad = 2000; nS = round(fs*T); y = sin(2.*pi*f/fs*(1:nS)'); w = .5*(1 - cos(2*pi*(1:nS)'/(nS+1))); y = w.*y; yPad = [y; zeros(nPad,1)]; wavplay(yPad, fs, 'sync') pause(0.5) wavplay(y, fs, 'sync') %%%%%%%%%%%%%%%%%%%%% -- Patrick M. Zurek President Sensimetrics Corporation 14 Summer St. Suite 403 Malden, MA 02148 Tel: 781-399-0858 x237 Fax: 781-399-0853 email: pat@xxxxxxxx web: www.sens.com --------------030103020706040808060701 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <font face="Calibri">I'm writing to notify list readers of a problem playing audio using Matlab. <br> <br> The problem is that brief signals are truncated, and it happens using any of the common commands for playing audio (wavplay, sound, and the play method of the audioplayer object).<br> <br> I can't specify the exact conditions under which the truncation occurs. However, with a sample rate of 44.1 kHz, signals shorter than about 500 msec are truncated. I haven't looked much at other sample rates.<br> <br> A simple work-around for the problem is to pad the end of the signal with a sufficient number of zeros that truncation occurs during the zero segment. I've found that at least 2000 zeros need to be added to assure no truncation of a 10-msec signal (with a sample rate of 44.1kHz).<br> <br> I've brought this problem to the attention of The Mathworks. They confirmed the problem, which they attribute to a bug in their driver. <br> <br> The Mathworks also informed me that the problem has been solved in their latest release (R2011b) for playing using audioplayer, but not necessarily for the other audio commands. I've confirmed this in very limited tests. <br> <br> The following is a piece of code that you can use to observe the truncation. It creates a 100-msec, 1-kHz sine wave, applies a hanning window, and then plays it first with zero-padding and then without. You should be able to hear the click at the end of the second tone, which is not present on the first. If not, you can see it on an oscilloscope.<br> <br> %%%%%%%%%%%%%%%%%%%%<br> fs = 44100;<br> f = 1000; <br> T = 0.1;<br> nPad = 2000;<br> <br> nS = round(fs*T);<br> <br> y = sin(2.*pi*f/fs*(1:nS)');<br> w = .5*(1 - cos(2*pi*(1:nS)'/(nS+1)));<br> y = w.*y;<br> yPad = [y; zeros(nPad,1)];<br> <br> wavplay(yPad, fs, 'sync')<br> pause(0.5)<br> wavplay(y, fs, 'sync')<br> %%%%%%%%%%%%%%%%%%%%%</font><br> <pre class="moz-signature" cols="72">-- Patrick M. Zurek President Sensimetrics Corporation 14 Summer St. Suite 403 Malden, MA 02148 Tel: 781-399-0858 x237 Fax: 781-399-0853 email: <a class="moz-txt-link-abbreviated" href="mailto:pat@xxxxxxxx">pat@xxxxxxxx</a> web: <a class="moz-txt-link-abbreviated" href="http://www.sens.com">www.sens.com</a></pre> </body> </html> --------------030103020706040808060701--


This message came from the mail archive
/var/www/postings/2011/
maintained by:
DAn Ellis <dpwe@ee.columbia.edu>
Electrical Engineering Dept., Columbia University