yogan - you could use the non-blocking record function instead and just assign a callback to the TimerFcn of your recorder. Then whenever the callback fires, you can grab the latest set of audio samples and process them. A very crude example is the following piece of code
function myRecorder = nonBlockingAudioRecorder
figure;
hPlot = plot(NaN,NaN);
sampleRate = 8192;
myRecorder = audiorecorder(sampleRate,8,1);
set(myRecorder, 'TimerFcn', @myRecorderCallback, 'TimerPeriod', 1);
atSecond = 1;
record(myRecorder);
function myRecorderCallback(~, ~)
allSamples = getaudiodata(myRecorder);
newSamples = allSamples((atSecond - 1) * sampleRate + 1:atSecond * sampleRate);
xdata = get(hPlot, 'XData');
ydata = get(hPlot, 'YData');
if isnan(xdata)
xdata = linspace(0, atSecond - 1/sampleRate,sampleRate);
ydata = [];
else
xdata = [xdata linspace(atSecond, atSecond + 1 - 1/sampleRate, sampleRate)];
end
ydata = [ydata newSamples'];
set(hPlot, 'XData', xdata, 'YData', ydata);
atSecond = atSecond + 1;
if atSecond > 10
stop(myRecorder);
end
end
end
The above code records about a little over eleven seconds of data. Whenever the callback fires (about every one second), we grab the latest 8192 samples and plot them.