simvx.core._audio_stream¶
Audio stream/data layer: :class:AudioStream resource + container detection.
Private leaf module behind the :mod:simvx.core.audio facade. Holds the
audio data concerns: the :class:AudioStream resource handle, the
header-probe container detection helpers, the WAV data chunk seek
helper, and the sample-rate/channel constants and type aliases that belong
to this layer. The playback mixin and the player nodes live in sibling
_audio_playback / _audio_players modules.
Module Contents¶
Classes¶
Audio resource (WAV/OGG file or synthetic PCM). |
Data¶
API¶
- simvx.core._audio_stream.AudioSource¶
None
- simvx.core._audio_stream.AudioContainer¶
None
- simvx.core._audio_stream.log¶
‘getLogger(…)’
- class simvx.core._audio_stream.AudioStream(source: simvx.core._audio_stream.AudioSource)[source]¶
Audio resource (WAV/OGG file or synthetic PCM).
This is a lightweight handle to audio data. Actual decoding is deferred to the backend (miniaudio, SDL3, web audio).
Accepts any of:
- class:
str/ :class:os.PathLike– a filesystem audio file.
- class:
~simvx.core.Resource– audio inside a Python package.
- class:
importlib.resources.abc.Traversable– the raw return ofimportlib.resources.files(pkg) / name.
Use :meth:
tonefor procedural sine-wave tones and :meth:from_pcmto wrap pre-rendered PCM data.Attributes: source: Original spec the stream was constructed from – a string, :class:
pathlib.Path, :class:Resource, or :class:Traversable. Preserved verbatim so scene serialisation can round-trip it. path: Resolved filesystem path string used by the backend (empty string for synthetic streams that have no file). backend_data: Backend-specific audio data (PCM ndarray, channel id, etc). Set automatically when decoded; may also be set by :meth:from_pcm/ :meth:tone. container: Detected container format – one of"wav","ogg","mp3","flac","pcm"(synthetic) or"unknown". Probed from the file header at construction time; the streaming open path uses it to pick the right decoder.Initialization
- __slots__¶
(‘source’, ‘_path’, ‘backend_data’, ‘sample_rate’, ‘channels’, ‘_container’)
- property path: str[source]¶
Resolved filesystem path string used by the backend.
Synthetic streams (from_pcm / tone / empty) carry their assigned
namehere. The dual-field design (separatesource+pathslots both holding the same string for synthetic streams) was collapsed during the audio refactor;pathis now a derived attribute backed by_path.
- property container: simvx.core._audio_stream.AudioContainer[source]¶
Detected container format. See :data:
AudioContainerfor the value set.
- classmethod tone(freq_hz: float, *, duration: float = 1.0, volume: float = 0.3, sample_rate: int = _SAMPLE_RATE) simvx.core._audio_stream.AudioStream[source]¶
Generate a sine-wave tone at freq_hz with a short fade-in/out.
The resulting stream has its PCM data baked into
backend_dataso the audio backend skips file decoding entirely.
- classmethod from_pcm(samples: numpy.ndarray, *, sample_rate: int, channels: int, name: str = 'pcm') simvx.core._audio_stream.AudioStream[source]¶
Wrap a pre-rendered PCM buffer as an AudioStream.
Args: samples: float32 ndarray. For stereo, interleaved (channels first within each frame); for mono, a 1-D array. sample_rate: PCM sample rate in Hz. Required: playing a 44.1 kHz buffer on a 48 kHz backend produces wrong-pitch audio if this is omitted. channels: 1 (mono) or 2 (stereo). Required for the same reason: a mono buffer played as stereo gives left-channel-only sound. name: Descriptive label used in :meth:
__repr__and as the stream’spath. The backend ignores it whenbackend_datais set.Raises: InvalidStreamError:
sample_rate <= 0orchannelsis not 1 or 2. TypeError:samplesisn’t a numpy ndarray.
- classmethod empty(*, name: str = 'empty') simvx.core._audio_stream.AudioStream[source]¶
Return a synthetic stream with no audio data.
Used internally by :meth:
AudioSynth.bake(before it overwrites the synthetic frame buffer) and by null-backend tests that need a placeholder stream object without touching the filesystem. The returned stream carriescontainer="pcm"andbackend_data=None: playing it through a real backend is undefined.Replaces the legacy
AudioStream("")sentinel.