-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtonecal_MMN.m
54 lines (37 loc) · 1.3 KB
/
tonecal_MMN.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
43
44
45
46
47
48
49
50
51
52
53
54
%Requires psychtoolbox
%Simple function to create an abitrary duration sine at one of 3
%frequencies (500 1000 1500)Hz
%e.g. tonecal_MMN(1000,5) --> a 1k tone for 5 seconds
%PFS March2018
function tonecal_MMN(frequency,duration)
if ~ismember(frequency,[500 1000 1500])
error ('Illegal duration: please use 500, 1000 or 1500 only')
else
end
InitializePsychSound(1);
% Number of channels and Frequency of the sound
nrchannels = 2;
freq = 48000;
% How many times to we wish to play the sound
repetitions = 1;
% Length of the tone
toneLengthSecs = duration; % in seconds
% Length of the pause between tones
tonePauseTime = 0.5;
% Start immediately (0 = immediately)
startCue = 0;
% Initialise PPA object
pahandle = PsychPortAudio('Open', [], [], 0, freq, nrchannels);
% Build the tone
tone = MakeBeep(frequency, toneLengthSecs, freq);
% Put waveform in buffer
PsychPortAudio('FillBuffer', pahandle, [tone; tone]);
% Set the calibration level this is the standard mid range
PsychPortAudio('Volume', pahandle,0.5); % dont change this volume
% Start playback
PsychPortAudio('Start', pahandle, repetitions, startCue, 1);
% Wait for stop of playback
PsychPortAudio('Stop', pahandle, 1, 1);
% Close the audio device
PsychPortAudio('Close', pahandle);
end