Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Change output audio device  (Read 3444 times)

0 Members and 1 Guest are viewing this topic.

FonzTech

  • Newbie
  • *
  • Posts: 2
    • View Profile
Change output audio device
« on: March 23, 2019, 03:36:35 pm »
Hi at all! I new on this forum. I have a direct question.
- Why SFML does not support output device switching on the fly? What are the technical reasons behind that?
I know that this implies many other things to consider, like listening for device changes by the OS, which OpenAL doesn't, obviously. Although I don't know much of OpenAL, I think there are some consideration about buffers, which are possibly related to a specific context, linked to an output device? Surely device switching on the fly it's 100% possible in OpenAL.
I think this would be a great function to be present in SFML. People like me, switch from headphones to the monitor audio output. Maybe you connect a third output device while running a SFML application, and restarting it is a very bad thing just to hear audio output.
Thanks in advance!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Change output audio device
« Reply #1 on: March 25, 2019, 10:08:18 am »
The current situation is as far as I know, that SFML will use the default device, when creating the first audio context (e.g. when you play a sf::Sound or sf::Music object).
As such, a workaround would be to destroy all sound/music objects when switching, that way, when the next audio context is created it will take the new default device.

I agree that there's still quite some potential for SFML's audio API to either handle the switch of the default device automatically and/or to provide the tools for the user to do it.

Now we simply need someone to provide a solution design/blueprint and then someone to provide the implementation. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FonzTech

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Change output audio device
« Reply #2 on: March 30, 2019, 10:22:47 pm »
Thanks for the reply.
I think SFML should give the ability to register a callback function, which triggers everytime the audio devices list is changed. Obviously SFML must give the ability to get the current available audio devices.

Something like this:

Quote
void sf::SetOnAudioDevicesUpdate(std::function<void()> callback);

std::vector<sf::priv::AudioDevice> sf::GetAudioDevices();

int sf::SetAudioDevice(sf::priv::AudioDevice audioDevice);

Now, you can destroy the previous context and recreate a new one with the supplied audio device, then make the context current.

Is this possible?

Thanks in advance!