BF: Fix default audio device not being found#6863
Merged
TEParsons merged 2 commits intopsychopy:releasefrom Sep 20, 2024
Merged
BF: Fix default audio device not being found#6863TEParsons merged 2 commits intopsychopy:releasefrom
TEParsons merged 2 commits intopsychopy:releasefrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release #6863 +/- ##
===========================================
- Coverage 49.64% 49.61% -0.03%
===========================================
Files 332 332
Lines 61204 61209 +5
===========================================
- Hits 30383 30371 -12
- Misses 30821 30838 +17
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to 2024.2.0, if your system audio output sample rate wasn't 48000 then initialising a Sound with default speaker raised an error, as ptb doesn't have a method of getting the system default speaker's sample rate; you can only initialise a speaker with -1 as the index. So with no way of asking "what is the sample rate of the system default speaker?" we're forced to just try to set it up with the default (48000), leading to an error if your speaker didn't match.
To get around this, rather than using an index of
-1to initialise a stream, we simply got the first device found and used its parameters instead. Because we got the device's actual info from ptb, this meant it wouldn't error when initialising, so you'd at least have a speaker. The problem is that the first device found isn't necessarily the system audio, so some people are finding audio playing out of the wrong speaker when it's set to "default".This solution attempts to retain ptb's default speaker behaviour (by passing it -1), but catching the error and resorting to using the first device found instead. This isn't ideal - if your system audio has a sample rate other than 48000 then you'll still find sound playing on the wrong device sometimes, and there's a lot of console spam (even if we catch errors raised by ptb, it'll still print to the console when it fails).
In the long run I think we need to find a way to identify the system default device and get its parameters before attempting to connect to it. I can't see a way to do that with ptb, but maybe we can use another audio system to get its system name and then match with ptb's indexes from that?
Fixes #6372