Skip to content

BF: Fix default audio device not being found#6863

Merged
TEParsons merged 2 commits intopsychopy:releasefrom
TEParsons:release-bf-ptb-default
Sep 20, 2024
Merged

BF: Fix default audio device not being found#6863
TEParsons merged 2 commits intopsychopy:releasefrom
TEParsons:release-bf-ptb-default

Conversation

@TEParsons
Copy link
Copy Markdown
Contributor

@TEParsons TEParsons commented Sep 19, 2024

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 -1 to 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

@TEParsons TEParsons requested a review from peircej September 19, 2024 15:27
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 49.61%. Comparing base (eb5e61b) to head (f775d44).
Report is 11 commits behind head on release.

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     
Components Coverage Δ
app ∅ <ø> (∅)
boilerplate ∅ <ø> (∅)
library ∅ <ø> (∅)
vm-safe library ∅ <ø> (∅)

@TEParsons TEParsons merged commit ab3e33a into psychopy:release Sep 20, 2024
@TEParsons TEParsons deleted the release-bf-ptb-default branch October 4, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant