From: lior on
Hello,
I'm simulating an active noise control system,

In one of the stages in need to continuously sample sound (using a for loop) and also continuously play the sound, it looks like this:

totalsampling=2000;
fs = 44100;

for i=1:totalsampling
un(i)= wavrecord(1,fs);
tic;
noise=un(i);
unminus(i)=-(un(i));
usound=50*unminus(i);
soundsc(usound)
timer(i)=toc;

end

The problem is that after approximately 400 iterations (varying each time), i'm getting this message:

??? Unable to open sound device.


Error in ==> sound at 36
playsnd(y,fs,bits);

Error in ==> soundsc at 47
sound(varargin{:})

Error in ==> test333 at 14
sound(usound)

Anyone have any idea why?

Thanks!