Extracting samples at the same time of recording
조회 수: 1 (최근 30일)
이전 댓글 표시
hi i am using this code to record audio from microphone and extract audio samples at the same time but am getting following error
Warning: Error occurred while executing the listener callback for event Executing defined for class
internal.IntervalTimer:
Error using tryaudio>audioTimer (line 35)
Undefined function or variable 'lastSampleIdx'.
> In internal.IntervalTimer/onCustomEvent (line 154)
In internal.IntervalTimer>@(source,data)obj.onCustomEvent(data.Type,data.Data) (line 115)
In asyncio.Channel/onCustomEvent (line 473)
In asyncio.Channel>@(source,data)obj.onCustomEvent(data.Type,data.Data) (line 405)
please help me in this i dont know how to solve it or where i am doing it wrong
Fs=8000;
if ~exist('durationSecs','var')
% default to five minutes of recording
durationSecs = 5;
end
if ~exist('N','var')
% default to the sampling rate
N = Fs;
end
% add an extra half-second so that we get the full duration in our
% processing
durationSecs = durationSecs + 0.5;
% index of the last sample obtained from our recording
lastSampleIdx = 0;
% start time of the recording
atTimSecs = 0;
% create the audio recorder
recorder = audiorecorder(Fs,8,1);
% assign a timer function to the recorder
set(recorder,'TimerPeriod',1,'TimerFcn',{@audioTimer});
% start the recording
record(recorder,durationSecs);
% define the timer callback
function audioTimer(hObject,~)
% get the sample data
samples = getaudiodata(hObject);
% skip if not enough data
if length(samples)<lastSampleIdx+1+Fs
return;
end
% extract the samples that we have not performed an FFT on
X = samples(lastSampleIdx+1:lastSampleIdx+Fs);
end
댓글 수: 3
Geoff Hayes
2020년 8월 10일
Hamza - you perhaps should show all of the relevant code and/or clarify how the above is used (via GUI, command line, etc.).
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!