-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveStream.m
42 lines (34 loc) · 903 Bytes
/
LiveStream.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function LiveStream(frame,fs,flag)
% Define system parameters
framesize = frame;%80; % Framesize (samples)
Fs = fs;%8000; % Sampling Frequency (Hz)
RUNNING = flag;%1; % A flag to continue data capture
% Setup data acquisition from sound card
ai = analoginput('winsound');
addchannel(ai, 1);
% Configure the analog input object.
set(ai, 'SampleRate', Fs);
set(ai, 'SamplesPerTrigger', framesize);
set(ai, 'TriggerRepeat',inf);
set(ai, 'TriggerType', 'immediate');
% Start acquisition
start(ai)
% Keep acquiring data while "RUNNING" ~= 0
while RUNNING
% Acquire new input samples
newdata = getdata(ai,ai.SamplesPerTrigger)
% Do some processing on newdata
...
%<DO_SOMETHING>
...
% Set RUNNING to zero if we are done
if flag==0
RUNNING = 0;
end
end
% Stop acquisition
stop(ai);
% Disconnect/Cleanup
delete(ai);
clear ai;
end