Skip to content

Instantly share code, notes, and snippets.

@kleinerm
kleinerm / MouseMotionRecordingDemoPimped.m
Created February 16, 2024 05:09
Demo for Psychtoolbox forum message 5248 - Joystick motion recording principle.
function MouseMotionRecordingDemoPimped
% MouseMotionRecordingDemoPimped - Record mouse motion via KbQueues.
%
% This demo shows very basic recording of mouse/touchpad motion
% movement data under Linux.
%
% Press a key on the keyboard to end the demo.
%
% It requests recording of raw motion, ie. of the device itself,
% in device and operating system specific distance units, not
@kleinerm
kleinerm / DelayedSoundFeedbackDemo.m
Created June 15, 2022 17:42
Modified files for Portaudio+Pulseaudio testing.
function DelayedSoundFeedbackDemo(reqlatency, duplex, freq, minLatency, device)
% DelayedSoundFeedbackDemo([reqlatency=150 ms][, duplex=0][, freq]=48000[, minLatency=10 ms][, device])
%
% CAUTION: TEST TIMING OF THIS SCRIPT WITH MEASUREMENT EQUIPMENT IF YOU
% DEPEND ON ACCURATE FEEDBACK TIMING!!!
%
% Demonstrates usage of the new Psychtoolbox sound driver PsychPortAudio()
% for audio feedback with a controlled delay.
%
% Sound is captured from the default recording device and then - with a
trial_number = 90;
% Input set of images:
test_images = [1,2,3,4,5]
nrImages = length(test_images);
% Present each 3 times:
max_image_presentations = trial_number / nrImages
tic
if 1
@kleinerm
kleinerm / 0001-Hacks-for-testing-cursor-control-by-server-for-a-lea.patch
Created January 26, 2022 20:36
Hack against x-server master/21.1 so it keeps controlling mouse cursor shape/position on a leased out RandR output.
From ee98f3b1c9d0239b460f7c772cbf0e1c0da33682 Mon Sep 17 00:00:00 2001
From: Mario Kleiner <mario.kleiner.de@gmail.com>
Date: Tue, 25 Jan 2022 23:32:57 +0100
Subject: [PATCH] Hacks for testing cursor control by server for a leased out
drm/randr output.
- Allow enable of atomic modesetting under modesetting-ddx to test how
an atomic server would behave.
- Disable some checks to allow X-Server to control cursor appearance and
function debugPseudogray(plotstim)
if nargin < 1
error('Specify plotstim as 0, 1 or 2 !');
end
KbName('UnifyKeyNames');
UpArrow = KbName('UpArrow');
DownArrow = KbName('DownArrow');
LeftArrow = KbName('LeftArrow');
function BasicSoundPhaseShiftDemoPimped(showit, targetChannel)
% BasicSoundPhaseShiftDemoPimped([showit=1][, targetChannel=1])
%
% Demonstrates how one can play back a phase-shifted sine tone, with dynamically
% adjustable phase shift, free of audible artifacts during phase shift change.
%
% This uses PsychPortAudio's realtime mixing and some trigonometric math to
% synthesize a cosine wave of selectable phase in realtime from the weighted sum
% of a pair of a cosine + sine wave with different relative amplitudes.
%
@kleinerm
kleinerm / MeasureLuminancePrecision.m
Created May 19, 2019 04:52
MeasureLuminancePrecision by Denis Pelli, slightly improved.
function data=MeasureLuminancePrecision
% data=MeasureLuminancePrecision
% INSTRUCTIONS: [Currently this program requires a Cambridge Research
% Systems photometer, but you could easily adapt it to use another
% photometer.] Plug your photometer's USB cable into your computer,
% carefully place your photometer stably against your computer's screen,
% set PARAMETERS (below), then run. The results (including the best-fitting
% n-bit-precision model) will be displayed as a graph in a MATLAB figure
% window, and also saved in three files (in the same folder as this file)
% with filename extensions: png, fig, and mat. The filename describes the
@kleinerm
kleinerm / RawMouse2.m
Created January 30, 2012 14:38
Do your own mouse driver as M-File via raw HID access. Version for "12-Bit mouse'
function [ dx, dy, sx, sy ] = RawMouse2(devIndex)
% Parse raw HID datastream from a mouse to implement
% raw mouse movement from HID reports.
%
% This is just an example! The data format is mouse
% dependent, this is for a DELL LaserMouse.
%
% Must be run "sudo" root unless proper udev rules
% are defined to allow non-root raw access to mouse
% on your system.
@kleinerm
kleinerm / RawMouse.m
Created January 30, 2012 14:37
Do your own mouse driver as M-File via raw HID access. Version for "8-Bit mouse'
function [ dx, dy, sx, sy ] = RawMouse(devIndex)
persistent sx;
persistent sy;
if isempty(sx)
sx = 0;
sy = 0;
end