audio.py

Audio Manager for LunaEngine - Named channels, curves, device selection, event system

class AudioEvent

Description

Audio events emitted by the audio system or channels.

Attributes
PLAYBACK_STARTED: Any = auto()
PLAYBACK_STOPPED: Any = auto()
PLAYBACK_PAUSED: Any = auto()
PLAYBACK_RESUMED: Any = auto()
PLAYBACK_COMPLETED: Any = auto()
FADE_COMPLETE: Any = auto()
LOOP: Any = auto()
CURVE_FINISHED: Any = auto()
ERROR: Any = auto()
Methods

No methods defined.

class AudioState

Description

No documentation

Attributes
STOPPED: Any = 'stopped'
PLAYING: Any = 'playing'
PAUSED: Any = 'paused'
Methods

No methods defined.

class SoundData

Description

Metadata and buffer reference for a loaded sound.

Methods
def __init__(self: Any, name: str, filepath: str, category: str = 'sfx') -> Any
No documentation
def get_buffer(self: Any, backend: OpenALBackend) -> Optional[OpenALBuffer]
Get or create the OpenAL buffer for this sound.

class AudioCurve

Description

Keyframe-based animation for a single audio property (volume, pitch, pan, balance).

Methods
def __init__(self: Any, property_name: str, keyframes: List[Tuple[float, float]], interpolation: str = 'linear', loop: bool = False) -> Any
Args:
   property_name: 'volume', 'pitch', 'pan', or 'balance'
   keyframes: list of (time, value) pairs, time in seconds.
   interpolation: 'linear' or 'smoothstep'
   loop: if True, restart animation when finished.
def evaluate(self: Any, t: float) -> float
Return interpolated value at time t (0..duration).
def update(self: Any, dt: float) -> bool
Advance animation; returns True if finished (and not looping).
def on_finished(self: Any, callback: Callable) -> Any
No documentation

class AudioChannel

Description

Named audio channel with individual volume, pitch, pan, balance, and curves.
Now supports effects: reverb, echo (via effect slot if EFX available).

Methods
def __init__(self: Any, name: str, manager: 'AudioManager', volume: float = 1.0, pitch: float = 1.0, pan: float = 0.0, balance: float = 0.0, loop: bool = False) -> Any
No documentation
def _get_source(self: Any) -> Optional[OpenALSource]
Get a free OpenAL source, reusing the current one if still playing.
def _emit_event(self: Any, event: AudioEvent, **kwargs: dict) -> Any
No documentation
def on_event(self: Any, event: AudioEvent, callback: Callable) -> Any
Register a callback for a specific event.
def _apply_effects(self: Any) -> Any
Apply all active effects to the source if EFX available.
def set_reverb(self: Any, amount: float) -> Any
No documentation
def set_echo(self: Any, amount: float) -> Any
No documentation
def set_chorus(self: Any, amount: float) -> Any
No documentation
def set_flanger(self: Any, amount: float) -> Any
No documentation
def set_distortion(self: Any, amount: float) -> Any
No documentation
def set_pitch_shift(self: Any, semitones: float) -> Any
Shift pitch by semitones (positive = higher pitch).
def play(self: Any, sound_name: str, loop: bool = False, fade_in: float = 0.0, curve: Optional[AudioCurve] = None) -> bool
Play a sound on this channel.
Returns True if playback started successfully.
def stop(self: Any) -> Any
No documentation
def pause(self: Any) -> Any
No documentation
def resume(self: Any) -> Any
No documentation
def set_volume(self: Any, volume: float, duration: float = 0.0, curve_type: str = 'linear') -> Any
Set target volume, optionally with a smooth transition.
def set_pitch(self: Any, pitch: float, duration: float = 0.0, curve_type: str = 'linear') -> Any
No documentation
def set_balance(self: Any, balance: float, duration: float = 0.0, curve_type: str = 'linear') -> Any
No documentation
def set_pan(self: Any, pan: float, duration: float = 0.0, curve_type: str = 'linear') -> Any
No documentation
def apply_curve(self: Any, curve: AudioCurve) -> Any
Apply a curve to this channel.
def update(self: Any, dt: float) -> Any
Update active curves and emit completion events.
def is_playing(self: Any) -> bool
No documentation
def is_paused(self: Any) -> bool
No documentation
def get_position(self: Any) -> float
No documentation

class AudioManager

Description

Main audio manager with named channels, curves, device selection, and event system.
Now includes master volume control and global effect toggles.

Methods
def __init__(self: Any, max_sources: int = 32, device_name: Optional[str] = None) -> Any
No documentation
def _emit_event(self: Any, event: AudioEvent, **kwargs: dict) -> Any
No documentation
def on_event(self: Any, event: AudioEvent, callback: Callable) -> Any
Register a global audio event handler.
def set_master_volume(self: Any, volume: float) -> Any
Set master volume (0.0 - 1.0).
def set_global_reverb(self: Any, amount: float) -> Any
No documentation
def set_global_echo(self: Any, amount: float) -> Any
No documentation
def set_global_chorus(self: Any, amount: float) -> Any
No documentation
def set_global_flanger(self: Any, amount: float) -> Any
No documentation
def set_global_distortion(self: Any, amount: float) -> Any
No documentation
def set_global_pitch_shift(self: Any, semitones: float) -> Any
No documentation
def list_devices(self: Any) -> List[str]
No documentation
def set_device(self: Any, device_name: str) -> bool
No documentation
def create_channel(self: Any, name: str, **kwargs: dict) -> AudioChannel
No documentation
def get_channel(self: Any, name: str) -> Optional[AudioChannel]
No documentation
def load_sound(self: Any, name: str, filepath: str, category: str = 'sfx', force_mono: bool = False, force_8bit: bool = False) -> bool
No documentation
def play(self: Any, sound_name: str, channel: Optional[Union[str, int]] = None, volume: float = 1.0, pitch: float = 1.0, pan: float = 0.0, balance: float = 0.0, loop: bool = False, fade_in: float = 0.0, curve: Optional[AudioCurve] = None, reverb: float = 0.0, echo: float = 0.0, chorus: float = 0.0, flanger: float = 0.0, distortion: float = 0.0, pitch_shift: float = 0.0) -> Optional[AudioChannel]
No documentation
def play_music(self: Any, sound_name: str, volume: float = 0.8, pitch: float = 1.0, loop: bool = True, fade_in: float = 0.0, curve: Optional[AudioCurve] = None, reverb: float = 0.0, echo: float = 0.0, chorus: float = 0.0, flanger: float = 0.0, distortion: float = 0.0, pitch_shift: float = 0.0) -> Optional[AudioChannel]
No documentation
def stop_all(self: Any) -> Any
No documentation
def update(self: Any, dt: float) -> Any
No documentation
def cleanup(self: Any) -> Any
No documentation
Back to Core Module