From adf770c21b3a276fcaaebecd3e65804d88099bc5 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Wed, 10 Apr 2024 16:05:48 +0100 Subject: [PATCH] PsychPortAudio/Win: Use auto samplerate conversion under WASAPI shared mode. WASAPI shared mode only supports one fixed sample rate, the rate of the system mixer, by default. Request use of system automatic sample format and sample rate conversion in reqlatencyclass 0 and 1, ie. if shared audio mode is used, to prevent this limitation from aborting scripts. This requires Windows 7 or later (a given), and Portaudio V19.7.0 or later, otherwise the new option will be silently ignored. We do ship that version or later, so should be fine, unless somebody uses an override portaudio dll from Matlab, whose version I don't know from the top of my head. -> Rebuild and test pending. Cfe. following issue where this would likely have helped: https://psychtoolbox.discourse.group/t/ptb-thinks-usb-sound-card-doesnt-support-44100hz/5324 --- .../Source/Common/PsychPortAudio/PsychPortAudio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PsychSourceGL/Source/Common/PsychPortAudio/PsychPortAudio.c b/PsychSourceGL/Source/Common/PsychPortAudio/PsychPortAudio.c index 00e062ebb..66eb70c2b 100644 --- a/PsychSourceGL/Source/Common/PsychPortAudio/PsychPortAudio.c +++ b/PsychSourceGL/Source/Common/PsychPortAudio/PsychPortAudio.c @@ -2873,6 +2873,13 @@ PsychError PSYCHPORTAUDIOOpen(void) inwasapiapisettings.flags |= paWinWasapiExclusive; outwasapiapisettings.flags |= paWinWasapiExclusive; } + else { + // In non-exclusive / shared mode, allow auto conversion of sample rate + // to system mixer sample rate, or most requested sample rates would fail in + // shared mode. Needs at least Windows 7SP1, and at least Portaudio V19.7.0: + inwasapiapisettings.flags |= paWinWasapiAutoConvert; + outwasapiapisettings.flags |= paWinWasapiAutoConvert; + } if (latencyclass > 2) { // Windows 10 or later?