Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Pausing/closing audio repeats the buffer in Chromium indefinitely #69

Closed
dos1 opened this issue Jan 10, 2019 · 9 comments · Fixed by #140
Closed

Pausing/closing audio repeats the buffer in Chromium indefinitely #69

dos1 opened this issue Jan 10, 2019 · 9 comments · Fixed by #140

Comments

@dos1
Copy link
Contributor

dos1 commented Jan 10, 2019

When using SDL_PauseAudioDevice or SDL_CloseAudioDevice, the sound doesn't stop in Chromium - instead, the last buffer contents seems to be repeated indefinitely (remember the bluescreens in Windows 9x? ;)).

Works as expected in Firefox.

Tested with Emscripten 1.38.21.

@dos1
Copy link
Contributor Author

dos1 commented Jan 10, 2019

Just noticed that bc41280 isn't included in a release yet. Not sure if it's really it, as pausing seems to be also affected, but it might be. Is there some easy way to use a HEAD version of the port?

@dos1
Copy link
Contributor Author

dos1 commented Jan 10, 2019

Looking at the code, I don't see any support for actually pausing the AudioContext (https://webaudio.github.io/web-audio-api/#dom-audiocontext-suspend) - might be a good thing to actually add to reduce CPU and power usage when audio device is paused.

@kripken
Copy link
Member

kripken commented Jan 11, 2019

You can edit tools/ports/sdl.py and change the tag to any branch, so e.g. master instead of version_15, for testing.

@dos1
Copy link
Contributor Author

dos1 commented Jan 11, 2019

Thanks!

...but nope, doesn't help.

@Daft-Freak
Copy link
Member

Do you have a example to test with?

@infval
Copy link

infval commented Apr 22, 2019

I have similar issue when switching tabs or minimizing Chrome. My fix:

window.addEventListener("blur", function() {
  pauseAudio(1);
}, false);
window.addEventListener("focus", function() {
  pauseAudio(0);
}, false);

// FIX (Chrome, ...?), project.js -> ASM_CONSTS
// https://github.com/emscripten-ports/SDL2/blob/master/src/audio/emscripten/SDL_emscriptenaudio.c
function pauseAudio(on) {
  if (typeof Module === 'undefined'
    || typeof Module.SDL2 === 'undefined'
    || typeof Module.SDL2.audio === 'undefined'
    || typeof Module.SDL2.audioContext === 'undefined')
    return;
  if (on) {
    Module.SDL2.audio.scriptProcessorNode.disconnect();
  }
  else {
    Module.SDL2.audio.scriptProcessorNode['connect'](Module.SDL2.audioContext['destination']);
  }
}

.c file:

case SDL_WINDOWEVENT_FOCUS_LOST:
    SDL_PauseAudio(1);
    break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
    SDL_PauseAudio(0);
    break;

@avivbeeri
Copy link

This workaround does the job... but it would be nice if it wasn't necessary. Any chance of this being fixed some time soon?

@Daft-Freak
Copy link
Member

Might just be a case of filling the buffer with 0s in the if(!enabled || paused) branch... but I need to find something using audio to test with.

@atomheartother
Copy link

atomheartother commented Mar 28, 2021

Is there any kind of workaround to the problem mentioned in the OP? This is still happening on Chrome. Worse, the device keeps looping the buffer but the audioCallback function is not called, so I can't even fill the buffer with 0s when I want to silence the audio device.

My only option would be to completely forget about pausing the device and instead have it continually play, simply silencing it by filling it with 0s, but that means making my entire program less efficient & consuming more power to accomodate a Chrome-specific bug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants