/usr/share/psychtoolbox-3/PsychTests/DirectInputMonitoringTest.m is in psychtoolbox-3-common 3.0.11.20140816.dfsg1-1.
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | function DirectInputMonitoringTest
% DirectInputMonitoringTest - Test "Zero latency direct input monitoring" feature of some sound cards.
%
% This test will currently only work on a subset of some ASIO 2.0 capable
% soundcards on Microsoft Windows operating systems with the latest
% PsychPortAudio driver and portaudio_x86 ASIO enabled plugin from the
% Psychtoolbox Wiki.
%
% The test allows you to exercise Direct input monitoring features on your
% soundcard if the card supports them.
%
% Use ESCape to exit. Space to toggle mute/unmute. 'i' key to change input
% channel to monitor, 'o' key to select output channel for monitoring. Use
% Cursor Up/Down to increase and decrease amplifier gain. Use Left/Right
% cursor keys to change stereo panning. The 'p' key puts the device into a
% fake playback mode.
%
% History:
% 2.8.2009 mk Written.
% Preinit driver:
InitializePsychSound(1);
% Choose high level of debug output:
oldverbosity = PsychPortAudio('Verbosity', 10);
% Open auto-detected audio device in full-duplex mode for audio capture &
% playback, with lowlatency mode 1. Lowlatency mode is not strictly
% required, but has the nice side-effect to automatically assing the lowest
% latency audio device, which is an installed ASIO card on Windows or the
% ALSA audio system on Linux -- both are required for direct input
% monitoring to work:
pa = PsychPortAudio('Open', [], 1+2, 1, 48000, 2);
% Create a fake playback buffer and recording buffer, in case we need to do
% fake playback/recording:
PsychPortAudio('Fillbuffer', pa, zeros(2, 10));
PsychPortAudio('GetAudioData', pa, 1);
% Retrieve number of input- and output soundchannels for device pa:
status = PsychPortAudio('GetStatus', pa);
outdev = PsychPortAudio('GetDevices', [], status.OutDeviceIndex);
noutputs = outdev.NrOutputChannels;
inpdev = PsychPortAudio('GetDevices', [], status.InDeviceIndex);
ninputs = inpdev.NrInputChannels;
fprintf('\n\nDevice has %i input channels and %i output channels.\n\n', ninputs, noutputs);
% Select all inputchannels (-1) for monitoring. Could also spec a specific
% channel number >=0 to set monitoring settings on a per-channel basis:
inputchannel = -1;
% Output to channel 0 or channels 0 & 1 on a stereo output channel pair.
% Any even number would do:
outputchannel = 0;
% Start with maximum 12 dB gain: On Windows, values between -1 and +1 are
% valid on ASIO hardware for attenuation (-1 = -inf dB) or amplification
% (+1 = +12 dB).
if IsWin
gain = 1.0;
end
% On OS/X we also set 12 dB gain, here the value actually specifies the
% requested dB value:
if IsOSX
gain = 12.0;
end
% Sterat with centered output on a stero channel: Values between 0.0 and
% 1.0 select left <-> right stereo panning, 0.5 is centered:
pan = 0.5;
KbName('UnifyKeyNames');
lKey = KbName('LeftArrow');
rKey = KbName('RightArrow');
uKey = KbName('UpArrow');
dKey = KbName('DownArrow');
oKey = KbName('o');
iKey = KbName('i');
pKey = KbName('p');
space = KbName('space');
esc = KbName('ESCAPE');
KbReleaseWait;
unmute = 1;
% Set initial 'DirectInputMonitoring mode':
diResult = PsychPortAudio('DirectInputMonitoring', pa, unmute, inputchannel, outputchannel, gain, pan);
fprintf('Enabled: %i Inchannel: %i, OutChannel: %i, gain %f, stereopan %f, RC = %i\n', unmute, inputchannel, outputchannel, gain, pan, diResult);
% Lower level of debug output:
PsychPortAudio('Verbosity', oldverbosity);
% Repeat parameter change loop until user presses ESCape or error:
while 1
% Wait for user keypress:
[secs, keyCode] = KbStrokeWait;
% Disable old setting - Mute current configuration:
% Don't know if this is really needed or not, but let's start safe...
% MK: Disabled for test purpose: diResult = PsychPortAudio('DirectInputMonitoring', pa, 0, inputchannel, outputchannel, gain, pan);
if keyCode(esc)
% Exit:
break;
end
if keyCode(pKey)
% Trigger fake playback & recording, in case this is needed:
fprintf('\n\n == Fake playback & recording started: == \n\n');
PsychPortAudio('Start', pa, 0, 0, 1);
KbReleaseWait;
% Disable pKey for further iterations:
pKey = 1;
end
if keyCode(space)
% Mute/Unmute:
unmute = 1 - unmute;
end
% Change stereo panning left/right:
if keyCode(lKey)
pan = min(1.0, max(0.0, pan - 0.1));
end
if keyCode(rKey)
pan = min(1.0, max(0.0, pan + 0.1));
end
% Change gain between -inf dB (Mute) to +12 dB on ASIO hardware:
if keyCode(uKey)
gain = min(1.0, max(-1.0, gain + 0.1));
end
if keyCode(dKey)
gain = min(1.0, max(-1.0, gain - 0.1));
end
% Switch through possible output channels:
if keyCode(oKey)
% Always increment by two so outputchannel stays even, which is
% required for ASIO hardware:
outputchannel = mod(outputchannel + 2, noutputs);
end
% Switch through possible output channels:
if keyCode(iKey)
inputchannel = inputchannel + 1;
% Wrap around to -1 (all channels) if max. reached:
if inputchannel >= ninputs
inputchannel = -1;
end
end
% Set a new 'DirectInputMonitoring mode':
diResult = PsychPortAudio('DirectInputMonitoring', pa, unmute, inputchannel, outputchannel, gain, pan);
fprintf('Enabled: %i Inchannel: %i, OutChannel: %i, gain %f, stereopan %f, RC = %i\n', unmute, inputchannel, outputchannel, gain, pan, diResult);
end
% Done. Try to mute setup. Don't care about error flag...
PsychPortAudio('DirectInputMonitoring', pa, 0, inputchannel, outputchannel, gain, pan);
% Close device and driver:
PsychPortAudio('Close');
fprintf('Done. Bye!\n');
return;
|