Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for changing the audio playback device during runtime #3029

Merged
merged 1 commit into from
May 28, 2024

Conversation

binary1248
Copy link
Member

Added functions to:

  • Get a list of available audio playback devices
  • Get the default audio playback device is one is marked as such
  • Get the currently used audio playback device
  • Set the audio playback device to use

The API mirrors that which is already part of sf::SoundRecorder for capture devices, with a few "upgrades" for the quirks that might occur with playback devices (such as duplicate names).

Test by plugging in multiple audio devices, running the sound effects example and spamming the F1 key to your heart's content.

@coveralls
Copy link
Collaborator

coveralls commented May 21, 2024

Pull Request Test Coverage Report for Build 9269750449

Details

  • 256 of 345 (74.2%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.009%) to 55.546%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/SFML/Audio/Sound.cpp 9 13 69.23%
src/SFML/Audio/SoundStream.cpp 15 20 75.0%
src/SFML/Audio/PlaybackDevice.cpp 7 20 35.0%
src/SFML/Audio/MiniaudioUtils.cpp 85 113 75.22%
src/SFML/Audio/AudioDevice.cpp 113 152 74.34%
Totals Coverage Status
Change from base Build 9256984392: -0.009%
Covered Lines: 11520
Relevant Lines: 19612

💛 - Coveralls

@Bambo-Borris
Copy link
Contributor

Awesome work here Binary! I'm looking forward to testing this in my own project later today, this is the kind of feature with real value to power users.

Copy link
Member

@vittorioromeo vittorioromeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you a lot for doing this work! I think it's a great improvement from the status quo.

My concern with this design is that we always have one global set-up audio playback device.

A user wouldn't be able to simultaneously send a few sounds to a device and few other sounds to another device, is that correct?

Use cases such as sending voice comms to headphones and game audio to speakers would not be supported if that is the case.

Have you considered a different design that would allow users to set a "default SFML playback device" but then also support the use case I described, where users can play sounds/music on specific audio devices without having to change the global set "playback device"?

include/SFML/Audio/PlaybackDevice.hpp Outdated Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Outdated Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/Sound.cpp Outdated Show resolved Hide resolved
@binary1248 binary1248 force-pushed the feature/select_playback_device branch from 23d83ca to 6d1fc67 Compare May 26, 2024 00:06
@binary1248
Copy link
Member Author

Updated with suggestions.

@binary1248
Copy link
Member Author

Use cases such as sending voice comms to headphones and game audio to speakers would not be supported if that is the case.

Have you considered a different design that would allow users to set a "default SFML playback device" but then also support the use case I described, where users can play sounds/music on specific audio devices without having to change the global set "playback device"?

This is a very very advanced topic, one so advanced that not many AAA games even dare to support simultaneously outputting different audio streams to different audio playback devices.

While technically possible, this would require an entire redesign of the sfml-audio public API, and that is definitely out of scope for this PR and SFML 3.

@binary1248 binary1248 force-pushed the feature/select_playback_device branch 2 times, most recently from 2b42a6e to 9b189b3 Compare May 26, 2024 01:21
Copy link
Member

@ChrisThrasher ChrisThrasher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No structural complaints but I have a number of smaller items of feedback

include/SFML/Audio/PlaybackDevice.hpp Outdated Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Outdated Show resolved Hide resolved
include/SFML/Audio/PlaybackDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.cpp Show resolved Hide resolved
src/SFML/Audio/AudioDevice.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.cpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/AudioDevice.hpp Outdated Show resolved Hide resolved
src/SFML/Audio/MiniaudioUtils.cpp Show resolved Hide resolved
@binary1248 binary1248 force-pushed the feature/select_playback_device branch from 9b189b3 to 186535b Compare May 27, 2024 16:05
@binary1248
Copy link
Member Author

Updated.

@binary1248 binary1248 force-pushed the feature/select_playback_device branch from 186535b to 8e4fc29 Compare May 27, 2024 17:43
@ChrisThrasher
Copy link
Member

Is it feasible to write tests for any of these new APIs?

@binary1248
Copy link
Member Author

Only if they don't have any expectations about what is returned from them... so probably not.

Copy link
Member

@vittorioromeo vittorioromeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, LGTM otherwise

examples/sound_effects/SoundEffects.cpp Outdated Show resolved Hide resolved
@binary1248 binary1248 force-pushed the feature/select_playback_device branch from 1c2c4fb to e93713c Compare May 28, 2024 12:56
@binary1248
Copy link
Member Author

Updated.

…g the default audio playback device and changing the audio playback device during runtime.
Copy link
Member

@vittorioromeo vittorioromeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is some great work. Still need to test this with Open Hexagon but I think it's worth merging now and fixing any issues that arise later.

@ChrisThrasher ChrisThrasher merged commit 123270f into master May 28, 2024
209 checks passed
@ChrisThrasher ChrisThrasher deleted the feature/select_playback_device branch May 28, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants