switchbrew / nx-hbloader

Host process for loading Switch homebrew NROs
ISC License
339 stars 72 forks source link

Pressing home or power twice causes apps to become slow with choppy sound #15

Closed rsn8887 closed 5 years ago

rsn8887 commented 5 years ago

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.

fincs commented 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.

rsn8887 commented 5 years ago

you might be right all apps it happens with seem to be using SDL, including nx quake I wasn’t aware.

yellows8 commented 5 years ago

Can you try non-SDL apps for this?

rsn8887 commented 5 years ago

I tried Retroarch and it doesn’t show the issue

yellows8 commented 5 years ago

RA has handling for this.

rsn8887 commented 5 years ago

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.

yellows8 commented 5 years ago

Not sure if using audren instead would help.

yellows8 commented 5 years ago

Try the audio examples from switch-examples.

rsn8887 commented 5 years ago

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.

yellows8 commented 5 years ago

"Do they use threaded audio though?" No, see source.

rsn8887 commented 5 years ago

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?

fincs commented 5 years ago

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.

rsn8887 commented 5 years ago

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?

fincs commented 5 years ago

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).