Skip to main content

Module mix

Module mix 

Source
Expand description

The mixer: everything playing, added up into one block of samples, in whole numbers, so the same script gives the same samples on every target.

  • Volumes and balance are u16s in 1/4096 (UNITY is full), the sum is in i32, and the result clamps to i16.
  • A rate is 16.16 (RATE_ONE is as recorded). A sound’s own rate and this rate make one exact step, and frames between are linearly interpolated.
  • Mixer::render takes no lock, allocates nothing, frees nothing, and does no decoder work or I/O, so a system’s audio callback can call it. All the memory is taken in Mixer::new.
  • A voice is never stopped to make room for another: with every voice busy, Mixer::play says Full. Which sound loses is the caller’s to decide, before it gets here.

A sound is decoded whole and held by the bank (Mixer::add_sound), and voices name it by SoundId. A stream is a Source that has its frames ready; a worker decodes ahead into a stream::feed, whose module says what the two ends promise each other. queue is how another thread commands a mixer.

Modules§

queue
Commands from another thread: a fixed ring of plain data, one writer and one reader, with no lock, no allocation and no unsafe.
stream
Streams: what a worker hands the mixer, and what a voice reads it through.

Structs§

Config
What a mixer is made with. All its memory comes from these.
Full
Every voice is busy, or the bank or the queue has no room. Nothing was stopped to make any.
Mixer
The mix (module docs).
Params
How a voice starts.
Region
Part of a source, in frames: start up to, not including, end. It plays what comes before it once, then goes round it with no gap.
SoundId
A sound of a mixer’s bank.
StreamId
A stream waiting in a mixer to be played.
VoiceId
A playing sound. Once it has ended the id means nothing: an operation on it does nothing, even when its voice is playing something else by then.

Constants§

RATE_MAX
The fastest rate: what a block costs stays bounded.
RATE_MIN
The slowest rate: a voice always ends, or comes round, in a bounded time.
RATE_ONE
As recorded, in 16.16.
UNITY
Full volume, and an even balance, in 1/4096.

Type Aliases§

SharedPcm
A sound many voices can hold.