Audiorecorder level trigger starting record
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone I'm trying to use Matlab to record sound from two microphones. I'm using an audiorecorder object to do so
Here's the part of my code concerned :
recObj = audiorecorder(48000,16,2);
recordblocking(recObj, 10);
y=getaudiodata(recObj);
I would like to use a level trigger to start the recording for a fixed time. Is there a function to do it ? instead of using recordblocking
0 个评论
回答(2 个)
Brian
2019-8-21
I know this is three years late, but in case anybody else comes here looking for a solution, you can use a combination of record (instead of record blocking), pause, and getaudiodata if you are using an audiorecorder object. The audiorecorder continues to record while you collect and analyze the data. See sample code below.
triggerLevel=1; % Level to trigger the recording
preRecord=0.1; % Time to record prior to peak
postRecord=0.5; % Time to record after peak
fs=96000; nBits=16;
recObj=audiorecorder(fs,nBits,1,0);
record(recObj) % Start recording
pause(0.5) % Wait half a second
tempdata=getaudiodata(recObj); % Grab data
while max(abs(tempdata))<triggerLevel % Check to see if you've hit the trigger level
pause(0.5) % Keep recording and gathering data if you haven't
tempdata=getaudiodata(recObj);
end
pause(postRecord) % Pause for the specified time
stop(recObj) % Stop recording
finaldata=getaudiodata(recObj);
[~,I]=max(abs(finaldata)); % Find the location of the peak
windowSamples=fs*[preRecord postRecord]+I; % Get window
dataout=finaldata(windowsamples(1):windowsamples(2));
I would recommend including a timeout function so you don't get into an infinite loop, but this is the guts. I hope to have a function submitted in the File Exchange soon, so I will update if it gets posted.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!