Skip to content

Engine → Audio

spatialisation.h

Listener and spatial maths. Pure functions, callable from any thread; the engine runs them on the main thread once per spatial voice per frame and sends the results to the mixer as commands.

Structs

File Description
attenuation_params Distance attenuation of one voice.
listener_state The one listener. Defaults: origin, forward -Z, up +Y, no velocity, gain 1.
spatial_result What the mixer needs for a spatial voice.

Functions

Public

clamp_attenuation

[[nodiscard]] CONJURE_API attenuation_params clamp_attenuation(
    const attenuation_params &params) noexcept;

Clamp rules: minDistance >= 0.01, maxDistance >= minDistance, rolloff [0, 10]; NaN becomes the default.

clamp_listener

[[nodiscard]] CONJURE_API listener_state clamp_listener(
    const listener_state &listener) noexcept;

Sanitises a listener: non-finite components become the defaults, forward and up are normalised (and up made perpendicular to forward), gain clamped to [0, 2].

compute_attenuation

[[nodiscard]] CONJURE_API f32 compute_attenuation(
    const attenuation_params &params,
    f32 distance) noexcept;

Gain in [0, 1] for a distance, with d = clamp(distance, minDistance, maxDistance): INVERSE min / (min + rolloff * (d - min)), LINEAR 1 - rolloff * (d - min) / (max - min) clamped to [0, 1], EXPONENTIAL (d / min) ^ -rolloff, NONE 1.

compute_doppler_ratio

[[nodiscard]] CONJURE_API f32 compute_doppler_ratio(
    const listener_state &listener,
    math::vec3 sourcePosition,
    math::vec3 sourceVelocity,
    f32 dopplerFactor,
    f32 speedOfSound) noexcept;

Doppler pitch ratio ((c - v_listener. dir) / (c - v_source. dir)) ^ dopplerFactor, clamped to [0.5, 2]; 1 when dopplerFactor is 0 or the source is at the listener.

compute_pan

[[nodiscard]] CONJURE_API f32 compute_pan(
    const listener_state &listener,
    math::vec3 sourcePosition) noexcept;

Stereo pan in [-1, 1]: the listener-right component of the normalised direction to the source (+1 right, -1 left, 0 ahead, behind or coincident).

compute_spatial

[[nodiscard]] CONJURE_API spatial_result compute_spatial(
    const listener_state &listener,
    math::vec3 sourcePosition,
    math::vec3 sourceVelocity,
    const attenuation_params &params,
    f32 dopplerFactor,
    f32 speedOfSound) noexcept;

Attenuation, pan and Doppler ratio of a source relative to the listener in one call.