Skip to main content

Crate cranpose_audio

Crate cranpose_audio 

Source
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

ThreadWork
UIdecode, 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 ndk crate (aaudio feature, on by default). No Java glue and no C++ toolchain.
  • Desktop: cpal (cpal-backend feature, 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§

AudioEngine
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. false means install registers an engine that will report AudioError::Unsupported.
install
Creates an engine and installs it as the platform audio player.