Extracting samples at the same time of recording

2 次查看(过去 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 个评论
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 中查找有关 Simulation, Tuning, and Visualization 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by