mwg API
    Preparing search index...

    Function audioGain

    • The gain a listener at distance hears a source at, clamped to [0, 1]: 1 at or inside refDistance, 0 at or beyond maxDistance, an inverse-distance curve between them.

      Parameters

      Returns number

      import { audioGain } from '@datamoc/mw_games/audio';

      audioGain(0, { refDistance: 2 }); // 1 - inside the full-volume radius
      audioGain(2, { refDistance: 2 }); // 1 - the reference distance itself
      audioGain(4, { refDistance: 2 }); // 0.5 - one doubling away
      audioGain(4, { refDistance: 2, maxDistance: 4 }); // 0 - at the edge of hearing