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

Author Topic: When I disable and re enable audio output device there is no audio output.  (Read 9485 times)

0 Members and 1 Guest are viewing this topic.

ngrj

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello,
I am using sf::Music music to play audio, so after loading the file and playing it, during the process if I disable audio output(speaker/headphones in Sound Window) , there is log in console called AL lib: (EE) MMDevApiProc: Failed to get padding: 0x88890004

How can I make sure music continues after enabling audio device.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #1 on: December 22, 2016, 10:12:11 am »
So far (and as far as I'm aware) SFML doesn't support switching devices on the fly, which also excludes the scenario you suggested. Is there any specific use case other than someone unplugging and reconnecting their headset for example?

ngrj

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #2 on: December 22, 2016, 10:19:36 am »
No, But to hear audio output , he  has to restart the app which is not a ideal solution.
is there any possible solution or hack for this problem?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #3 on: December 22, 2016, 10:20:31 am »
Not right now. Being able to (re-)select devices would be a nice feature though.

ngrj

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #4 on: December 22, 2016, 10:25:43 am »
 :(

or else can u suggest any other cpp audio library if u know any?
because this is kind of an important feature in my app.
I need to work around this.
Also after reconnecting audio device, I've defined a new Music stance, and tried playing it, but it had no effect.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #5 on: December 23, 2016, 06:09:19 pm »
SFML keeps the audio stuff alive in background, even if no active objects persist. You'd have to modify the source to change this.

AndyOrange

  • Newbie
  • *
  • Posts: 13
    • View Profile
I absolutely support this feature request: One needs to be able to "restart" the device without closing the app...

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
I absolutely support this feature request: One needs to be able to "restart" the device without closing the app...
SFML keeps the audio stuff alive in background, even if no active objects persist. You'd have to modify the source to change this.
This was changed quite a while ago. "Restarting" OpenAL is possible, but just as with OpenGL, the user will need to recreate all SFML audio resources in order for the context and device to be recreated. This makes perfect sense for OpenGL since one cannot assume that the contents of device local memory persist even after the device is restarted. In the case of audio devices device local memory seems rather strange but might not even be that far fetched.

Simply put, "restarting" SFML audio is already possible now. The only open problem to solve is how to notice when a device is removed/re-added to the system. When/If the user is notified of such an event, they can take the necessary measures to recreate all audio resources. Since audio device implementations vary from platform to platform and the way changes to the device tree and propagated to applications as well, there is no platform independent way to solve this problem. This is also very specific to audio devices, and to be honest, this isn't something that happens so often that it will be handled with high priority.

For some reason people feel okay disabling and re-enabling audio devices as they see fit even when audio applications are running. On the other hand, everybody would agree that disabling and re-enabling a GPU whether or not a game is running is an absurd idea. If there isn't a good reason to do something then don't do it. I cannot imagine a legitimate reason why swapping out audio devices while applications are still running is absolutely necessary. I've done this with my USB audio devices many times in the past, and I remember every single time I had to restart VLC and other applications that had open audio streams, this really isn't something new. To me this sounds more like a workaround for a problem that should be solved elsewhere.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

AndyOrange

  • Newbie
  • *
  • Posts: 13
    • View Profile
To me this sounds more like a workaround for a problem that should be solved elsewhere.

Completely agreed, but for the time being even vendors build their drivers such that plugging in and out headphones changes the sound device's state (mentioning realtek onboard sound here). Concerning this:

"Restarting" OpenAL is possible, but just as with OpenGL, the user will need to recreate all SFML audio resources in order for the context and device to be recreated.

I would be thankful for a link or for mentioning resources within sfml where this happens, so that one can "copy" that. This at least allows a reset when we know things have been dis-/enabled.

Thanks in advance,
Andy

HughPH

  • Newbie
  • *
  • Posts: 13
    • View Profile
I don't have to restart anything when I unplug my USB amplifier. binary1248 are you using Windows 10 or some earlier version?

I typically change audio devices so that I can listen on speakers when nobody else is in the room, then switch to earphones without interruption. Or I might switch to the digital output so audio goes through my surround system - or back to earphones again if I need to.

I don't see what's so strange about it, and Windows 10 seems to support it better than any previous version of Windows I've used. That suggests Microsoft also consider it a valid and common enough use case for them to support.

The only app that might occasionally "break" is Audacity, but that's because it allows you to select your output device - making it an expected behaviour.

Even Winamp 5.666 works.

HughPH

  • Newbie
  • *
  • Posts: 13
    • View Profile
After a quick look at OpenAL, I don't see that this would be particularly hard. SFML "knows" which sounds are playing, because it's got to be dealing with populating the AL buffers... right? (?) You might lose a bit of buffer, but I doubt anyone's writing military-grade communications systems with SFML. All that's required is to check for error states, and if there's an unrecoverable error, just clean up the old context and create a new one. Swapping out a pointer to the context would mean not much more needs to be done - any music that's playing will pick back up when the buffer next gets written, and sounds would recover too. The only fly in the ointment might be the listener, but if you abstract the refresh of the context to another method, that should be manageable.

All I need to do to switch to OpenAL (via OpenTK probably) is to put together a class that manages the data and streaming it into the OpenAL buffers, either from file (like SFML Music) or from memory buffers. The worst part would be integrating a Vorbis decoder.

GatoRat

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: When I disable and re enable audio output device there is no audio output.
« Reply #11 on: October 11, 2017, 02:23:30 am »
This was changed quite a while ago. "Restarting" OpenAL is possible.... Simply put, "restarting" SFML audio is already possible now.
[/quote]

How?

In our situation if a user Hot-Tabs away from the application AND it is using HDMI audio out, we get the error AL lib: (EE) MMDevApiProc: Failed to get padding: 0x88890004, and the audio stops working. The "solution" is to restart the app. However, adding logic to simply restart OpenAL under certain circumstances would be preferable.

Edit: After looking more at the source, it seems that if stop caching SoundBuffer instances in a global object (main screen) and instead cache them as memory objects only, instantiating them as SoundBuffer instances only when required, OpenAL will effectively reset every time we return to the main screen. Is this correct?
« Last Edit: October 11, 2017, 02:47:56 am by GatoRat »