Audio stacking and build up volume (crackling audio)

Hello everyone,

I noticed a problem with the audio in mz, as I'm using an abs system it often happens to have a lot of "se"
at the same time (monster noise, impact animation), and when multiples sounds are played at the same time
the volume adds up, sometimes very loud to the point of crashing audio (and coming back when action is finished)

I didn't noticed the audio crash was this bad before because I playtested at low volume (20% se me and bgs with no bgm)
but when everything is 100% it pretty bad to the point of crackling audio to no audio for 1sec..

Is it a know issue ? is there a way to have some kind of limiter to prevent audio from stacking on itself ?

Thanks again !
Sounds are waves, when you stack waves on top of each other they amplify at the peaks. The solution is to manage the volume going in (by reducing the volume of ones you notice are playing too frequently, or reducing how frequently they play if possible), and trying to prevent too much stacking where you can.

I don't know if there's any plugins that add a real time limiter, that would probably be pretty resource intensive.
Core MZ implements a very basic safety measure: it prevents playing multiple copies of the same SE in the same frame. But that doesn't prevent the same SE from playing a new instance every single frame, or (I assume this is what you're seeing) stacking volumes from different SEs.

Typically you'd work around that by implementing limits in your audio-emitting system. However, for a plugin that would require code edits (perhaps a lot of edits, depending on the situation).

As a generic solution, you could try applying a dynamic range compressor to the game's output audio. Thanks to the WebAudio API, that's relatively easy to do. Something like this may work:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Apply dynamic range compression to the game's audio.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/169565/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {

  /**
   * Compressor settings.
   * https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode
   */
  const OPTS = {
    attack:     0.003,
    release:    0.2,
    ratio:      20,
    threshold: -25,
    knee:       30
  };

  // Patch - add compressor between master gain and destination.
  const alias = WebAudio._createMasterGainNode;
  WebAudio._createMasterGainNode = function() {
    alias.apply(this, arguments);
    if (this._masterGainNode) {
      const ctx = this._context;
      const d = ctx.destination;
      const c = this._compressorNode
              = new DynamicsCompressorNode(ctx, OPTS);
      this._masterGainNode.disconnect(d);
      this._masterGainNode.connect(c);
      c.connect(d)
    }
  };

})();
You may want to adjust the OPTS values.

Alternatively you could check out feature Q16 of my plugin Cae_Tweaks: it's basically the same, except it can be toggled on/off via an in-game option.
Thanks a lot for the help I didn't know how it worked but this is perfect,
gonna tweak it so the bgm doesn't get quit as loud as it is with this but no more cracking audio It just lower the volume when a lot happens

Thank you again for the help and information !

Edit:
Also is there a way to lower the maximum volume of the game (without controls of it in the options for the player) to limit the use of the compression effect ?

I tried different settings and I think I might help to limit the volume of my game with this compression option enable in case it goes to loud sometimes
Great, you're welcome! 👋

Also is there a way to lower the maximum volume of the game (without controls of it in the options for the player) to limit the use of the compression effect ?
Check out TUR_DevMasterVolume.js, posted here:
Or, if you change your mind about an in-game master volume option:
Note that, regardless of your players' hearing and their speaker setup/capability, the audio may also be processed after it leaves the game, e.g.
  • Physical controls on speaker hardware;
  • The OS volume mixer;
  • Audio drivers, third-party software (noise-gating, dynamic range control, etc).
For example, this range compression doesn't increase the volume of quiet sounds...but you noticed the BGM got louder with it enabled. I'm guessing your audio driver has some kind of enhancement to boost the volume of quiet sounds.
Great, you're welcome! 👋


Check out TUR_DevMasterVolume.js, posted here:
Or, if you change your mind about an in-game master volume option:
Note that, regardless of your players' hearing and their speaker setup/capability, the audio may also be processed after it leaves the game, e.g.
  • Physical controls on speaker hardware;
  • The OS volume mixer;
  • Audio drivers, third-party software (noise-gating, dynamic range control, etc).
For example, this range compression doesn't increase the volume of quiet sounds...but you noticed the BGM got louder with it enabled. I'm guessing your audio driver has some kind of enhancement to boost the volume of quiet sounds.

TUR_DevMasterVolume.js did the job perfectly thanks !

I already have a master volume control in the player options but It was more to contain the overall
volume of the game and minimize the use of compression
With both your plugin and this, problem solved

Thanks again for your time and help

Original thread: https://forums.rpgmakerweb.com/threads/audio-stacking-and-build-up-volume-crackling-audio.169565/