Re: Audio Glitch in Matlab (Etienne Gaudrain )


Subject: Re: Audio Glitch in Matlab
From:    Etienne Gaudrain  <egaudrain.cam@xxxxxxxx>
Date:    Mon, 17 Oct 2011 17:21:23 +0100
List-Archive:<http://lists.mcgill.ca/scripts/wa.exe?LIST=AUDITORY>

--0015175d03cc7857e604af80ffa9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, We also had some clicking and truncating issues when using directly the default (WDM) Windows audio drivers. Like Brian we solved the problem by using ASIO drivers. You can tap directl= y into the ASIO drivers from Matlab using the Playrec ( http://www.playrec.co.uk/) toolbox, based on Portaudio (the audio library behind Audacity). And most to our astonishment we discovered that we only needed to initializ= e the card using Playrec, and then everything was fine even when using the standard Matlab functions (sound, audioplay...). So basically, we do: playrec('init', 44100, 1, -1); Then we can call sound(x, fs)... etc... with no clicking and no truncating... Maybe the ASIO driver sets the card in a state that is more sensible than the default state set by the WDM, like putting sensible buffer lengths... something like that. The trick works on Windows XP with even older versions of Matlab, and with E-MU and Asus sound cards. Haven't tried on Windows 7, and this is probably different as the sound system is different. -Etienne --=20 Etienne Gaudrain, PhD MRC Cognition and Brain Sciences Unit 15 Chaucer Road Cambridge, CB2 7EF United-Kingdom +44 1223 355 294, ext. 645 On 17 October 2011 15:35, Brian FG Katz <brian.katz@xxxxxxxx> wrote: > This bug is quite present in Windows. The solution is to not use the > default system driver, but an ASIO supported soundcard. This is also > recommended for any sync play/rec situations, as the default Windows driv= er > does not assure good or repeatable synchronization. **** > > ** ** > > -Brian FG Katz**** > > --**** > > Brian FG Katz, Ph.D**** > > Audio & Acoustique**** > > LIMSI-CNRS**** > > BP 133**** > > F91403 Orsay**** > > France**** > > tel. (+33) 01 69 85 81 55**** > > fax. (+33) 01.69.85.80.88**** > > e-mail Brian.Katz@xxxxxxxx <mailto:Brian.Katz@xxxxxxxx<Brian.Katz@xxxxxxxx= r> > >**** > > web_theme: http://www.limsi.fr/Scientifique/aa/thmsonesp/**** > > web_group: http://www.limsi.fr/Scientifique/aa/**** > > ** ** > > ** ** > > ** ** > > *De :* AUDITORY - Research in Auditory Perception [mailto: > AUDITORY@xxxxxxxx *De la part de* Patrick Zurek > *Envoy=C3=A9 :* lundi 17 octobre 2011 09:57 > *=C3=80 :* AUDITORY@xxxxxxxx > *Objet :* [AUDITORY] Audio Glitch in Matlab**** > > ** ** > > I'm writing to notify list readers of a problem playing audio using Matla= b. > > > 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 m= sec > 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 truncat= ion > of a 10-msec signal (with a sample rate of 44.1kHz). > > I've brought this problem to the attention of The Mathworks. They confirm= ed > 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 necessaril= y > 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 =3D 44100; > f =3D 1000; > T =3D 0.1; > nPad =3D 2000; > > nS =3D round(fs*T); > > y =3D sin(2.*pi*f/fs*(1:nS)'); > w =3D .5*(1 - cos(2*pi*(1:nS)'/(nS+1))); > y =3D w.*y; > yPad =3D [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**** > > --0015175d03cc7857e604af80ffa9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <span class=3D"Apple-style-span" style=3D"color: rgb(80, 0, 80); font-famil= y: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255)= ; ">Hi,=C2=A0<br><br>We also had some clicking and truncating issues when u= sing directly the default (WDM) Windows audio drivers.=C2=A0<br> Like Brian we solved the problem by using ASIO drivers. You can tap directl= y into the ASIO drivers from Matlab using the Playrec (<a href=3D"http://ww= w.playrec.co.uk/" target=3D"_blank" style=3D"color: rgb(0, 0, 204); ">http:= //www.playrec.co.uk/</a>) toolbox, based on Portaudio (the audio library be= hind Audacity).=C2=A0<br> <div class=3D"im" style=3D"color: rgb(80, 0, 80); "><br>And most to our ast= onishment we discovered that we only needed to initialize the card using Pl= ayrec, and then everything was fine even when using the standard Matlab fun= ctions (sound, audioplay...).=C2=A0<br> <br>So basically, we do:=C2=A0<br>playrec(&#39;init&#39;, 44100, 1, -1);=C2= =A0<br><br>Then we can call sound(x, fs)... etc... with no clicking and no = truncating...=C2=A0<br><br>Maybe the ASIO driver sets the card in a state t= hat is more sensible than the default state set by the WDM, like putting se= nsible buffer lengths... something like that.=C2=A0<br> <br>The trick works on Windows XP with even older versions of Matlab, and w= ith E-MU and Asus sound cards.=C2=A0<br>Haven&#39;t tried on Windows 7, and= this is probably different as the sound system is different.=C2=A0<br><br>= -Etienne=C2=A0<br> <br><div><span>--=C2=A0<br></span>Etienne Gaudrain, PhD<br>MRC Cognition an= d Brain Sciences Unit<br>15 Chaucer Road<br>Cambridge, CB2 7EF<br>United-Ki= ngdom<br><a href=3D"tel:%2B44%201223%20355%20294%2C%20ext.%20645" value=3D"= +441223355294" target=3D"_blank" style=3D"color: rgb(0, 0, 204); ">+44 1223= 355 294, ext. 645</a>=C2=A0<br> </div><div><br></div></div></span><br><div class=3D"gmail_quote">On 17 Octo= ber 2011 15:35, Brian FG Katz <span dir=3D"ltr">&lt;<a href=3D"mailto:brian= .katz@xxxxxxxx">brian.katz@xxxxxxxx</a>&gt;</span> wrote:<br><blockquote cl= ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p= adding-left:1ex;"> <div bgcolor=3D"white" lang=3D"EN-US" link=3D"blue" vlink=3D"purple"><div><= p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;color:#1F497D">This b= ug is quite present in Windows. The solution is to not use the default syst= em driver, but an ASIO supported soundcard. This is also recommended for an= y sync play/rec situations, as the default Windows driver does not assure g= ood or repeatable synchronization. <u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;color:#1F497D"><u></= u>=C2=A0<u></u></span></p><p class=3D"MsoNormal"><span style=3D"font-size:1= 1.0pt;color:#1F497D">-Brian FG Katz<u></u><u></u></span></p><div><p class= =3D"MsoNormal"> <span lang=3D"FR" style=3D"font-size:10.0pt;color:#1F497D">--<u></u><u></u>= </span></p><p class=3D"MsoNormal"><span lang=3D"FR" style=3D"font-size:10.0= pt;color:#1F497D">Brian FG Katz, Ph.D<u></u><u></u></span></p><p class=3D"M= soNormal"> <span lang=3D"FR" style=3D"font-size:10.0pt;color:#1F497D">Audio &amp; Acou= stique<u></u><u></u></span></p><p class=3D"MsoNormal"><span style=3D"font-s= ize:10.0pt;color:#1F497D">LIMSI-CNRS<u></u><u></u></span></p><p class=3D"Ms= oNormal"> <span style=3D"font-size:10.0pt;color:#1F497D">BP 133<u></u><u></u></span><= /p><p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;color:#1F497D">F9= 1403 Orsay<u></u><u></u></span></p><p class=3D"MsoNormal"><span style=3D"fo= nt-size:10.0pt;color:#1F497D">France<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;color:#1F497D">tel. = <a href=3D"tel:%28%2B33%29%2001%2069%2085%2081%2055" value=3D"+33169858155"= target=3D"_blank">(+33) 01 69 85 81 55</a><u></u><u></u></span></p><p clas= s=3D"MsoNormal"> <span style=3D"font-size:10.0pt;color:#1F497D">fax. <a href=3D"tel:%28%2B33= %29%2001.69.85.80.88" value=3D"+33169858088" target=3D"_blank">(+33) 01.69.= 85.80.88</a><u></u><u></u></span></p><p class=3D"MsoNormal"><span style=3D"= font-size:10.0pt;color:#1F497D">e-mail </span><span lang=3D"FR" style=3D"fo= nt-size:10.0pt;color:#1F497D"><a href=3D"mailto:Brian.Katz@xxxxxxxx" target= =3D"_blank"><span lang=3D"EN-US" style=3D"color:blue">Brian.Katz@xxxxxxxx</= span></a></span><span style=3D"font-size:10.0pt;color:#1F497D"> &lt;</span>= <span lang=3D"FR" style=3D"font-size:10.0pt;color:#1F497D"><a href=3D"mailt= o:Brian.Katz@xxxxxxxx" target=3D"_blank"><span lang=3D"EN-US" style=3D"colo= r:blue">mailto:Brian.Katz@xxxxxxxx</span></a></span><span style=3D"font-siz= e:10.0pt;color:#1F497D">&gt;<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;color:#1F497D">web_t= heme: </span><span lang=3D"FR" style=3D"font-size:10.0pt;color:#1F497D"><a = href=3D"http://www.limsi.fr/Scientifique/aa/thmsonesp/" target=3D"_blank"><= span lang=3D"EN-US" style=3D"color:blue">http://www.limsi.fr/Scientifique/a= a/thmsonesp/</span></a></span><span style=3D"font-size:10.0pt;color:#1F497D= "><u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;color:#1F497D">web_g= roup: </span><span lang=3D"FR" style=3D"font-size:10.0pt;color:#1F497D"><a = href=3D"http://www.limsi.fr/Scientifique/aa/" target=3D"_blank"><span lang= =3D"EN-US" style=3D"color:blue">http://www.limsi.fr/Scientifique/aa/</span>= </a></span><span style=3D"font-size:10.0pt;color:#1F497D"><u></u><u></u></s= pan></p> <p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;color:#1F497D"><u></= u>=C2=A0<u></u></span></p><p class=3D"MsoNormal"><span style=3D"font-size:1= 0.0pt;color:#1F497D"><u></u>=C2=A0<u></u></span></p></div><p class=3D"MsoNo= rmal"><span style=3D"font-size:11.0pt;color:#1F497D"><u></u>=C2=A0<u></u></= span></p> <div><div style=3D"border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt= 0cm 0cm 0cm"><p class=3D"MsoNormal"><b><span lang=3D"FR" style=3D"font-siz= e:10.0pt;color:windowtext">De=C2=A0:</span></b><span lang=3D"FR" style=3D"f= ont-size:10.0pt;color:windowtext"> AUDITORY - Research in Auditory Percepti= on [mailto:<a href=3D"mailto:AUDITORY@xxxxxxxx" target=3D"_blank">AU= DITORY@xxxxxxxx</a>] <b>De la part de</b> Patrick Zurek<br> <b>Envoy=C3=A9=C2=A0:</b> lundi 17 octobre 2011 09:57<br><b>=C3=80=C2=A0:</= b> <a href=3D"mailto:AUDITORY@xxxxxxxx" target=3D"_blank">AUDITORY@xxxxxxxx= ISTS.MCGILL.CA</a><br><b>Objet=C2=A0:</b> [AUDITORY] Audio Glitch in Matlab= <u></u><u></u></span></p> </div></div><div><div></div><div class=3D"h5"><p class=3D"MsoNormal"><u></u= >=C2=A0<u></u></p><p class=3D"MsoNormal"><span>I&#39;m writing to notify li= st 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 co= mmands for playing audio (wavplay, sound, and the play method of the audiop= layer object).<br> <br>I can&#39;t specify the exact conditions under which the truncation occ= urs. However, with a sample rate of 44.1 kHz, signals shorter than about 50= 0 msec are truncated. I haven&#39;t looked much at other sample rates.<br> <br>A simple work-around for the problem is to pad the end of the signal wi= th a sufficient number of zeros that truncation occurs during the zero segm= ent. I&#39;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&#39;ve brought this problem to the attention of The Mathworks. They c= onfirmed the problem, which they attribute to a bug in their driver. <br><b= r>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&#39;ve confirmed this in very limited tests= . <br> <br>The following is a piece of code that you can use to observe the trunca= tion. 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 t= he first. If not, you can see it on an oscilloscope.<br> <br>%%%%%%%%%%%%%%%%%%%%<br>fs =3D 44100;<br>f =3D 1000; <br>T =3D 0.1;<br>= nPad =3D 2000;<br><br>nS =3D round(fs*T);<br><br>y =3D sin(2.*pi*f/fs*(1:nS= )&#39;);<br>w =3D .5*(1 - cos(2*pi*(1:nS)&#39;/(nS+1)));<br>y =3D w.*y;<br>= yPad =3D [y; zeros(nPad,1)];<br> <br>wavplay(yPad, fs, &#39;sync&#39;)<br>pause(0.5)<br>wavplay(y, fs, &#39;= sync&#39;)<br>%%%%%%%%%%%%%%%%%%%%%</span><br><br><u></u><u></u></p><pre>--= <u></u><u></u></pre><pre>Patrick M. Zurek<u></u><u></u></pre><pre>Presiden= t <u></u><u></u></pre> <pre><u></u>=C2=A0<u></u></pre><pre>Sensimetrics Corporation<u></u><u></u><= /pre><pre>14 Summer St.<u></u><u></u></pre><pre>Suite 403<u></u><u></u></pr= e><pre>Malden, MA 02148<u></u><u></u></pre><pre>Tel: <a href=3D"tel:781-399= -0858%20x237" value=3D"+17813990858" target=3D"_blank">781-399-0858 x237</a= ><u></u><u></u></pre> <pre>Fax: <a href=3D"tel:781-399-0853" value=3D"+17813990853" target=3D"_bl= ank">781-399-0853</a><u></u><u></u></pre><pre>email: <a href=3D"mailto:pat@xxxxxxxx= sens.com" target=3D"_blank">pat@xxxxxxxx</a><u></u><u></u></pre><pre>web: <= a href=3D"http://www.sens.com" target=3D"_blank">www.sens.com</a><u></u><u>= </u></pre> </div></div></div></div></blockquote></div><br> --0015175d03cc7857e604af80ffa9--


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