问题
I'm trying to record my microphone input and process it at the same time.
I tried with a loop with this inside:
recordblocking(recorder, 1);
y = getaudiodata(recorder);
% any processing on y
But while I'm doing something with y
, I'm losing information since not recording continuously.
Is there something I could do to continuously record sound coming in my microphone, store it in some kind of buffer, and process chunks of it at the same time?
A delay isn't a problem, but I really need the recording and processing done simultaneously.
Thanks in advance for any help.
回答1:
I think that you should use Stream processing like this:
% Visualization of audio spectrum frame by frame
Microphone = dsp.AudioRecorder;
Speaker = dsp.AudioPlayer;
SpecAnalyzer = dsp.SpectrumAnalyzer;
tic;
while(toc<30)
audio = step(Microphone);
step(SpecAnalyzer,audio);
step(Speaker, audio);
end
you can find more information here and also in this presentation
回答2:
You can try the block processing framework in LTFAT http://ltfat.github.io/doc/demos/demo_blockproc_basicloop_code.html
Edit: This is the main gist of the code:
% Basic Control pannel (Java object)
p = blockpanel({
{'GdB','Gain',-20,20,0,21},...
});
% Setup blocktream
fs = block('playrec','loadind',p);
% Set buffer length to 30 ms
L = floor(30e-3*fs);
flag = 1;
%Loop until end of the stream (flag) and until panel is opened
while flag && p.flag
gain = blockpanelget(p,'GdB');
gain = 10^(gain/20);
% Read the block
[f,flag] = blockread(L);
% Play the block and do the processing
blockplay(f*gain);
end
blockdone(p);
Note that it is possible to specify input and output devices and their channels by passing additional arguments to the block function. List of available audio devices can be obtained by calling blockdevices.
来源:https://stackoverflow.com/questions/30101695/matlab-real-time-audio-processing