Skip to main content

Module spatial

Module spatial 

Source
Expand description

Point-source 3D placement, horizontal speaker layouts and an explicit stereo fold. Coordinates are right-handed: +X right, +Y up, default forward -Z. Positions and distances use the same units; velocities and sound speed use units/second. Velocity controls Doppler only: the host supplies updated positions explicitly.

Surround speaker directions are horizontal: quad +/-45 and +/-135 degrees; 5.1 front +/-30, centre 0, surrounds +/-110; 7.1 adds sides +/-90 and backs +/-150. Angles are clockwise from forward. Elevation affects distance and Doppler; a directly vertical/coincident emitter uses the front direction. There is no HRTF, geometric occlusion, propagation delay or bass management.

Let d=clamp(distance,min,max) and r=rolloff. Linear gain is clamp(1-r*(d-min)/(max-min),0,1), inverse is min/(min+r*(d-min)), exponential is (d/min)^(-r). These follow the clamped models in the OpenAL specification. Max distance clamps evaluation, not voice lifetime; inverse/exponential retain a floor. The independent existing Space2d model keeps its previous behavior.

Doppler uses the listener-to-emitter unit vector n and ratio (c+factordot(listener_velocity,n))/(c+factordot(emitter_velocity,n)). Scaled radial velocities clamp to +/-0.9c and the ratio to 0.25..=4; a coincident source has ratio 1. The final ratepitchDoppler playback speed clamps to 1/1024..=512, preserving the mixer’s existing fixed-point/resampler bound.

Directional gains have unit power and are renormalized during ramps. Distance remains a separate ramp used by quietest-voice policy. Listener/emitter targets apply in command sequence order, using the listener then current; spatial clocks freeze with their voice/bus. Legacy voices route to the front pair on surround output. Effects process every channel, compressors/limiters link all channels, and modulation phase offsets repeat according to channel index. Channel order/masks follow WAVEFORMATEXTENSIBLE.

Structs§

Attenuation
Clamped distance models: below min gain is one; beyond max distance is clamped to max. Inverse/exponential therefore retain a nonzero floor. Rolloff zero disables attenuation. Equations are documented in the module README/reference.
Emitter
A mono point emitter. Stereo inputs collapse to (L+R)/2, which can cancel antiphase content. Non-spatial voices retain their usual stereo image.
Listener
Listener pose. Orientation axes need not be unit or exactly perpendicular; preparation orthonormalizes them. Zero/near-parallel axes are rejected.
Placement
Normalized direction gains plus independent attenuation and playback ratio.
SpatialConfig

Enums§

DistanceModel
OutputLayout
Interleaved WAVE speaker order. LFE receives no point-source signal.

Constants§

MAX_OUTPUT_CHANNELS