Extracting samples at the same time of recording
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Geoff Hayes
am 10 Aug. 2020
Hamza - you perhaps should show all of the relevant code and/or clarify how the above is used (via GUI, command line, etc.).
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulation, Tuning, and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!