Skip to content

Commit

Permalink
Merge pull request #622 from Psychtoolbox-3/master
Browse files Browse the repository at this point in the history
PTB BETA "Funky Syncopation!" SP2

* Emergency fix for Screen + NVidia blob on Linux.
* Improvements to Snd() and Beeper()
* Some fix to FillInPhotoReceptors()
  • Loading branch information
kleinerm committed Dec 10, 2019
2 parents eaaecd9 + 34ec551 commit 32c8845
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
3 changes: 2 additions & 1 deletion PsychSourceGL/Source/Linux/Screen/PsychWindowGlue.c
Expand Up @@ -1550,9 +1550,10 @@ psych_bool PsychOSOpenOnscreenWindow(PsychScreenSettingsType *screenSettings, Ps
PsychLockDisplay();
vrr_atom = XInternAtom(dpy, "_VARIABLE_REFRESH", False);
XChangeProperty(dpy, win, vrr_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &state, 1);
PsychUnlockDisplay();
}

PsychUnlockDisplay();

// Try to enable swap event delivery to us:
if (PsychOSSwapCompletionLogging(windowRecord, 2, 0) && (PsychPrefStateGet_Verbosity() > 3)) {
printf("PTB-INFO: INTEL_swap_event support for additional swap completion correctness checks enabled.\n");
Expand Down
22 changes: 19 additions & 3 deletions Psychtoolbox/PsychBasic/Beeper.m
Expand Up @@ -54,17 +54,33 @@
end
end

% Silence any console output of Snd():
oldverbo = Snd('Verbosity', 0);

sampleRate = Snd('DefaultRate');

nSample = sampleRate*durationSec;
soundVec = sin(2*pi*frequency*(1:nSample)/sampleRate);

% Scale down the volume
soundVec = soundVec * fVolume;
% sound(soundVec);
try % this part sometimes crashes for unknown reasons. If it happens replace sound with normal beep


try % this part sometimes crashes for unknown reasons. If it happens replace sound with normal beep:
% Play:
Snd('Play', soundVec, sampleRate);

% Wait for playback done:
Snd('Wait');

% Close sound driver again:
Snd('Close');

% Restore old verbosity:
Snd('Verbosity', oldverbo);
catch
% Restore old verbosity:
Snd('Verbosity', oldverbo);

% Primitive beep() fallback:
beep
end
Binary file modified Psychtoolbox/PsychBasic/Octave3LinuxFiles64/Screen.mex
Binary file not shown.
Binary file modified Psychtoolbox/PsychBasic/Screen.mexa64
Binary file not shown.
61 changes: 50 additions & 11 deletions Psychtoolbox/PsychBasic/Snd.m
Expand Up @@ -68,6 +68,9 @@
% is checked for correctness, but other than that it is ignored. Allowable
% values are either 8 or 16.
%
% oldverbosity = Snd('Verbosity' [, verbosity]);
% - Query current level of verbosity, optionally set a new 'verbosity' level.
%
% Snd('Open') opens the channel, which stays open until you call
% Snd('Close'). Snd('Play',...) automatically opens the channel if it isn't
% already open. You can use Snd('Open', pahandle); to share an existing
Expand Down Expand Up @@ -106,8 +109,8 @@
%
% Snd('Play',sin(0:10000)); % play 22 KHz/(2*pi)=3.5 kHz tone
% Snd('Play',[sin(1:20000) zeros(1,10000);zeros(1,10000) sin(1:20000)]); % stereo
% Snd('Wait'); % wait until end of all sounds currently in channel
% Snd('Quiet'); % stop the sound and flush the queue
% Snd('Wait'); % wait until end of all sounds currently in channel
% Snd('Quiet'); % stop the sound and flush the queue
%
% For most of the commands, the returned value is zero when successful, and
% a nonzero error number when Snd fails.
Expand Down Expand Up @@ -162,15 +165,18 @@
% 1/19/16 mk Make more robust against failing InitializePsychSound. Fallback to sound().
% 7/11/19 mk Allow sharing pahandle with external code / piggyback onto existing pahandle
% via Snd('Open', pahandle);
% 12/9/19 mk Add 'Verbosity' subcommand to be able to silence Snd() and PsychPortAudio() output.

persistent ptb_snd_oldstyle;
persistent ptb_snd_injected;
persistent pahandle;
persistent verbose;

persistent endTime;
if isempty(endTime)
endTime = 0;
ptb_snd_injected = 0;
verbose = 1;
end

% Default return value:
Expand All @@ -180,6 +186,16 @@
error('Wrong number of arguments: see Snd.');
end

if strcmpi(command, 'Verbosity')
if nargin ~= 2
error('Snd: Called "Verbosity" without specifying verbosity level.');
end

err = verbose;
verbose = signal;
return;
end

% Snd('Open', pahandle) called to inject a pahandle of an already open
% PsychPortAudio device for sharing? If so, we piggyback onto pahandle
% for our audio playback:
Expand All @@ -200,7 +216,10 @@

endTime = 0;

fprintf('Snd(): Using PsychPortAudio via handle %i until you call Snd(''Close'');\n', pahandle);
if verbose
fprintf('Snd(): Using PsychPortAudio via handle %i until you call Snd(''Close'');\n', pahandle);
end

return;
end

Expand All @@ -213,12 +232,16 @@
% Matlab/Octave sound() function:
ptb_snd_oldstyle = 1;

fprintf('Snd(): Using Matlab/Octave sound() function for sound output.\n');
if verbose
fprintf('Snd(): Using Matlab/Octave sound() function for sound output.\n');
end
else
% User wants new-style PsychPortAudio variant:
ptb_snd_oldstyle = 0;

fprintf('Snd(): Initializing PsychPortAudio driver for sound output.\n');
if verbose
fprintf('Snd(): Initializing PsychPortAudio driver for sound output.\n');
end

% Low-Latency preinit. Not that we'd need it, but doesn't hurt:
try
Expand All @@ -237,9 +260,23 @@
% Windows, as that device will often have exclusive access, so we would
% fail here:
if ~(strcmpi(command,'Open') || strcmpi(command,'Quiet') || strcmpi(command,'Close')) && ...
isempty(pahandle) && ~ptb_snd_oldstyle && ~IsOSX && (PsychPortAudio('GetOpenDeviceCount') > 0)
fprintf('Snd(): PsychPortAudio already in use. Using old sound() fallback instead...\n');
ptb_snd_oldstyle = 1;
isempty(pahandle) && ~ptb_snd_oldstyle && ~IsOSX

if ~verbose
oldv = PsychPortAudio('Verbosity', 0);
odc = PsychPortAudio('GetOpenDeviceCount');
PsychPortAudio('Verbosity', oldv);
else
odc = PsychPortAudio('GetOpenDeviceCount');
end

if odc > 0
if verbose
fprintf('Snd(): PsychPortAudio already in use. Using old sound() fallback instead...\n');
end

ptb_snd_oldstyle = 1;
end
end

if strcmpi(command,'Play')
Expand Down Expand Up @@ -329,8 +366,10 @@
else
% Should change samplerate, but can not, as this is a shared
% pahandle:
fprintf('Snd(): Shared PsychPortAudio handle. Can not change sample rate from current %f Hz to %f Hz as requested!\n', ...
props.SampleRate, rate);
if verbose
fprintf('Snd(): Shared PsychPortAudio handle. Can not change sample rate from current %f Hz to %f Hz as requested!\n', ...
props.SampleRate, rate);
end
end
end
end
Expand All @@ -348,7 +387,7 @@
% Restore standard level of verbosity:
PsychPortAudio('Verbosity', oldverbosity);

if ~IsOSX
if ~IsOSX && verbose
fprintf('Snd(): PsychPortAudio will be blocked for use by your own code until you call Snd(''Close'');\n');
fprintf('Snd(): If you want to use PsychPortAudio and Snd in the same session, make sure to open your\n');
fprintf('Snd(): stimulation sound device via calls to, e.g., pahandle = PsychPortAudio(''Open'', ...);\n');
Expand Down
2 changes: 1 addition & 1 deletion Psychtoolbox/PsychColorimetricData/FillInPhotoreceptors.m
Expand Up @@ -325,7 +325,7 @@
photoreceptors.lensDensity.transmittance(photoreceptors.lensDensity.transmittance > 1) = 1;
end
else
if (~isfield(photoreceptors.lensDensity.transmittance))
if (~isfield(photoreceptors.lensDensity,'transmittance'))
error('photoreceptors.lensDensity field passed, but without source or transmittance');
end
end
Expand Down

0 comments on commit 32c8845

Please sign in to comment.