/usr/share/psychtoolbox-3/PsychSound/moallowlatency.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | function moallowlatency
% Establish key mapping: ESCape aborts, Space toggles between auto-
% movement of sound source or user mouse controlled movement:
KbName('UnifyKeynames');
space = KbName('space');
esc = KbName('ESCAPE');
% Initialize OpenAL subsystem at debuglevel 2 with the default output
% device:
InitializeMatlabOpenAL(0);
dummy=GetSecs;
WaitSecs(0.1);
% Generate one sound buffer:
buffers = alGenBuffers(1);
% Query for errors:
alGetString(alGetError)
% Create sound data:
freq = 44100;
% Start off with 10 seconds of 48 Khz random stereo noise as a fallback:
%mynoise = randn(2,freq * 0.1);
% Create sound data:
freq = 44100;
% Start off with 10 seconds of 48 Khz random stereo noise as a fallback:
%mynoise = randn(2,freq * 0.1);
mynoise(1,:) = 0.9 * MakeBeep(1000, 0.1, freq);
mynoise(2,:) = mynoise(1,:);
% Convert to 16 bit signed integer format, map range from -1.0 ; 1.0 to -32768 ; 32768.
% This is one of two sound formats accepted by OpenAL, the other being unsigned 8 bit
% integer in range 0;255. Other formats (e.g. float or double) are supported by some
% implementations, but one can't count on it. This is more efficient anyways...
mynoise = int16(mynoise * 32767);
% Fill our sound buffer with the data from the sound vector. Tell AL that its
% a 16 bpc, stereo format, with length(mynoise)*2*2 bytes total, to be played at
% a sampling rate of freq Hz. The AL will resample this to the native device
% sampling rate and format at buffer load time.
% We use stereo even for mono sounds, because stereo sounds are not
% spatialized by OpenAL, i.e., no 3D computations --> faster.
alBufferData( buffers, AL.FORMAT_STEREO16, mynoise, length(mynoise)*2*2, freq);
% Create a sound source:
source = alGenSources(1);
% Attach our buffer to it: The source will play the buffers sound data.
alSourceQueueBuffers(source, 1, buffers);
% Switch source to single shot.
alSourcei(source, AL.LOOPING, AL.FALSE);
% Set emission volume to 100%, aka a gain of 1.0:
alSourcef(source, AL.GAIN, 1);
% Set source to head-relative: In some implementations this skips some
% source<->listener 3D transformations. Our source sits in the origin
% (0,0,0) by default, as does our listener. --> No 3D spatialization.
alSourcei(source, AL.SOURCE_RELATIVE, AL.TRUE);
alSourcePlay(source);
WaitSecs(0.5);
offset = alGetSourcef(source, AL.SAMPLE_OFFSET);
alSourceStop(source);
% Perform some preflip to heat up the pipe:
screenid = max(Screen('Screens'));
win = Screen('OpenWindow', screenid, 0);
% Wait for keypress.
while KbCheck; end;
KbWait;
% Realtime scheduling:
% Priority(MaxPriority(win));
for i=1:10
Screen('Flip', win);
% Prepare black white transition:
Screen('FillRect', win, 255);
Screen('DrawingFinished', win);
% Wait a few seconds...
WaitSecs(0.66);
% Ok, the next flip will do a black-white transition...
[vbl visual_onset t1] = Screen('Flip', win);
% Start playback for this source:
alSourcePlay(source);
t2 = GetSecs;
tstart = t2;
%WaitSecs(0.020);
% Spin-Wait until hw reports the first sample is played...
offset = 0;
while offset == 0
offset = alGetSourcef(source, AL.SAMPLE_OFFSET);
t3=GetSecs;
end
fprintf('Expected visual onset at %6.6f\n', visual_onset);
fprintf('Sound started between %6.6f and %6.6f\n', t1, t2);
fprintf('Expected latency sound - visual = %6.6f\n', t2 - visual_onset);
fprintf('First sound buffer played at %6.6f\n', t3);
fprintf('Delay start vs. played: %6.6f secs, offset %f\n', t3 - t2, offset);
WaitSecs(0.2);
% Stop playback:
alSourceStop(source);
Screen('FillRect', win, 0);
telapsed = Screen('Flip', win) - visual_onset
end
Priority(0);
% Unqueue sound buffer:
alSourceUnqueueBuffers(source, 1);
% Wait a bit:
WaitSecs(0.1);
% Delete buffer:
alDeleteBuffers(1, buffers);
% Wait a bit:
WaitSecs(0.1);
% Delete source:
alDeleteSources(1, source);
% Wait a bit:
WaitSecs(0.1);
% Shutdown OpenAL:
CloseOpenAL;
Screen('CloseAll');
% Done. Bye.
return;
|