Closed rsn8887 closed 5 years ago
Seems to me like a problem with the homebrew apps themselves. Which apps have issues? If they're based on SDL; then this issue should be reported there.
you might be right all apps it happens with seem to be using SDL, including nx quake I wasn’t aware.
Can you try non-SDL apps for this?
I tried Retroarch and it doesn’t show the issue
RA has handling for this.
So you mean the audio problems mentioned here have been fixed somehow:
https://github.com/switchbrew/libnx/pull/201#issuecomment-436737946 ?
Because the way I understand it now, Retroarch "handles" this is by simply disabling suspend to prevent the audio problems on resume.
I would like to resume from suspend without audio problems without disabling suspend altogether.
Not sure if using audren instead would help.
Try the audio examples from switch-examples.
Hmm, the audio examples work fine. Well, the echo example is always distorted/choppy but that is regardless of the suspend/resume history. It might be my microphone (builtin mic on Apple earbuds).
Do they use threaded audio though? I remember in the Retroarch comments it was specifically mentioned threaded audio only as the problem. And SDL uses threaded audio, too.
"Do they use threaded audio though?" No, see source.
To quote @natinusula on Discord: [1:18 AM] natinusala: Suspend is the action of freezing the process whenever it is out of focus (HOME menu active or sleep) [1:18 AM] natinusala: What kills audio is suspending the process [1:19 AM] natinusala: So as a workaround you use the focus mode where the process isn't suspended when out of focus [1:19 AM] natinusala: And use the applet hook to pause the game when that happens [1:20 AM] natinusala: This is supposedly an issue with libnx, I think they acknowledged it
Has this really been acknowledged as an issue? Shall I open the issue in libnx repo?
It's not an issue with libnx. libnx is not responsible for what users do when calling its functions. Focus mode exists in applet for a reason - to allow applications to perform any necessary cleanup operations during a suspend or exit event - otherwise the system will freeze or kill the application process, which as you see can have unwanted consequences.
But I want the OS to freeze my application on suspend. I just don't understand why that causes threaded audio (e.g. all audio in SDL) to become choppy as soon as the application is unfrozen.
Maybe in SDL, SDL_PauseAudioDevice could be called whenever the app loses/gains focus?
Precisely what I'm trying to say is that it is not possible to do anything to solve the problem as long as the focus mode isn't changed because the OS suspends the application without notifying it. Hence, probably SDL needs to be updated to change the focus mode and add an applet hook to wind down the audio streaming process during suspend; or explore alternative options (such as using audren).
The same happens when pressing the power button to sleep, and pressing the power button again to wake up. Using the power button, the problem happens with applets launched via album, too.