Skip to content

Commit

Permalink
PsychPortAudio/Win: Use auto samplerate conversion under WASAPI share…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
kleinerm committed Apr 10, 2024
1 parent a595170 commit adf770c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions PsychSourceGL/Source/Common/PsychPortAudio/PsychPortAudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit adf770c

Please sign in to comment.