simvx.core.audio_backend

Miniaudio-based audio backend for SimVX.

Provides MiniaudioBackend — a real-time audio mixer that plays decoded PCM via miniaudio.PlaybackDevice. Each active sound is tracked as a _Channel with its own gain, pan, pitch, loop flag, and cursor. The device callback mixes all active channels into a single interleaved S16 output buffer every audio period.

Duck-typed interface consumed by AudioStreamPlayer, AudioStreamPlayer2D, and AudioStreamPlayer3D.

Module Contents

Classes

MiniaudioBackend

Real-time audio mixer using miniaudio’s PlaybackDevice.

Data

API

simvx.core.audio_backend.log[source]

‘getLogger(…)’

simvx.core.audio_backend.__all__

[‘MiniaudioBackend’]

class simvx.core.audio_backend.MiniaudioBackend(sample_rate: int = _SAMPLE_RATE, nchannels: int = _NCHANNELS)[source]

Real-time audio mixer using miniaudio’s PlaybackDevice.

The backend owns a single playback device that runs a callback on a dedicated audio thread. All public methods are thread-safe — they mutate _channels under a lock while the audio thread reads from it.

Initialization

play_audio(stream: simvx.core.audio.AudioStream, *, volume_db: float = 0.0, pitch: float = 1.0, loop: bool = False, bus: str = 'master') int | None[source]

Decode and play an audio stream. Returns a channel ID.

play_audio_2d(stream: simvx.core.audio.AudioStream, *, position: Any = None, volume_db: float = 0.0, pitch: float = 1.0, loop: bool = False, bus: str = 'sfx', max_distance: float = 2000.0) int | None[source]

Play a 2D-positioned sound. Spatialization is updated per-frame via update_audio_2d.

play_audio_3d(stream: simvx.core.audio.AudioStream, *, position: Any = None, volume_db: float = 0.0, pitch: float = 1.0, loop: bool = False, bus: str = 'sfx', max_distance: float = 100.0) int | None[source]

Play a 3D-positioned sound. Spatialization is updated per-frame via update_audio_3d.

stop_audio(channel_id: int) None[source]

Stop a playing channel.

pause_audio(channel_id: int) None[source]

Pause a playing channel.

resume_audio(channel_id: int) None[source]

Resume a paused channel.

update_audio_2d(channel_id: int, volume_db: float, pan: float) None[source]

Update volume and pan for a 2D channel (called each frame).

update_audio_3d(channel_id: int, volume_db: float, pan: float, pitch: float) None[source]

Update volume, pan, and pitch for a 3D channel (called each frame).

get_playback_position(channel_id: int) float[source]

Return current playback position in seconds.

open_stream(*, volume_db: float = 0.0, pitch: float = 1.0, bus: str = 'master') int[source]

Open a streaming channel that accepts raw PCM chunks via feed_audio_chunk.

feed_audio_chunk(channel_id: int, chunk: bytes) None[source]

Append raw PCM bytes to a streaming channel’s buffer.

shutdown() None[source]

Stop the playback device and release resources.