pixijs / sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.
https://pixijs.io/sound/examples/
MIT License
406 stars 68 forks source link

Energy use #129

Open Article19 opened 4 years ago

Article19 commented 4 years ago

I believe I’m noticing different amounts of energy use (as measured by the Activity Monitor in OSX) in different scenarios. In particular, when I pause a game (stop all rendering and tickers) if I issue a PIXI.sound.pauseAll() I see a MUCH lower average energy impact than if I only pause the 1 or 2 sounds that are playing at that moment. Is there some background process running that pauseAll interrupts?

andrewstart commented 4 years ago

pauseAll() suspends the WebAudio audio context, so the browser stops whatever processing it normally does for the context.

Article19 commented 4 years ago

Understood. As an accompanying concern, are any of the built-in PIXI tickers being used? We often fiddle with the FPS of some of these, and completely stop others. Haven't run into any issues with sound yet, but wouldn't want to find something out the hard way. In our experience, high ticker rates results in more cpu use.

andrewstart commented 4 years ago

Each playing audio instance will attach a listener to Ticker.shared for an update method. Reducing the fps of that ticker will have two effects:

  1. Reduce how many "progress" events it emits (one per tick, if the sound is playing).
  2. Reduce the accuracy of unpausing audio, as playback progress is calculated during this update method. This matters if pausing is done outside of the update loop, which I would imagine would generally be the case.

That said, the actual cpu usage of the update method depends on the number of sounds playing and due to the small amount of basic math should pale in the comparison to usage due to rendering.