[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Audio Glitch in Matlab


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 directly 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 initialize 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 Gaudrain, PhD
MRC Cognition and Brain Sciences Unit
15 Chaucer Road
Cambridge, CB2 7EF
+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 driver does not assure good or repeatable synchronization.


-Brian FG Katz


Brian FG Katz, Ph.D

Audio & Acoustique


BP 133

F91403 Orsay


tel. (+33) 01 69 85 81 55

fax. (+33)

e-mail Brian.Katz@xxxxxxxx <mailto:Brian.Katz@xxxxxxxx>

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@xxxxxxxxxxxxxxx] De la part de Patrick Zurek
EnvoyÃÂ: lundi 17 octobre 2011 09:57
ÃÂ: AUDITORY@xxxxxxxxxxxxxxx
ObjetÂ: [AUDITORY] Audio Glitch in Matlab


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')
wavplay(y, fs, 'sync')

Patrick M. Zurek
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