module

PointClickEngine::Audio::SpatialAudio

Utility module for spatial audio calculations

Class methods

calculate_distance(pos1 : RL::Vector2, pos2 : RL::Vector2) : Float32

Calculate distance between two 2D points

Source
calculate_pan(source_pos : RL::Vector2, listener_pos : RL::Vector2, pan_width : Float32 = 400.0_f32) : Float32

Calculate stereo panning based on horizontal position Returns a value between -1.0 (full left) and 1.0 (full right)

  • source_pos: Position of the sound source
  • listener_pos: Position of the listener
  • pan_width: Horizontal distance at which full panning occurs
Source
calculate_spatial_params(source_pos : RL::Vector2, listener_pos : RL::Vector2, max_distance : Float32 = 500.0_f32, pan_width : Float32 = 400.0_f32, falloff : Float32 = 1.0_f32) : NamedTuple(volume: Float32, pan: Float32)

Calculate both volume and pan for a sound source Returns a named tuple with :volume and :pan

Source
calculate_volume_factor(source_pos : RL::Vector2, listener_pos : RL::Vector2, max_distance : Float32, falloff : Float32 = 1.0_f32) : Float32

Calculate volume factor based on distance Returns a value between 0.0 (out of range) and 1.0 (at listener position)

  • source_pos: Position of the sound source
  • listener_pos: Position of the listener (usually player/camera)
  • max_distance: Maximum distance at which sound is audible
  • falloff: How quickly sound fades (1.0 = linear, >1 = faster falloff)
Source
in_range?(source_pos : RL::Vector2, listener_pos : RL::Vector2, max_distance : Float32) : Bool

Check if a position is within audible range

Source