Audiorecorder level trigger starting record

조회 수: 2 (최근 30일)
Benoit Meriot
Benoit Meriot 2016년 6월 1일
답변: Brian 2019년 8월 21일
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

답변 (2개)

Brian
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.

Pavel Dey
Pavel Dey 2016년 6월 9일
I think you may refer to this link , which answers a similar query.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by