필터 지우기
필터 지우기

Extracting samples at the same time of recording

조회 수: 3 (최근 30일)
Hamza Ashraf
Hamza Ashraf 2020년 8월 9일
댓글: Geoff Hayes 2020년 8월 10일
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
Hamza Ashraf
Hamza Ashraf 2020년 8월 9일
oki but in that example i can not reuse the samples X in my code can you help me how can i use these X samples somewhere else in the code
% extract the samples that we have not performed an FFT on
X = samples(lastSampleIdx+1:lastSampleIdx+Fs);
Geoff Hayes
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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by