melonJS
    Preparing search index...

    Function noise

    • Fire a single-shot envelope-shaped noise burst on the shared getAudioContext context. Sits alongside tone as the non-pitched half of the procedural-audio surface — tone is the right tool for anything with a clear pitch (clicks, chimes, lasers), noise is the right tool for anything percussive without one (explosions, hi-hats, swooshes, footsteps, wind).

      The output runs through the master gain shared with file-based playback, so muteAll / setVolume apply uniformly. Browser autoplay gating applies — the first call after a user gesture lets every subsequent call play.

      Requires WebAudio. When WebAudio is not supported (or audio is explicitly disabled) this is a silent no-op: getAudioContext returns null and nothing is scheduled.

      Parameters

      • opts: NoiseOptions

        the NoiseOptions (duration, spectral colour, envelope, pan, optional filter + sweep). See the interface for per-field defaults.

      Returns void

      // Explosion: brown rumble closing into a thud
      me.audio.noise({
      duration: 0.8,
      type: "brown",
      gain: 0.4,
      filter: { type: "lowpass", frequency: 800 },
      filterSweep: 0.3,
      });
      // Hi-hat: short, bright, top-end only
      me.audio.noise({
      duration: 0.05,
      filter: { type: "highpass", frequency: 7000 },
      gain: 0.2,
      });
      // Swoosh: bandpass white with rising sweep — UI transition, melee whoosh
      me.audio.noise({
      duration: 0.3,
      filter: { type: "bandpass", frequency: 400, Q: 1.5 },
      filterSweep: 4,
      gain: 0.3,
      });
      // Wind / breath: long, low-pink, no sweep
      me.audio.noise({
      duration: 2,
      type: "pink",
      filter: { type: "bandpass", frequency: 600 },
      gain: 0.08,
      });
      // Footstep on dirt — short brown thump
      me.audio.noise({
      duration: 0.08,
      type: "brown",
      filter: { type: "lowpass", frequency: 200 },
      gain: 0.25,
      });