-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_recordaudio.m
28 lines (23 loc) · 1.41 KB
/
demo_recordaudio.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
%% Very basic audio recording script
% Records 2 seconds of audio on the default sound playback device
%% PsychToolbox basic setup
PsychDefaultSetup(2); % apply common Psychtoolbox parameters
InitializePsychSound; % initialize Psychtoolbox audio
%% Sound setup
if PsychPortAudio('GetOpenDeviceCount') % check to see if a PortAudio device is still open...
PsychPortAudio('Close'); % ...and close it
end
paudio = PsychPortAudio('Open',[],2); % open default sound capture device using lowest latency interface
status = PsychPortAudio('GetStatus',paudio); % Get audio device status
fs = status.SampleRate; % ...extract sample rate
%% Recording setup
duration = 5; % set sound capture duration (secs)
PsychPortAudio('GetAudioData', paudio, duration); % setup recording buffer of required duration
%% Record sound
tstart = PsychPortAudio('Start',paudio,[],[],1); % start recording and save start time
WaitSecs(duration);
status = PsychPortAudio('GetStatus',paudio);
tstop = status.EstimatedStopTime; % save stop time
wav = PsychPortAudio('GetAudioData', paudio); % get recorded sound
%% Tidy up & end
PsychPortAudio('Close'); % close audio device