Extracting samples at the same time of recording

2 visualizzazioni (ultimi 30 giorni)
Hamza Ashraf
Hamza Ashraf il 9 Ago 2020
Commentato: Geoff Hayes il 10 Ago 2020
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 Commenti
Hamza Ashraf
Hamza Ashraf il 9 Ago 2020
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 il 10 Ago 2020
Hamza - you perhaps should show all of the relevant code and/or clarify how the above is used (via GUI, command line, etc.).

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Simulation, Tuning, and Visualization in Help Center e File Exchange

Tag

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by