Expand description
The real-time audio engine behind cranpose_services::audio.
cranpose-services defines the Compose-shaped API — [AudioPlayer], the
[SoundId] handle, ProvideAudio, rememberSoundBank — and ships a no-op
default. This crate is the implementation an app installs when it wants
sound: a software mixer on the platform’s real-time thread, fed through a
lock-free queue from the UI thread.
// Once, at startup, before the first composition.
cranpose_audio::install();§What runs where
| Thread | Work |
|---|---|
| UI | decode, clip and voice handle bookkeeping, one queue push per call |
| Audio (real-time) | drain the queue, resample, mix, clamp |
The audio callback allocates nothing, locks nothing and logs nothing. Clips
reach it as Arc<[f32]> inside a command; clips it drops travel back over a
second queue so the deallocation happens on the UI thread.
§When the device is open
Only while there is sound to make. The output device opens on the first
play, not on
install and not on
load_clip — a clip load is a
queue push, and the queue exists before any mixer does — and the mixer gives
the stream up again once nothing has sounded for a couple of seconds. A
silent screen therefore costs no audio thread and no output route, whether
it is the first screen or one reached after an hour of play.
§Devices
- Android and Wear OS: AAudio through the
ndkcrate (aaudiofeature, on by default). No Java glue and no C++ toolchain. - Desktop:
cpal(cpal-backendfeature, off by default because it links a system audio library). - Anything else: [
AudioError::Unsupported], and the service falls back to the no-op player so the app still runs.
Structs§
- Audio
Engine - A mixing audio player backed by a platform output device.
Constants§
- MAX_
CLIPS - How many clips the engine holds at once. One byte of index, and far more than the couple of dozen cues a game keeps resident.
- MAX_
VOICES - How many voices can sound simultaneously. Beyond this the oldest one-shot is stolen, which is what a listener expects when a cue storm arrives.
Functions§
- create
- Creates an engine without registering it, for an app that wants to hold the handle itself.
- has_
device_ backend - Whether this build has a real output device compiled in.
falsemeansinstallregisters an engine that will reportAudioError::Unsupported. - install
- Creates an engine and installs it as the platform audio player.