In development. It changes without notice.
Topic
Sound: Catalog, Renderers & Speaker
The sounds as data, the two renderers that turn one into what a board plays, and the task that plays it.
The sounds are one family: a click for a key, wood for what the owner did, a bell for how it ended, a closed note for a refusal, where up means forward or yes and down means back or no. The catalog states each one twice, because the boards have two kinds of sound hardware:
| Rendition | Renderer | What it makes |
|---|---|---|
| Notes, for a speaker | hal:: | 16 kHz, 16-bit mono frames, a block at a time |
| Steps, for a buzzer | hal:: | Frequency, duty and length of each change of a PWM channel |
Both are integer arithmetic with no hardware behind them, so a computer renders what a board would.
AudioFeedback is what the rest of the firmware calls. On the buzzer boards each cue is played as the catalog writes it. On the speaker boards each cue is a plain tone, and the notes are rendered only on a computer. Sound can be switched off in settings; there is no volume control. A buzzer plays every cue at 25 % of the volume law (sound_
Files | |
| file | src/ |
| Short UI audio cues (entry digits, success/ | |
| file | src/ |
The speaker back-end of AudioFeedback (audio_ | |
| file | src/ |
| Every sound the device makes, as data: what it is for and both of its renditions. | |
| file | src/ |
| The names of the device's sounds and of their classes, and nothing else. | |
| file | src/ |
| The fixed-point tables of the sound synthesizer, built at compile time. | |
| file | src/ |
| Turns a catalog sound into the frequency and duty updates a one-bit buzzer is driven with. | |
| file | src/ |
| Renders a catalog sound into 16 kHz, 16-bit mono PCM, a block at a time. | |
| file | src/ |
| The volume law: what a volume figure does to each rendition of a sound. | |
| file | src/ |
| Variant-agnostic speaker facade for tone playback. | |
| file | src/ |
| The samples one run of tones is streamed as over I2S, block by block. | |
Functions | |
| constexpr Note | kleidos:: |
| A click: a struck tick, bright for a few milliseconds, then a plain tone. | |
| constexpr Note | kleidos:: |
| A wood note: struck, with the octave and the double octave over it while the strike lasts. | |
| constexpr uint16_t | kleidos:: |
| The modulator ratio a bell has at a pitch. | |
| constexpr uint16_t | kleidos:: |
| The modulation index a bell is struck with at a pitch. | |
| constexpr Note | kleidos:: |
| A bell note: glass, with a shimmer that outlasts the strike. | |
| constexpr Note | kleidos:: |
| A soft bell: swelled instead of struck, its shimmer fading with the note. | |
| constexpr Note | kleidos:: |
| A closed note: inharmonic and damped, the timbre of a refusal. | |
| constexpr Step | kleidos:: |
| A buzzer note with a soft start and end. | |
| constexpr Step | kleidos:: |
| A buzzer glide with a soft start and end. | |
| constexpr Step | kleidos:: |
| A buzzer tick: one burst at half of the duty, moving in pitch or not. | |
| constexpr Step | kleidos:: |
| A buzzer rest: the pin low. | |
| constexpr uint16_t | kleidos:: |
| Length of one play of a note list. | |
| constexpr uint16_t | kleidos:: |
| Length of one play of a step list. | |
| constexpr uint16_t | kleidos:: |
| Length of a rendition played several times with a gap between plays. | |
| constexpr uint16_t | kleidos:: |
How long note index really sounds, once the two-voice rule is applied. | |
| constexpr Entry | kleidos:: |
| Builds one catalog row, with its length worked out from its notes. | |
| constexpr const Entry & | kleidos:: |
| The catalog row of a sound. | |
| constexpr const Entry * | kleidos:: |
| Finds a sound by the name the console and the portal use. | |
| constexpr uint16_t | kleidos:: |
| Length of a sound's buzzer rendition. | |
| constexpr uint64_t | kleidos:: |
| Folds one 16-bit value into a 64-bit FNV-1a hash, low byte first. | |
| constexpr uint32_t | kleidos:: |
| Q15 gain of an attenuation. | |
| constexpr uint32_t | kleidos:: |
| Per-frame Q16 decay factor of a time constant. | |
| constexpr int32_t | kleidos:: |
| Sine of a 32-bit phase, in Q15. | |
| constexpr uint32_t | kleidos:: |
| Phase advance per frame of a frequency. | |
| constexpr uint32_t | kleidos:: |
| Peak phase swing of a modulation index, as a fraction of a turn. | |
| Digest | kleidos:: |
| Renders a whole sound to nowhere and reports what came out. | |
| Digest | kleidos:: |
| Renders a whole row to nowhere and reports what came out. | |
| constexpr uint8_t | kleidos:: |
| The law's figure for any requested one. | |
| constexpr uint32_t | kleidos:: |
| I2S: how far below the ceiling a volume plays. | |
| constexpr uint16_t | kleidos:: |
| Buzzer: the duty a full-level step plays at. | |
| bool | kleidos:: |
| Initialize the speaker backend. | |
| void | kleidos:: |
| Set output volume. | |
| bool | kleidos:: |
| Queue a tone for the speaker task. | |
| bool | kleidos:: |
| Play a catalog sound on a buzzer board. | |
| uint32_t | kleidos:: |
| How many tones and sounds the speaker task has played. | |
| StreamStats | kleidos:: |
| How often the I2S streams were cut, started again and lost. | |
| void | kleidos:: |
| Power off the speaker backend. | |
| bool | kleidos:: |
| Drive the speaker amplifier's own gate, where this board has one. | |
| bool | kleidos:: |
| Check whether a working speaker backend is present. | |
| const char * | kleidos:: |
| Compile-time name of the audio codec on this variant, if any. | |
| constexpr uint32_t | kleidos:: |
Frames (mono samples) that play for ms at sampleRateHz. | |
| constexpr uint32_t | kleidos:: |
How long frames play at sampleRateHz, in milliseconds, rounded up. | |
| constexpr ToneStreamPlan | kleidos:: |
| The plan for a channel and an amplifier. | |
Variables | |
| constexpr std::size_t | kleidos:: |
| Most notes one sound has. | |
| constexpr std::size_t | kleidos:: |
| Most buzzer steps one sound has. | |
| constexpr uint16_t | kleidos:: |
| Length of a note's closing linear release, and of the release a stolen note gets. | |
| constexpr std::size_t | kleidos:: |
Notes that sound at once: note n plays on voice n modulo this. | |
| constexpr uint16_t | kleidos:: |
| Longest SoundClass:: | |
| constexpr uint32_t | kleidos:: |
| Center frequency of a buzzer nobody has swept yet, in hertz: a guess to replace per board. | |
| constexpr uint16_t | kleidos:: |
| Shortest buzzer step, in milliseconds: what a task still times on a 1 ms tick. | |
| constexpr uint16_t | kleidos:: |
| How often a buzzer glide or duty ramp is updated, in milliseconds. | |
| constexpr uint16_t | kleidos:: |
| Slices a Envelope:: | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Bits of the fraction of Step:: | |
| constexpr uint16_t | kleidos:: |
| Length of the half-duty tail of a Envelope:: | |
| constexpr uint16_t | kleidos:: |
| Shortest Envelope:: | |
| constexpr std::array< uint16_t, 8 > | kleidos:: |
| Every pitch of the scale, lowest first. | |
| constexpr uint16_t | kleidos:: |
The one pitch off the scale: Lockout ends on a note the scale does not have. | |
| constexpr uint16_t | kleidos:: |
| constexpr std::array< Entry, kSoundCount > | kleidos:: |
| Every sound, in the order of hal::Sound. | |
| constexpr std::size_t | kleidos:: |
| How many sounds hal::Sound names. | |
| constexpr uint32_t | kleidos:: |
| Sample rate of the I2S rendition, in frames per second (16-bit mono). | |
| constexpr uint32_t | kleidos:: |
| Frames in one millisecond at kSampleRateHz. | |
| constexpr std::size_t | kleidos:: |
| Entries of the sine table kSineQ15, which holds one period. | |
| constexpr std::size_t | kleidos:: |
| Entries of the gain table kGainQ15, one per half-decibel from 0 to 63.5 dB. | |
| constexpr std::size_t | kleidos:: |
| Entries of the decay table kDecayCoefQ16, one per millisecond from 0 to 127. | |
| constexpr uint32_t | kleidos:: |
| Full scale of a Q15 gain or envelope: 1.0. | |
| constexpr uint32_t | kleidos:: |
| A Q16 decay coefficient that leaves its state unchanged: a held level. | |
| constexpr uint64_t | kleidos:: |
| Value an empty 64-bit FNV-1a hash starts from. | |
| constexpr uint64_t | kleidos:: |
| Multiplier of 64-bit FNV-1a. | |
| constexpr std::array< uint16_t, kGainTableSize > | kleidos:: |
Q15 gain of an attenuation in half-decibels: entry n is round( 32768 x 10^( -n / 40 ) ). | |
| constexpr std::array< uint16_t, kDecayTableSize > | kleidos:: |
Q16 factor that decays a level by 1/e over a time constant: entry tau, in milliseconds, is round( 65536 x e^( -1 / ( tau x 16 ) ) ). | |
| constexpr std::array< int16_t, kSineTableSize > | kleidos:: |
One period of the sine in Q15: entry i is round( 32767 x sin( 2 pi i / 256 ) ). | |
| constexpr uint64_t | kleidos:: |
| FNV-1a of the gain, decay and sine tables, in that order. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr std::size_t | kleidos:: |
| Frames in the block a sound is streamed in: 8 ms at 16 kHz. | |
| constexpr std::size_t | kleidos:: |
| Notes that can be heard at once: kVoices sounding and one in its release. | |
| constexpr uint8_t | kleidos:: |
| Lowest figure the law takes, in percent. | |
| constexpr uint8_t | kleidos:: |
| Highest figure the law takes, in percent. | |
| constexpr uint8_t | kleidos:: |
| One step of the law, in percent. | |
| constexpr uint8_t | kleidos:: |
| The figure a buzzer plays every cue at, in percent. | |
| constexpr std::size_t | kleidos:: |
| How many figures the law takes: 5, 10 ... 100. | |
| constexpr uint32_t | kleidos:: |
| I2S: attenuation at 0 % against 100 %, in half-decibels (30 dB). | |
| constexpr uint8_t | kleidos:: |
| I2S: level of full volume below digital full scale, in half-decibels (-4 dBFS). | |
| constexpr uint32_t | kleidos:: |
| Buzzer: resolution of the duty the sequencer hands the PWM facade, in bits. | |
| constexpr uint16_t | kleidos:: |
| Buzzer: the highest duty ever asked for, 50 % of the kPwmDutyBits range. | |
| constexpr uint32_t | kleidos:: |
| Buzzer: level at 0 % against 100 %, in tenths of a decibel (18 dB). | |
| constexpr std::array< uint16_t, kVolumeSteps > | kleidos:: |
| Buzzer: the duty of a full-level step at each volume, 5 % first. | |
| constexpr uint32_t | kleidos:: |
Notes of each sound | |
| constexpr std::array | kleidos:: |
KeyTick: a soft, dry "tk". One click on E6, the tick that does not move. | |
| constexpr std::array | kleidos:: |
NavUp: a tick that jumps up a fourth, from E6 to rest on A6. | |
| constexpr std::array | kleidos:: |
NavDown: its mirror, down a fourth to rest on B5. | |
| constexpr std::array | kleidos:: |
| constexpr std::array | kleidos:: |
Select: two wood notes up a fifth, far enough apart for their order to be heard. | |
| constexpr std::array | kleidos:: |
Back: the same two notes down. | |
| constexpr std::array | kleidos:: |
Notice: one small bell. | |
| constexpr std::array | kleidos:: |
SendStart: a rising sweep of a fifth, "off it goes". | |
| constexpr std::array | kleidos:: |
Delete: a wood note that falls a fifth and closes. | |
| constexpr std::array | kleidos:: |
Success: two bright bells, a fourth up; the second rings. | |
| constexpr std::array | kleidos:: |
| constexpr std::array | kleidos:: |
| constexpr std::array | kleidos:: |
| constexpr std::array | kleidos:: |
PinWrong: two closed notes, a minor third down, no ring. | |
| constexpr std::array | kleidos:: |
Warning: the same bell twice, insistent. | |
| constexpr std::array | kleidos:: |
Pairing: a question. Two bells, the second a tone higher and left open. | |
| constexpr std::array | kleidos:: |
LowBattery: two soft bells sinking a fourth, E6 then B5. | |
| constexpr std::array | kleidos:: |
Lockout: three closed notes down, the last one off the scale. | |
Buzzer steps of each sound | |
| constexpr std::array | kleidos:: |
KeyTick: one 4 ms burst at the center. | |
| constexpr std::array | kleidos:: |
NavUp: a short glide up one degree. | |
| constexpr std::array | kleidos:: |
NavDown: a short glide down one degree. | |
| constexpr std::array | kleidos:: |
NavEdge: the same double knock, two bursts below the center. | |
| constexpr std::array | kleidos:: |
Select: two notes rising a fourth to the center. | |
| constexpr std::array | kleidos:: |
Back: the same two notes down. | |
| constexpr std::array | kleidos:: |
Notice: one note. | |
| constexpr std::array | kleidos:: |
SendStart: a glide rising to the center. | |
| constexpr std::array | kleidos:: |
Delete: a falling glide. | |
| constexpr std::array | kleidos:: |
Success: two notes rising to the center, the second longer. | |
| constexpr std::array | kleidos:: |
Error: one long glide falling a fourth from the center. | |
| constexpr std::array | kleidos:: |
| constexpr std::array | kleidos:: |
Lock: three notes falling from the center. | |
| constexpr std::array | kleidos:: |
PinWrong: two notes a minor third apart, falling, with a gap. | |
| constexpr std::array | kleidos:: |
Warning: the same note twice, at the center. | |
| constexpr std::array | kleidos:: |
Pairing: two notes, the second a degree higher and longer. | |
| constexpr std::array | kleidos:: |
LowBattery: two notes falling a fourth, with a long rest between. | |
| constexpr std::array | kleidos:: |
Lockout: three falling notes. | |
Enumeration Type Documentation
Envelope #
Sound #
Every sound the device makes, named by what it means.
In priority order: the four ticks, the five actions, the eight results, the two alerts (hal::hal::.
SoundClass #
What a sound is for, in rising priority.
A request of an equal or higher class cuts the sound that is playing; a lower one is dropped.
Function Documentation
begin() #
Initialize the speaker backend.
- Return values
-
Value Meaning true if the backend started successfully. false on I2C / I2S / PWM configuration failure.
bell() #
A bell note: glass, with a shimmer that outlasts the strike.
- Parameters
-
Name Direction Meaning startMs in Onset. hz in Pitch; it picks the ratio and the index (bellRatioQ8, bellIndexQ8). decayTauMs in kBellDecayMs, kBellRingMs on a note that rings out, less on a damped one. lengthMs in Length. levelHalfDb in Level against the sound's.
- Returns
- The note.
bellIndexQ8() #
The modulation index a bell is struck with at a pitch.
- Parameters
-
Name Direction Meaning hz in Pitch.
- Returns
- Less from A6 up and less again on D7, so the top of an arpeggio is not its harshest note.
bellRatioQ8() #
The modulator ratio a bell has at a pitch.
- Parameters
-
Name Direction Meaning hz in Pitch.
- Returns
- kBellHighRatioQ8 on A6 and B6, where 4.5 times the note would land on the 8 kHz limit or past it; kBellRatioQ8 elsewhere.
click() #
A click: a struck tick, bright for a few milliseconds, then a plain tone.
- Parameters
-
Name Direction Meaning startMs in Onset. f0Hz in Pitch at the onset. f1Hz in Pitch after the glide; f0Hzfor a tick that stays.glideMs in Length of the glide. decayTauMs in How fast it dies, 4 to 10. lengthMs in Length. levelHalfDb in Level against the sound's.
- Returns
- The note.
closed() #
A closed note: inharmonic and damped, the timbre of a refusal.
- Parameters
-
Name Direction Meaning startMs in Onset. f0Hz in Pitch at the onset. f1Hz in Pitch after the glide; f0Hzfor a note that stays.glideMs in Length of the glide. decayTauMs in How fast it dies, 60 to 90: damped, never held. lengthMs in Length. levelHalfDb in Level against the sound's.
- Returns
- The note.
codecName() #
Compile-time name of the audio codec on this variant, if any.
Reports the codec IC selected at build time (e.g. "ES8311"). This is a pure build-configuration query: it does not touch the codec object (which is created lazily on the first tone) and plays no sound.
- Returns
- Codec name, or
nullptron variants with no I2C codec (PWM buzzers and codec-less I2S amps).
decayCoefQ16() #
Per-frame Q16 decay factor of a time constant.
- Parameters
-
Name Direction Meaning tauMs in Time constant in milliseconds; 0 means "held", and a value past the table decays as the table's last entry does.
- Returns
- The factor, kCoefHeldQ16 for a held level.
depthTurnsQ16() #
Peak phase swing of a modulation index, as a fraction of a turn.
- Parameters
-
Name Direction Meaning indexQ8 in Modulation index in radians, Q8 (256 = 1.0).
- Returns
- The swing in turns, Q16 (65536 = one turn).
digestOf() [1/2] #
Renders a whole row to nowhere and reports what came out.
- Parameters
-
Name Direction Meaning entry in The row, as Synth::start takes it. volumePercent in Volume, in percent. ceilingHalfDb in The ceiling.
- Returns
- The render's length, peak, clamp count and hash.
digestOf() [2/2] #
Renders a whole sound to nowhere and reports what came out.
The identity check of the synthesizer: the native tests pin Digest::fnv1a for every sound, and the same call on a device must print the same number. FNV-1a, not a cryptographic hash, because nothing here needs one and a hardware hash engine is not to be taken from a diagnostic.
- Parameters
-
Name Direction Meaning sound in The sound. volumePercent in Volume, in percent. ceilingHalfDb in The ceiling, as in Synth::start.
- Returns
- The render's length, peak, clamp count and hash.
end() #
Power off the speaker backend.
On an I2S board the speaker task does the close and this call waits for it (a quarter of a second at most): a stream in flight is abandoned at its next block, the amplifier's gate goes low, the channel stops and the codec powers down. The channel stays allocated, as the I2S facade never deletes one, and the next begin reopens it.
entryOf() #
The catalog row of a sound.
- Parameters
-
Name Direction Meaning sound in The sound.
- Returns
- Its row; the first row for a value that names no sound.
findByName() #
Finds a sound by the name the console and the portal use.
- Parameters
-
Name Direction Meaning name in The name, case as in the catalog.
- Returns
- The row, or
nullptrwhen no sound has that name.
fnv1aWith() #
Folds one 16-bit value into a 64-bit FNV-1a hash, low byte first.
The digest of a rendered sound and of the tables below: an identity check, for which a cryptographic hash would be the wrong tool.
- Parameters
-
Name Direction Meaning hash in The hash so far; kFnvOffsetBasis to begin. value in The value to fold in.
- Returns
- The hash with both bytes of
valuefolded in.
framesForMs() #
Frames (mono samples) that play for ms at sampleRateHz.
- Parameters
-
Name Direction Meaning sampleRateHz in Sample rate in hertz. ms in Length in milliseconds.
- Returns
- The frame count, rounded down; saturated at
UINT32_MAX.
gainQ15() #
Q15 gain of an attenuation.
- Parameters
-
Name Direction Meaning halfDb in Attenuation in half-decibels; past the table it stays at the table's last entry, 63.5 dB down.
- Returns
- The gain, 32768 for no attenuation.
i2sAttenuationHalfDb() #
I2S: how far below the ceiling a volume plays.
- Parameters
-
Name Direction Meaning percent in Volume; normalized first (normalizeVolume).
- Returns
- Attenuation in half-decibels: 0 at 100 %, three more per step down.
isAvailable() #
Check whether a working speaker backend is present.
- Return values
-
Value Meaning true if a speaker is available (PWM buzzer, I2S amp, or codec). false if the build has no audio backend (neither a buzzer pin nor an I2S path).
makeEntry() #
Builds one catalog row, with its length worked out from its notes.
- Parameters
-
Name Direction Meaning id in The sound. name in Its name. cls in Its class. levelHalfDb in Its level against the volume's full level. notes in Its I2S rendition. steps in Its buzzer rendition. repeat in Times it plays. repeatGapMs in Silence between two plays.
- Returns
- The row.
makeToneStreamPlan() #
The plan for a channel and an amplifier.
- Parameters
-
Name Direction Meaning sampleRateHz in Sample rate of the channel, in hertz. ringFrames in Frames the channel's DMA ring holds; a restart puts that much silence ahead of the first sample. ampStartMs in Silence the amplifier must see between its gate going high and the first sample, in milliseconds.
- Returns
- The lead-in (what
ampStartMsneeds beyond the ring) and the tail (the ring plus kToneTailMarginMs).
msForFrames() #
How long frames play at sampleRateHz, in milliseconds, rounded up.
- Parameters
-
Name Direction Meaning sampleRateHz in Sample rate in hertz. frames in Frame count.
- Returns
- The length; 0 when the rate is 0, saturated at
UINT32_MAX.
normalizeVolume() #
The law's figure for any requested one.
Rounds to the nearest step and clamps to the range, so a requested 3 plays as 5 and a requested 27 as 25.
- Parameters
-
Name Direction Meaning percent in Any value.
- Returns
- A multiple of kVolumeStepPercent between kVolumeMinPercent and kVolumeMaxPercent.
passLengthMs() [1/2] #
Length of one play of a note list.
- Parameters
-
Name Direction Meaning notes in The notes.
- Returns
- The latest end of any of them, in milliseconds.
passLengthMs() [2/2] #
Length of one play of a step list.
- Parameters
-
Name Direction Meaning steps in The steps.
- Returns
- The sum of their lengths, in milliseconds.
phaseIncrement() #
Phase advance per frame of a frequency.
- Parameters
-
Name Direction Meaning hz in Frequency in hertz, below half of kSampleRateHz.
- Returns
- hz x 2^32 / kSampleRateHz, rounded down.
playedCount() #
How many tones and sounds the speaker task has played.
Counts each request the backend produced output for (PWM updates the channel took, or samples the I2S channel took), whether it ran out or a stop cut it short; a request the backend refused, or one still queued when end() ran, is not counted. A console can so tell that a request reached the hardware. It does not tell that a tone was heard: an I2S tone is counted when its first sample is handed to the channel, a ring away from the pin, and a stream cut there plays nothing. streamStats says which streams reached their end.
- Returns
- The count since boot.
playSound() #
Play a catalog sound on a buzzer board.
Queues sound for the speaker task, which walks the catalog's buzzer rendition (hal::
- Parameters
-
Name Direction Meaning sound in The sound. volumePercent in Volume, 5 to 100 % (normalized by the sequencer).
- Return values
-
Value Meaning true The sound was queued. false The board's output is not a buzzer, the backend is not started, or the queue is full.
playTone() #
Queue a tone for the speaker task.
On an I2S board the task plays it inside the audio side's hold on the hardware SHA/AES engines (kleidos::
- Parameters
-
Name Direction Meaning frequencyHz in Tone frequency in Hz. durationMs in Duration in milliseconds.
- Return values
-
Value Meaning true The tone was queued. false The backend is not started or the queue is full.
pwmDuty() #
Buzzer: the duty a full-level step plays at.
- Parameters
-
Name Direction Meaning percent in Volume; normalized first (normalizeVolume).
- Returns
- The duty in kPwmDutyBits bits, kPwmDutyCap at 100 %.
pwmLengthMs() #
Length of a sound's buzzer rendition.
- Parameters
-
Name Direction Meaning entry in The sound's row.
- Returns
- Its length in milliseconds, repeats and gaps included.
repeatedLengthMs() #
Length of a rendition played several times with a gap between plays.
- Parameters
-
Name Direction Meaning passMs in Length of one play. repeat in Times it plays. repeatGapMs in Silence between two plays.
- Returns
- The whole length, in milliseconds.
rest() #
A buzzer rest: the pin low.
- Parameters
-
Name Direction Meaning ms in Length.
- Returns
- The step.
setAmpGate() #
Drive the speaker amplifier's own gate, where this board has one.
The amplifier's enable line or supply gate, and nothing else: the I2S channel is left as it is. The gate is a PMIC GPIO, an I/O-expander pin or a board pin depending on the variant, and the amp driver owns that detail including the order its pad must be configured in.
Creates the amplifier object if the first tone has not yet done so, so the gate can be driven from a cold boot. Only declared where the build drives an audio output (AUDIO_); callers fence on it.
- Parameters
-
Name Direction Meaning on in True to raise the gate, false to lower it.
- Return values
-
Value Meaning true This board has a gate and it was driven. false No software gate on this board (an always-on part, or none).
setVolume() #
Set output volume.
- Parameters
-
Name Direction Meaning volume in Level 0..255; mapped to the backend's native range.
sineQ15() #
Sine of a 32-bit phase, in Q15.
The top eight bits pick the table entry and the next eight interpolate to the one after it, so sixteen bits of the phase are heard.
- Parameters
-
Name Direction Meaning phase in The phase; the whole 32-bit range is one turn.
- Returns
- The sine, -32767 to 32767.
slide() #
A buzzer glide with a soft start and end.
- Parameters
-
Name Direction Meaning fromQ8 in Pitch at the start. toQ8 in Pitch at the end. ms in Length, kPwmSoftMinMs or more. dutyScaleQ7 in Level.
- Returns
- The step.
softBell() #
A soft bell: swelled instead of struck, its shimmer fading with the note.
- Parameters
-
Name Direction Meaning startMs in Onset. hz in Pitch, below A6. lengthMs in Length.
- Returns
- The note.
soundingLengthMs() #
How long note index really sounds, once the two-voice rule is applied.
Note n plays on voice n modulo kVoices. A note that starts on a voice still sounding releases the old one over kReleaseMs while it attacks, so a note is over at the latest kReleaseMs after the onset of the note kVoices places after it.
- Parameters
-
Name Direction Meaning notes in The notes of one sound, by onset. index in Which note.
- Returns
- Its length in milliseconds: its own, or less when a later note takes its voice.
streamStats() #
How often the I2S streams were cut, started again and lost.
A stream is one cue: the tones queued back to back. It is lost when it does not write its tail: it could not have the engines to start, it gave way and was not resumed (or was cut again after its last resume), end() or a stop ended it, or a write failed; the tones of the cue still queued behind it are dropped with it. So a cue was heard whole when playedCount rose by its tones and lost did not move; heard with a gap in it when resumed rose too. All zero on a buzzer board, whose sounds take no lock.
- Returns
- The counts since boot.
tick() #
A buzzer tick: one burst at half of the duty, moving in pitch or not.
Half and no less: at the default volume a narrower pulse is a few microseconds wide, and nobody knows yet whether a buzzer's coil answers one.
- Parameters
-
Name Direction Meaning fromQ8 in Pitch at the start. toQ8 in Pitch at the end; fromQ8for a tick that stays.ms in Length.
- Returns
- The step.
tone() #
A buzzer note with a soft start and end.
- Parameters
-
Name Direction Meaning ratioQ8 in Pitch. ms in Length, kPwmSoftMinMs or more. dutyScaleQ7 in Level.
- Returns
- The step.
wood() #
A wood note: struck, with the octave and the double octave over it while the strike lasts.
- Parameters
-
Name Direction Meaning startMs in Onset. f0Hz in Pitch at the onset. f1Hz in Pitch after the glide; f0Hzfor a note that stays.glideMs in Length of the glide. decayTauMs in How fast it dies, 14 to 35. lengthMs in Length. levelHalfDb in Level against the sound's. indexTauMs in How long its color lasts; longer on a note that glides.
- Returns
- The note.
Variable Documentation
kBuzzerCenterMaxHz #
Highest center frequency a board may declare: the top pitch of the catalog (kRatioFifthAbove) must still be one the timer makes.
kCatalog #
Every sound, in the order of hal::Sound.
Levels are half-decibels against the volume's full level, and they are peaks. They are not a loudness order: a tick peaks 6 dB under the unlock in order to be heard some 13 dB under it, and a refusal peaks 4 dB under it in order not to be heard above it. The unlock has the highest peak and, by the measure a host test holds, the most loudness of anything but its own repeat.
kCeilingHalfDb #
I2S: level of full volume below digital full scale, in half-decibels (-4 dBFS).
The 4 dB are room for the waveform between the samples. A frame is not the waveform: the bells put partials near the top of the band, and what a DAC rebuilds between two samples peaks up to 3 dB over the samples themselves. With this room the rebuilt waveform of every sound stays under full scale (a host test holds it). The figure is also under the level at which the M5StickS3 browns out on battery (75 % of full scale), so no board needs a ceiling of its own for that.
kErrorNotes #
Error: one closed note sliding down a fourth, from the home note. The buzzer plays the same slide. From D6 and not higher: the closed timbre's upper partials then stay clear of the top of the band.
kLockNotes #
Lock: the top of the unlock backwards and damped, a latch closing. No longer than it is heard: the way into sleep waits for its last frame.
kLowestHz #
Lowest pitch a note may sound at, in hertz: under it a 1 W micro-speaker in a small case gives almost nothing back, and a sound heard on a computer would be missing on the board.
kNavEdgeNotes #
NavEdge: a double knock on B5, the second softer. A rhythm and not a low pitch: any speaker and the buzzer return a rhythm.
kPwmAttackDivisor #
A Envelope::
kPwmMaxFrequencyHz #
Highest frequency a step may come to, in hertz. The PWM timer makes 7,800 Hz at kPwmDutyBits bits from the slowest clock the boards run it on (RC_FAST, 8 MHz nominal); that clock is an uncalibrated RC oscillator, so the limit sits a sixth under it.
kPwmSliceMs #
How often a buzzer glide or duty ramp is updated, in milliseconds.
A step that moves is cut into slices of this length, and a Envelope::Select and Back first) have to be retimed in the same edit. The asserts at the end of this file refuse the edit until they are.
kToneTailMarginMs #
Silence the tail adds to the ring, in milliseconds: the margin that keeps the last tone sample out of what a pause discards.
kUnlockNotes #
Unlock: the signature. A rising four-note bell arpeggio that rings out. Locate plays it twice.
kUnlockSteps #
Unlock: four notes rising to the center, where the last is held. Locate plays it twice.