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

Re: Audio Glitch in Matlab



On Mon, Oct 17, 2011 at 09:57, Patrick Zurek <pat@xxxxxxxx> wrote:
> I'm writing to notify list readers of a problem playing audio using Matlab.

I don't know if the bug you're referring to is Windows-specific; but
the "sound" command on Linux used to have ... issues. (possibly
related to the JVM and the OSS/ALSA/whatever is used now transition)

I wrote a small almost trivial workaround (see
http://signalsprocessed.blogspot.com/2011/02/playing-sounds-from-matlab-on-unix.html)
that would simply write the sound to disk then play it from there:

function [ ] = usound( w, fs )
%USOUND Plays sound on ALSA-based linux machines or macs

if nargin < 2
    fs = 16000;
end

filename = ['/tmp/' getenv('USER') '_matplay.wav'];
wavwrite( w, fs, filename );
if ismac
    eval(['!afplay ' filename ' &']);
else
    eval(['!aplay ' filename ' &']);
end

On a modern machine, the overhead is not perceptible: /tmp should be
in RAM anyways.

Note this also doesn't block, so you can continue working while the
sound is playing (IIRC - this code is a bit old :-)

Joe.

-- 
Joachim Thiemann :: http://www.tsp.ece.mcgill.ca/~jthiem1