Kleidos API Search

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::sound::Synth 16 kHz, 16-bit mono frames, a block at a time
Steps, for a buzzer hal::sound::PwmSequencer 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_volume.h), a speaker at a quarter of its range.

See also
Hardware Abstraction Layer, The boards, Audio Drivers

Files

file src/hal/sound/audio_feedback.h
file src/hal/sound/audio_feedback_speaker.cpp
file src/hal/sound/sound_catalog.h
Every sound the device makes, as data: what it is for and both of its renditions.
file src/hal/sound/sound_id.h
The names of the device's sounds and of their classes, and nothing else.
file src/hal/sound/sound_math.h
The fixed-point tables of the sound synthesizer, built at compile time.
file src/hal/sound/sound_pwm.h
Turns a catalog sound into the frequency and duty updates a one-bit buzzer is driven with.
file src/hal/sound/sound_synth.h
Renders a catalog sound into 16 kHz, 16-bit mono PCM, a block at a time.
file src/hal/sound/sound_volume.h
The volume law: what a volume figure does to each rendition of a sound.
file src/hal/sound/speaker.h
Variant-agnostic speaker facade for tone playback.
file src/hal/sound/tone_stream.h
The samples one run of tones is streamed as over I2S, block by block.

Classes

class kleidos::AudioFeedback
Plays short UI feedback tones and persists the enabled preference. More about kleidos::AudioFeedback
struct kleidos::hal::sound::Note
One struck note of a sound's I2S rendition. More about kleidos::hal::sound::Note
struct kleidos::hal::sound::Step
One step of a sound's buzzer rendition: a note, a glide or a rest. More about kleidos::hal::sound::Step
struct kleidos::hal::sound::Entry
One sound: its name, its class, its level and both renditions. More about kleidos::hal::sound::Entry
struct kleidos::hal::sound::PwmUpdate
One setting of the buzzer's PWM channel, and how long it stands. More about kleidos::hal::sound::PwmUpdate
class kleidos::hal::sound::PwmSequencer
Walks one catalog sound as a sequence of PWM updates. More about kleidos::hal::sound::PwmSequencer
class kleidos::hal::sound::Synth
Plays one catalog sound into PCM blocks. More about kleidos::hal::sound::Synth
struct kleidos::hal::sound::Digest
What one whole render of a sound comes to. More about kleidos::hal::sound::Digest
struct kleidos::hal::speaker::StreamStats
What became of the I2S streams (the runs of tones) since boot. More about kleidos::hal::speaker::StreamStats
struct kleidos::hal::sound::ToneStreamPlan
The lengths one tone stream is cut from, in frames. More about kleidos::hal::sound::ToneStreamPlan
struct kleidos::hal::sound::StreamTone
One square-wave tone of a stream. More about kleidos::hal::sound::StreamTone
class kleidos::hal::sound::ToneStream
Hands out the blocks of one run of tones: lead-in, tones, tail. More about kleidos::hal::sound::ToneStream
class kleidos::hal::sound::ResumeBudget
How long, and how often, a stream that gave way may start again. More about kleidos::hal::sound::ResumeBudget
class kleidos::hal::sound::QuietWatch
Whether the engines have gone quiet since they were last looked at. More about kleidos::hal::sound::QuietWatch

Enumerations

enum class kleidos::hal::sound::Envelope : uint8_t { kleidos::hal::sound::Envelope::Flat , kleidos::hal::sound::Envelope::Soft }
How a buzzer step's duty moves between its first and last millisecond. More about kleidos::hal::sound::Envelope
enum class kleidos::hal::Sound : uint8_t { kleidos::hal::Sound::KeyTick, kleidos::hal::Sound::NavUp, kleidos::hal::Sound::NavDown, kleidos::hal::Sound::NavEdge, kleidos::hal::Sound::Select, kleidos::hal::Sound::Back, kleidos::hal::Sound::Notice, kleidos::hal::Sound::SendStart, kleidos::hal::Sound::Delete, kleidos::hal::Sound::Success, kleidos::hal::Sound::Error, kleidos::hal::Sound::Unlock, kleidos::hal::Sound::Lock, kleidos::hal::Sound::PinWrong, kleidos::hal::Sound::Warning, kleidos::hal::Sound::Pairing, kleidos::hal::Sound::LowBattery, kleidos::hal::Sound::Lockout, kleidos::hal::Sound::Locate }
Every sound the device makes, named by what it means. More about kleidos::hal::Sound
enum class kleidos::hal::sound::SoundClass : uint8_t { kleidos::hal::sound::SoundClass::Tick , kleidos::hal::sound::SoundClass::Action , kleidos::hal::sound::SoundClass::Result , kleidos::hal::sound::SoundClass::Alert }
What a sound is for, in rising priority. More about kleidos::hal::sound::SoundClass

Functions

constexpr Notekleidos::hal::sound::click (uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb=0)
A click: a struck tick, bright for a few milliseconds, then a plain tone.
constexpr Notekleidos::hal::sound::wood (uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb=0, uint16_t indexTauMs=kWoodIndexTauMs)
A wood note: struck, with the octave and the double octave over it while the strike lasts.
constexpr uint16_tkleidos::hal::sound::bellRatioQ8 (uint16_t hz)
The modulator ratio a bell has at a pitch.
constexpr uint16_tkleidos::hal::sound::bellIndexQ8 (uint16_t hz)
The modulation index a bell is struck with at a pitch.
constexpr Notekleidos::hal::sound::bell (uint16_t startMs, uint16_t hz, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb=0)
A bell note: glass, with a shimmer that outlasts the strike.
constexpr Notekleidos::hal::sound::softBell (uint16_t startMs, uint16_t hz, uint16_t lengthMs)
A soft bell: swelled instead of struck, its shimmer fading with the note.
constexpr Notekleidos::hal::sound::closed (uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb=0)
A closed note: inharmonic and damped, the timbre of a refusal.
constexpr Stepkleidos::hal::sound::tone (uint16_t ratioQ8, uint16_t ms, uint8_t dutyScaleQ7=kDutyFull)
A buzzer note with a soft start and end.
constexpr Stepkleidos::hal::sound::slide (uint16_t fromQ8, uint16_t toQ8, uint16_t ms, uint8_t dutyScaleQ7=kDutyFull)
A buzzer glide with a soft start and end.
constexpr Stepkleidos::hal::sound::tick (uint16_t fromQ8, uint16_t toQ8, uint16_t ms)
A buzzer tick: one burst at half of the duty, moving in pitch or not.
constexpr Stepkleidos::hal::sound::rest (uint16_t ms)
A buzzer rest: the pin low.
constexpr uint16_tkleidos::hal::sound::passLengthMs (std::span< const Note > notes)
Length of one play of a note list.
constexpr uint16_tkleidos::hal::sound::passLengthMs (std::span< const Step > steps)
Length of one play of a step list.
constexpr uint16_tkleidos::hal::sound::repeatedLengthMs (uint16_t passMs, uint8_t repeat, uint16_t repeatGapMs)
Length of a rendition played several times with a gap between plays.
constexpr uint16_tkleidos::hal::sound::soundingLengthMs (std::span< const Note > notes, std::size_t index)
How long note index really sounds, once the two-voice rule is applied.
constexpr Entrykleidos::hal::sound::makeEntry (Sound id, const char *name, SoundClass cls, int8_t levelHalfDb, std::span< const Note > notes, std::span< const Step > steps, uint8_t repeat=1, uint16_t repeatGapMs=0)
Builds one catalog row, with its length worked out from its notes.
constexpr const Entry &kleidos::hal::sound::entryOf (Sound sound)
The catalog row of a sound.
constexpr const Entry *kleidos::hal::sound::findByName (std::string_view name)
Finds a sound by the name the console and the portal use.
constexpr uint16_tkleidos::hal::sound::pwmLengthMs (const Entry &entry)
Length of a sound's buzzer rendition.
constexpr uint64_tkleidos::hal::sound::fnv1aWith (uint64_t hash, uint16_t value)
Folds one 16-bit value into a 64-bit FNV-1a hash, low byte first.
constexpr uint32_tkleidos::hal::sound::gainQ15 (uint32_t halfDb)
Q15 gain of an attenuation.
constexpr uint32_tkleidos::hal::sound::decayCoefQ16 (uint32_t tauMs)
Per-frame Q16 decay factor of a time constant.
constexpr int32_tkleidos::hal::sound::sineQ15 (uint32_t phase)
Sine of a 32-bit phase, in Q15.
constexpr uint32_tkleidos::hal::sound::phaseIncrement (uint32_t hz)
Phase advance per frame of a frequency.
constexpr uint32_tkleidos::hal::sound::depthTurnsQ16 (uint32_t indexQ8)
Peak phase swing of a modulation index, as a fraction of a turn.
Digestkleidos::hal::sound::digestOf (Sound sound, uint8_t volumePercent, uint8_t ceilingHalfDb=kCeilingHalfDb)
Renders a whole sound to nowhere and reports what came out.
Digestkleidos::hal::sound::digestOf (const Entry &entry, uint8_t volumePercent, uint8_t ceilingHalfDb=kCeilingHalfDb)
Renders a whole row to nowhere and reports what came out.
constexpr uint8_tkleidos::hal::sound::normalizeVolume (uint8_t percent)
The law's figure for any requested one.
constexpr uint32_tkleidos::hal::sound::i2sAttenuationHalfDb (uint8_t percent)
I2S: how far below the ceiling a volume plays.
constexpr uint16_tkleidos::hal::sound::pwmDuty (uint8_t percent)
Buzzer: the duty a full-level step plays at.
boolkleidos::hal::speaker::begin ()
Initialize the speaker backend.
voidkleidos::hal::speaker::setVolume (uint8_t volume)
Set output volume.
boolkleidos::hal::speaker::playTone (uint32_t frequencyHz, uint32_t durationMs)
Queue a tone for the speaker task.
boolkleidos::hal::speaker::playSound (hal::Sound sound, uint8_t volumePercent)
Play a catalog sound on a buzzer board.
uint32_tkleidos::hal::speaker::playedCount ()
How many tones and sounds the speaker task has played.
StreamStatskleidos::hal::speaker::streamStats ()
How often the I2S streams were cut, started again and lost.
voidkleidos::hal::speaker::end ()
Power off the speaker backend.
boolkleidos::hal::speaker::setAmpGate (bool on)
Drive the speaker amplifier's own gate, where this board has one.
boolkleidos::hal::speaker::isAvailable ()
Check whether a working speaker backend is present.
const char *kleidos::hal::speaker::codecName ()
Compile-time name of the audio codec on this variant, if any.
constexpr uint32_tkleidos::hal::sound::framesForMs (uint32_t sampleRateHz, uint32_t ms)
Frames (mono samples) that play for ms at sampleRateHz.
constexpr uint32_tkleidos::hal::sound::msForFrames (uint32_t sampleRateHz, uint32_t frames)
How long frames play at sampleRateHz, in milliseconds, rounded up.
constexpr ToneStreamPlankleidos::hal::sound::makeToneStreamPlan (uint32_t sampleRateHz, uint32_t ringFrames, uint32_t ampStartMs)
The plan for a channel and an amplifier.

Variables

constexpr std::size_tkleidos::hal::sound::kMaxNotes
Most notes one sound has.
constexpr std::size_tkleidos::hal::sound::kMaxSteps
Most buzzer steps one sound has.
constexpr uint16_tkleidos::hal::sound::kReleaseMs
Length of a note's closing linear release, and of the release a stolen note gets.
constexpr std::size_tkleidos::hal::sound::kVoices
Notes that sound at once: note n plays on voice n modulo this.
constexpr uint16_tkleidos::hal::sound::kShortSoundMaxMs
Longest SoundClass::Tick or SoundClass::Action sound, in milliseconds.
constexpr uint32_tkleidos::hal::sound::kBuzzerCenterDefaultHz
Center frequency of a buzzer nobody has swept yet, in hertz: a guess to replace per board.
constexpr uint16_tkleidos::hal::sound::kPwmStepMinMs
Shortest buzzer step, in milliseconds: what a task still times on a 1 ms tick.
constexpr uint16_tkleidos::hal::sound::kPwmSliceMs
How often a buzzer glide or duty ramp is updated, in milliseconds.
constexpr uint16_tkleidos::hal::sound::kPwmAttackSlices
Slices a Envelope::Soft step spends rising: a quarter of its duty, then half.
constexpr uint32_tkleidos::hal::sound::kPwmAttackDivisor
constexpr uint32_tkleidos::hal::sound::kDutyScaleBits
Bits of the fraction of Step::dutyScaleQ7.
constexpr uint16_tkleidos::hal::sound::kPwmDecayMs
Length of the half-duty tail of a Envelope::Soft step, in milliseconds.
constexpr uint16_tkleidos::hal::sound::kPwmSoftMinMs
Shortest Envelope::Soft step: its rise, one slice at its whole duty, its tail.
constexpr std::array< uint16_t, 8 >kleidos::hal::sound::kScaleHz
Every pitch of the scale, lowest first.
constexpr uint16_tkleidos::hal::sound::kGs5
The one pitch off the scale: Lockout ends on a note the scale does not have.
constexpr uint16_tkleidos::hal::sound::kLowestHz
constexpr std::array< Entry, kSoundCount >kleidos::hal::sound::kCatalog
Every sound, in the order of hal::Sound.
constexpr std::size_tkleidos::hal::sound::kSoundCount
How many sounds hal::Sound names.
constexpr uint32_tkleidos::hal::sound::kSampleRateHz
Sample rate of the I2S rendition, in frames per second (16-bit mono).
constexpr uint32_tkleidos::hal::sound::kFramesPerMs
Frames in one millisecond at kSampleRateHz.
constexpr std::size_tkleidos::hal::sound::kSineTableSize
Entries of the sine table kSineQ15, which holds one period.
constexpr std::size_tkleidos::hal::sound::kGainTableSize
Entries of the gain table kGainQ15, one per half-decibel from 0 to 63.5 dB.
constexpr std::size_tkleidos::hal::sound::kDecayTableSize
Entries of the decay table kDecayCoefQ16, one per millisecond from 0 to 127.
constexpr uint32_tkleidos::hal::sound::kUnityQ15
Full scale of a Q15 gain or envelope: 1.0.
constexpr uint32_tkleidos::hal::sound::kCoefHeldQ16
A Q16 decay coefficient that leaves its state unchanged: a held level.
constexpr uint64_tkleidos::hal::sound::kFnvOffsetBasis
Value an empty 64-bit FNV-1a hash starts from.
constexpr uint64_tkleidos::hal::sound::kFnvPrime
Multiplier of 64-bit FNV-1a.
constexpr std::array< uint16_t, kGainTableSize >kleidos::hal::sound::kGainQ15
Q15 gain of an attenuation in half-decibels: entry n is round( 32768 x 10^( -n / 40 ) ).
constexpr std::array< uint16_t, kDecayTableSize >kleidos::hal::sound::kDecayCoefQ16
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::hal::sound::kSineQ15
One period of the sine in Q15: entry i is round( 32767 x sin( 2 pi i / 256 ) ).
constexpr uint64_tkleidos::hal::sound::kTablesDigest
FNV-1a of the gain, decay and sine tables, in that order.
constexpr uint32_tkleidos::hal::sound::kPwmMaxFrequencyHz
constexpr uint32_tkleidos::hal::sound::kBuzzerCenterMaxHz
constexpr std::size_tkleidos::hal::sound::kBlockFrames
Frames in the block a sound is streamed in: 8 ms at 16 kHz.
constexpr std::size_tkleidos::hal::sound::kVoiceSlots
Notes that can be heard at once: kVoices sounding and one in its release.
constexpr uint8_tkleidos::hal::sound::kVolumeMinPercent
Lowest figure the law takes, in percent.
constexpr uint8_tkleidos::hal::sound::kVolumeMaxPercent
Highest figure the law takes, in percent.
constexpr uint8_tkleidos::hal::sound::kVolumeStepPercent
One step of the law, in percent.
constexpr uint8_tkleidos::hal::sound::kVolumeDefaultPercent
The figure a buzzer plays every cue at, in percent.
constexpr std::size_tkleidos::hal::sound::kVolumeSteps
How many figures the law takes: 5, 10 ... 100.
constexpr uint32_tkleidos::hal::sound::kI2sSpanHalfDb
I2S: attenuation at 0 % against 100 %, in half-decibels (30 dB).
constexpr uint8_tkleidos::hal::sound::kCeilingHalfDb
I2S: level of full volume below digital full scale, in half-decibels (-4 dBFS).
constexpr uint32_tkleidos::hal::sound::kPwmDutyBits
Buzzer: resolution of the duty the sequencer hands the PWM facade, in bits.
constexpr uint16_tkleidos::hal::sound::kPwmDutyCap
Buzzer: the highest duty ever asked for, 50 % of the kPwmDutyBits range.
constexpr uint32_tkleidos::hal::sound::kPwmSpanTenthDb
Buzzer: level at 0 % against 100 %, in tenths of a decibel (18 dB).
constexpr std::array< uint16_t, kVolumeSteps >kleidos::hal::sound::kPwmDutyByStep
Buzzer: the duty of a full-level step at each volume, 5 % first.
constexpr uint32_tkleidos::hal::sound::kToneTailMarginMs

The scale: D major pentatonic, A5 to D7, in hertz

constexpr uint16_tkleidos::hal::sound::kA5
A5.
constexpr uint16_tkleidos::hal::sound::kB5
B5.
constexpr uint16_tkleidos::hal::sound::kD6
D6: the family's home note.
constexpr uint16_tkleidos::hal::sound::kE6
E6: where the ticks sit.
constexpr uint16_tkleidos::hal::sound::kFs6
F sharp 6.
constexpr uint16_tkleidos::hal::sound::kA6
A6.
constexpr uint16_tkleidos::hal::sound::kB6
B6.
constexpr uint16_tkleidos::hal::sound::kD7
D7.

Timbres: modulator ratio and index, Q8

constexpr uint16_tkleidos::hal::sound::kClickRatioQ8
1 : 2.
constexpr uint16_tkleidos::hal::sound::kClickIndexQ8
2.0 radians at the strike.
constexpr uint16_tkleidos::hal::sound::kWoodRatioQ8
1 : 3: partials at 2 and 4 times the note.
constexpr uint16_tkleidos::hal::sound::kWoodIndexQ8
1.0 at the strike.
constexpr uint16_tkleidos::hal::sound::kBellRatioQ8
1 : 3.5: partials at 2.5 and 4.5 times.
constexpr uint16_tkleidos::hal::sound::kBellIndexQ8
1.5 at the strike.
constexpr uint16_tkleidos::hal::sound::kBellHighRatioQ8
1 : 2.5 on A6 and B6: 1.5 and 3.5 times.
constexpr uint16_tkleidos::hal::sound::kBellHighIndexQ8
1.25 on A6 and B6.
constexpr uint16_tkleidos::hal::sound::kBellTopIndexQ8
1.0 on D7, whose 4.5 partial folds back.
constexpr uint16_tkleidos::hal::sound::kSoftBellIndexQ8
1.0: a bell struck with felt.
constexpr uint16_tkleidos::hal::sound::kClosedRatioQ8
1 : 2.41: a tritone and 3.41 times above.
constexpr uint16_tkleidos::hal::sound::kClosedIndexQ8
1.25 at the strike.

Timbres: envelope times, in milliseconds

constexpr uint16_tkleidos::hal::sound::kClickIndexTauMs
The click is gone in a few ms.
constexpr uint16_tkleidos::hal::sound::kWoodIndexTauMs
The wood's color outlasts its strike.
constexpr uint16_tkleidos::hal::sound::kBellIndexTauMs
The bell's shimmer lasts longer.
constexpr uint16_tkleidos::hal::sound::kSoftBellIndexTauMs
Felt: the shimmer fades with the note.
constexpr uint16_tkleidos::hal::sound::kClosedIndexTauMs
A closed note stays closed to its end.
constexpr uint16_tkleidos::hal::sound::kBellDecayMs
A bell note that makes way for the next.
constexpr uint16_tkleidos::hal::sound::kBellRingMs
A last bell note that rings out.
constexpr uint16_tkleidos::hal::sound::kSoftBellDecayMs
A soft bell's body.
constexpr uint8_tkleidos::hal::sound::kStruckAttackMs
Struck.
constexpr uint8_tkleidos::hal::sound::kBellAttackMs
Struck, a little rounder.
constexpr uint8_tkleidos::hal::sound::kClosedAttackMs
Pressed, not struck.
constexpr uint8_tkleidos::hal::sound::kSoftAttackMs
Swelled: the gentlest onset a note has.

Buzzer pitches: ratios of the center frequency, Q8

Degrees of the scale in equal temperament, with the center as its home note, and the major scale's seventh for the one figure that needs four rising notes.

constexpr uint16_tkleidos::hal::sound::kRatioFourthBelow
0.75.
constexpr uint16_tkleidos::hal::sound::kRatioThirdBelow
0.84, a minor third down.
constexpr uint16_tkleidos::hal::sound::kRatioSeventhBelow
0.94, a semitone down: the leading note.
constexpr uint16_tkleidos::hal::sound::kRatioCenter
1.0: the buzzer's loudest region.
constexpr uint16_tkleidos::hal::sound::kRatioSecondAbove
1.12.
constexpr uint16_tkleidos::hal::sound::kRatioFifthAbove
1.5: the highest a step may ask for.

Buzzer levels: share of the volume's duty, Q7

constexpr uint8_tkleidos::hal::sound::kDutyFull
Results and alerts.
constexpr uint8_tkleidos::hal::sound::kDutyAction
Three quarters: what the user just did.
constexpr uint8_tkleidos::hal::sound::kDutyHalf
Ticks: the least a flat burst is given.
constexpr uint8_tkleidos::hal::sound::kDutyRest
Silence, the pin low.

Notes of each sound

constexpr std::arraykleidos::hal::sound::kKeyTickNotes
KeyTick: a soft, dry "tk". One click on E6, the tick that does not move.
constexpr std::arraykleidos::hal::sound::kNavUpNotes
NavUp: a tick that jumps up a fourth, from E6 to rest on A6.
constexpr std::arraykleidos::hal::sound::kNavDownNotes
NavDown: its mirror, down a fourth to rest on B5.
constexpr std::arraykleidos::hal::sound::kNavEdgeNotes
constexpr std::arraykleidos::hal::sound::kSelectNotes
Select: two wood notes up a fifth, far enough apart for their order to be heard.
constexpr std::arraykleidos::hal::sound::kBackNotes
Back: the same two notes down.
constexpr std::arraykleidos::hal::sound::kNoticeNotes
Notice: one small bell.
constexpr std::arraykleidos::hal::sound::kSendStartNotes
SendStart: a rising sweep of a fifth, "off it goes".
constexpr std::arraykleidos::hal::sound::kDeleteNotes
Delete: a wood note that falls a fifth and closes.
constexpr std::arraykleidos::hal::sound::kSuccessNotes
Success: two bright bells, a fourth up; the second rings.
constexpr std::arraykleidos::hal::sound::kErrorNotes
constexpr std::arraykleidos::hal::sound::kUnlockNotes
constexpr std::arraykleidos::hal::sound::kLockNotes
constexpr std::arraykleidos::hal::sound::kPinWrongNotes
PinWrong: two closed notes, a minor third down, no ring.
constexpr std::arraykleidos::hal::sound::kWarningNotes
Warning: the same bell twice, insistent.
constexpr std::arraykleidos::hal::sound::kPairingNotes
Pairing: a question. Two bells, the second a tone higher and left open.
constexpr std::arraykleidos::hal::sound::kLowBatteryNotes
LowBattery: two soft bells sinking a fourth, E6 then B5.
constexpr std::arraykleidos::hal::sound::kLockoutNotes
Lockout: three closed notes down, the last one off the scale.

Buzzer steps of each sound

constexpr std::arraykleidos::hal::sound::kKeyTickSteps
KeyTick: one 4 ms burst at the center.
constexpr std::arraykleidos::hal::sound::kNavUpSteps
NavUp: a short glide up one degree.
constexpr std::arraykleidos::hal::sound::kNavDownSteps
NavDown: a short glide down one degree.
constexpr std::arraykleidos::hal::sound::kNavEdgeSteps
NavEdge: the same double knock, two bursts below the center.
constexpr std::arraykleidos::hal::sound::kSelectSteps
Select: two notes rising a fourth to the center.
constexpr std::arraykleidos::hal::sound::kBackSteps
Back: the same two notes down.
constexpr std::arraykleidos::hal::sound::kNoticeSteps
Notice: one note.
constexpr std::arraykleidos::hal::sound::kSendStartSteps
SendStart: a glide rising to the center.
constexpr std::arraykleidos::hal::sound::kDeleteSteps
Delete: a falling glide.
constexpr std::arraykleidos::hal::sound::kSuccessSteps
Success: two notes rising to the center, the second longer.
constexpr std::arraykleidos::hal::sound::kErrorSteps
Error: one long glide falling a fourth from the center.
constexpr std::arraykleidos::hal::sound::kUnlockSteps
constexpr std::arraykleidos::hal::sound::kLockSteps
Lock: three notes falling from the center.
constexpr std::arraykleidos::hal::sound::kPinWrongSteps
PinWrong: two notes a minor third apart, falling, with a gap.
constexpr std::arraykleidos::hal::sound::kWarningSteps
Warning: the same note twice, at the center.
constexpr std::arraykleidos::hal::sound::kPairingSteps
Pairing: two notes, the second a degree higher and longer.
constexpr std::arraykleidos::hal::sound::kLowBatterySteps
LowBattery: two notes falling a fourth, with a long rest between.
constexpr std::arraykleidos::hal::sound::kLockoutSteps
Lockout: three falling notes.

Back to the top

Enumeration Type Documentation

Envelope #

enum class kleidos::hal::sound::Envelope : uint8_t

How a buzzer step's duty moves between its first and last millisecond.

Enumerator
Flat 

One duty from start to end: a tick.

Soft 

A quarter, then half, then the whole duty; half again over the last 8 ms.

Sound #

enum class kleidos::hal::Sound : uint8_t

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::sound::SoundClass). The enumerator's value is the sound's row in hal::sound::kCatalog.

Enumerator
KeyTick 

A key in any text or secret entry: every key the same.

NavUp 

The selection moved up or left.

NavDown 

The selection moved down or right.

NavEdge 

A move that cannot happen: the end of a list that does not wrap.

Select 

An item opened, a choice confirmed, a toggle going on.

Back 

A screen left, a cancel, a toggle going off.

Notice 

An informational popup or toast appeared.

SendStart 

A BLE send begins.

Delete 

An item was removed from a list, once it is gone.

Success 

Send done, saved, synced, paired, backup written.

Error 

Send failed, save refused, sync failed, pairing refused.

Unlock 

PIN or passphrase accepted and HOME is on screen.

Lock 

A live session ended on a lit panel.

PinWrong 

PIN or passphrase refused, no lockout started.

Warning 

A destructive confirm appeared.

Pairing 

The numeric-comparison prompt appeared.

LowBattery 

The low-battery notice was painted on a lit panel.

Lockout 

A refused secret started a lockout.

Locate 

The sound check of the portal and the console.

SoundClass #

enum class kleidos::hal::sound::SoundClass : uint8_t

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.

Enumerator
Tick 

Keys and list moves: dropped first, never queued behind anything.

Action 

What the user just did: open, leave, notice, send, delete.

Result 

How something ended.

Alert 

What must be heard: a lockout, the sound check.

Back to the top

Function Documentation

begin() #

bool kleidos::hal::speaker::begin()

Initialize the speaker backend.

Return values
ValueMeaning
trueif the backend started successfully.
falseon I2C / I2S / PWM configuration failure.

bell() #

Note kleidos::hal::sound::bell(uint16_t startMs, uint16_t hz, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb = 0)
constexpr

A bell note: glass, with a shimmer that outlasts the strike.

Parameters
NameDirectionMeaning
startMsinOnset.
hzinPitch; it picks the ratio and the index (bellRatioQ8, bellIndexQ8).
decayTauMsinkBellDecayMs, kBellRingMs on a note that rings out, less on a damped one.
lengthMsinLength.
levelHalfDbinLevel against the sound's.
Returns
The note.

bellIndexQ8() #

uint16_t kleidos::hal::sound::bellIndexQ8(uint16_t hz)
constexpr

The modulation index a bell is struck with at a pitch.

Parameters
NameDirectionMeaning
hzinPitch.
Returns
Less from A6 up and less again on D7, so the top of an arpeggio is not its harshest note.

bellRatioQ8() #

uint16_t kleidos::hal::sound::bellRatioQ8(uint16_t hz)
constexpr

The modulator ratio a bell has at a pitch.

Parameters
NameDirectionMeaning
hzinPitch.
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() #

Note kleidos::hal::sound::click(uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb = 0)
constexpr

A click: a struck tick, bright for a few milliseconds, then a plain tone.

Parameters
NameDirectionMeaning
startMsinOnset.
f0HzinPitch at the onset.
f1HzinPitch after the glide; f0Hz for a tick that stays.
glideMsinLength of the glide.
decayTauMsinHow fast it dies, 4 to 10.
lengthMsinLength.
levelHalfDbinLevel against the sound's.
Returns
The note.

closed() #

Note kleidos::hal::sound::closed(uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb = 0)
constexpr

A closed note: inharmonic and damped, the timbre of a refusal.

Parameters
NameDirectionMeaning
startMsinOnset.
f0HzinPitch at the onset.
f1HzinPitch after the glide; f0Hz for a note that stays.
glideMsinLength of the glide.
decayTauMsinHow fast it dies, 60 to 90: damped, never held.
lengthMsinLength.
levelHalfDbinLevel against the sound's.
Returns
The note.

codecName() #

const char * kleidos::hal::speaker::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 nullptr on variants with no I2C codec (PWM buzzers and codec-less I2S amps).

decayCoefQ16() #

uint32_t kleidos::hal::sound::decayCoefQ16(uint32_t tauMs)
constexpr

Per-frame Q16 decay factor of a time constant.

Parameters
NameDirectionMeaning
tauMsinTime 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() #

uint32_t kleidos::hal::sound::depthTurnsQ16(uint32_t indexQ8)
constexpr

Peak phase swing of a modulation index, as a fraction of a turn.

Parameters
NameDirectionMeaning
indexQ8inModulation index in radians, Q8 (256 = 1.0).
Returns
The swing in turns, Q16 (65536 = one turn).

digestOf() [1/2] #

Digest kleidos::hal::sound::digestOf(const Entry & entry, uint8_t volumePercent, uint8_t ceilingHalfDb = kCeilingHalfDb)

Renders a whole row to nowhere and reports what came out.

Parameters
NameDirectionMeaning
entryinThe row, as Synth::start takes it.
volumePercentinVolume, in percent.
ceilingHalfDbinThe ceiling.
Returns
The render's length, peak, clamp count and hash.

digestOf() [2/2] #

Digest kleidos::hal::sound::digestOf(Sound sound, uint8_t volumePercent, uint8_t ceilingHalfDb = kCeilingHalfDb)

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
NameDirectionMeaning
soundinThe sound.
volumePercentinVolume, in percent.
ceilingHalfDbinThe ceiling, as in Synth::start.
Returns
The render's length, peak, clamp count and hash.

end() #

void kleidos::hal::speaker::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() #

const Entry & kleidos::hal::sound::entryOf(Sound sound)
constexpr

The catalog row of a sound.

Parameters
NameDirectionMeaning
soundinThe sound.
Returns
Its row; the first row for a value that names no sound.

findByName() #

const Entry * kleidos::hal::sound::findByName(std::string_view name)
constexpr

Finds a sound by the name the console and the portal use.

Parameters
NameDirectionMeaning
nameinThe name, case as in the catalog.
Returns
The row, or nullptr when no sound has that name.

fnv1aWith() #

uint64_t kleidos::hal::sound::fnv1aWith(uint64_t hash, uint16_t value)
constexpr

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
NameDirectionMeaning
hashinThe hash so far; kFnvOffsetBasis to begin.
valueinThe value to fold in.
Returns
The hash with both bytes of value folded in.

framesForMs() #

uint32_t kleidos::hal::sound::framesForMs(uint32_t sampleRateHz, uint32_t ms)
constexpr

Frames (mono samples) that play for ms at sampleRateHz.

Parameters
NameDirectionMeaning
sampleRateHzinSample rate in hertz.
msinLength in milliseconds.
Returns
The frame count, rounded down; saturated at UINT32_MAX.

gainQ15() #

uint32_t kleidos::hal::sound::gainQ15(uint32_t halfDb)
constexpr

Q15 gain of an attenuation.

Parameters
NameDirectionMeaning
halfDbinAttenuation 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() #

uint32_t kleidos::hal::sound::i2sAttenuationHalfDb(uint8_t percent)
constexpr

I2S: how far below the ceiling a volume plays.

Parameters
NameDirectionMeaning
percentinVolume; normalized first (normalizeVolume).
Returns
Attenuation in half-decibels: 0 at 100 %, three more per step down.

isAvailable() #

bool kleidos::hal::speaker::isAvailable()

Check whether a working speaker backend is present.

Return values
ValueMeaning
trueif a speaker is available (PWM buzzer, I2S amp, or codec).
falseif the build has no audio backend (neither a buzzer pin nor an I2S path).

makeEntry() #

Entry kleidos::hal::sound::makeEntry(Sound id, const char * name, SoundClass cls, int8_t levelHalfDb, std::span< const Note > notes, std::span< const Step > steps, uint8_t repeat = 1, uint16_t repeatGapMs = 0)
constexpr

Builds one catalog row, with its length worked out from its notes.

Parameters
NameDirectionMeaning
idinThe sound.
nameinIts name.
clsinIts class.
levelHalfDbinIts level against the volume's full level.
notesinIts I2S rendition.
stepsinIts buzzer rendition.
repeatinTimes it plays.
repeatGapMsinSilence between two plays.
Returns
The row.

makeToneStreamPlan() #

ToneStreamPlan kleidos::hal::sound::makeToneStreamPlan(uint32_t sampleRateHz, uint32_t ringFrames, uint32_t ampStartMs)
constexpr

The plan for a channel and an amplifier.

Parameters
NameDirectionMeaning
sampleRateHzinSample rate of the channel, in hertz.
ringFramesinFrames the channel's DMA ring holds; a restart puts that much silence ahead of the first sample.
ampStartMsinSilence the amplifier must see between its gate going high and the first sample, in milliseconds.
Returns
The lead-in (what ampStartMs needs beyond the ring) and the tail (the ring plus kToneTailMarginMs).

msForFrames() #

uint32_t kleidos::hal::sound::msForFrames(uint32_t sampleRateHz, uint32_t frames)
constexpr

How long frames play at sampleRateHz, in milliseconds, rounded up.

Parameters
NameDirectionMeaning
sampleRateHzinSample rate in hertz.
framesinFrame count.
Returns
The length; 0 when the rate is 0, saturated at UINT32_MAX.

normalizeVolume() #

uint8_t kleidos::hal::sound::normalizeVolume(uint8_t percent)
constexpr

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
NameDirectionMeaning
percentinAny value.
Returns
A multiple of kVolumeStepPercent between kVolumeMinPercent and kVolumeMaxPercent.

passLengthMs() [1/2] #

uint16_t kleidos::hal::sound::passLengthMs(std::span< const Note > notes)
constexpr

Length of one play of a note list.

Parameters
NameDirectionMeaning
notesinThe notes.
Returns
The latest end of any of them, in milliseconds.

passLengthMs() [2/2] #

uint16_t kleidos::hal::sound::passLengthMs(std::span< const Step > steps)
constexpr

Length of one play of a step list.

Parameters
NameDirectionMeaning
stepsinThe steps.
Returns
The sum of their lengths, in milliseconds.

phaseIncrement() #

uint32_t kleidos::hal::sound::phaseIncrement(uint32_t hz)
constexpr

Phase advance per frame of a frequency.

Parameters
NameDirectionMeaning
hzinFrequency in hertz, below half of kSampleRateHz.
Returns
hz x 2^32 / kSampleRateHz, rounded down.

playedCount() #

uint32_t kleidos::hal::speaker::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() #

bool kleidos::hal::speaker::playSound(hal::Sound sound, uint8_t volumePercent)

Play a catalog sound on a buzzer board.

Queues sound for the speaker task, which walks the catalog's buzzer rendition (hal::sound::PwmSequencer) as frequency and duty updates of the buzzer's PWM channel and holds the pin low once it is over.

Parameters
NameDirectionMeaning
soundinThe sound.
volumePercentinVolume, 5 to 100 % (normalized by the sequencer).
Return values
ValueMeaning
trueThe sound was queued.
falseThe board's output is not a buzzer, the backend is not started, or the queue is full.

playTone() #

bool kleidos::hal::speaker::playTone(uint32_t frequencyHz, uint32_t durationMs)

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::platform::crypto_hw::AudioHold): the channel runs only while tones stream, tones queued back to back play as one stream, a crypto caller that asks for the engines cuts the stream within the yield budget, and a tone that cannot have the engines in time is dropped. A stream that was cut starts again when the engines have gone quiet soon enough (unused for 10 ms, within 150 ms of its first cut, twice at most): behind a short burst of their use, such as an NVS write on a hardened build, a cue is heard with a gap in it; behind a key derivation it is lost (streamStats). On a buzzer board it is LEDC PWM and takes no lock.

Parameters
NameDirectionMeaning
frequencyHzinTone frequency in Hz.
durationMsinDuration in milliseconds.
Return values
ValueMeaning
trueThe tone was queued.
falseThe backend is not started or the queue is full.

pwmDuty() #

uint16_t kleidos::hal::sound::pwmDuty(uint8_t percent)
constexpr

Buzzer: the duty a full-level step plays at.

Parameters
NameDirectionMeaning
percentinVolume; normalized first (normalizeVolume).
Returns
The duty in kPwmDutyBits bits, kPwmDutyCap at 100 %.

pwmLengthMs() #

uint16_t kleidos::hal::sound::pwmLengthMs(const Entry & entry)
constexpr

Length of a sound's buzzer rendition.

Parameters
NameDirectionMeaning
entryinThe sound's row.
Returns
Its length in milliseconds, repeats and gaps included.

repeatedLengthMs() #

uint16_t kleidos::hal::sound::repeatedLengthMs(uint16_t passMs, uint8_t repeat, uint16_t repeatGapMs)
constexpr

Length of a rendition played several times with a gap between plays.

Parameters
NameDirectionMeaning
passMsinLength of one play.
repeatinTimes it plays.
repeatGapMsinSilence between two plays.
Returns
The whole length, in milliseconds.

rest() #

Step kleidos::hal::sound::rest(uint16_t ms)
constexpr

A buzzer rest: the pin low.

Parameters
NameDirectionMeaning
msinLength.
Returns
The step.

setAmpGate() #

bool kleidos::hal::speaker::setAmpGate(bool on)

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_OUTPUT_DRIVEN); callers fence on it.

Parameters
NameDirectionMeaning
oninTrue to raise the gate, false to lower it.
Return values
ValueMeaning
trueThis board has a gate and it was driven.
falseNo software gate on this board (an always-on part, or none).

setVolume() #

void kleidos::hal::speaker::setVolume(uint8_t volume)

Set output volume.

Parameters
NameDirectionMeaning
volumeinLevel 0..255; mapped to the backend's native range.

sineQ15() #

int32_t kleidos::hal::sound::sineQ15(uint32_t phase)
constexpr

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
NameDirectionMeaning
phaseinThe phase; the whole 32-bit range is one turn.
Returns
The sine, -32767 to 32767.

slide() #

Step kleidos::hal::sound::slide(uint16_t fromQ8, uint16_t toQ8, uint16_t ms, uint8_t dutyScaleQ7 = kDutyFull)
constexpr

A buzzer glide with a soft start and end.

Parameters
NameDirectionMeaning
fromQ8inPitch at the start.
toQ8inPitch at the end.
msinLength, kPwmSoftMinMs or more.
dutyScaleQ7inLevel.
Returns
The step.

softBell() #

Note kleidos::hal::sound::softBell(uint16_t startMs, uint16_t hz, uint16_t lengthMs)
constexpr

A soft bell: swelled instead of struck, its shimmer fading with the note.

Parameters
NameDirectionMeaning
startMsinOnset.
hzinPitch, below A6.
lengthMsinLength.
Returns
The note.

soundingLengthMs() #

uint16_t kleidos::hal::sound::soundingLengthMs(std::span< const Note > notes, std::size_t index)
constexpr

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
NameDirectionMeaning
notesinThe notes of one sound, by onset.
indexinWhich note.
Returns
Its length in milliseconds: its own, or less when a later note takes its voice.

streamStats() #

StreamStats kleidos::hal::speaker::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() #

Step kleidos::hal::sound::tick(uint16_t fromQ8, uint16_t toQ8, uint16_t ms)
constexpr

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
NameDirectionMeaning
fromQ8inPitch at the start.
toQ8inPitch at the end; fromQ8 for a tick that stays.
msinLength.
Returns
The step.

tone() #

Step kleidos::hal::sound::tone(uint16_t ratioQ8, uint16_t ms, uint8_t dutyScaleQ7 = kDutyFull)
constexpr

A buzzer note with a soft start and end.

Parameters
NameDirectionMeaning
ratioQ8inPitch.
msinLength, kPwmSoftMinMs or more.
dutyScaleQ7inLevel.
Returns
The step.

wood() #

Note kleidos::hal::sound::wood(uint16_t startMs, uint16_t f0Hz, uint16_t f1Hz, uint16_t glideMs, uint16_t decayTauMs, uint16_t lengthMs, int8_t levelHalfDb = 0, uint16_t indexTauMs = kWoodIndexTauMs)
constexpr

A wood note: struck, with the octave and the double octave over it while the strike lasts.

Parameters
NameDirectionMeaning
startMsinOnset.
f0HzinPitch at the onset.
f1HzinPitch after the glide; f0Hz for a note that stays.
glideMsinLength of the glide.
decayTauMsinHow fast it dies, 14 to 35.
lengthMsinLength.
levelHalfDbinLevel against the sound's.
indexTauMsinHow long its color lasts; longer on a note that glides.
Returns
The note.

Back to the top

Variable Documentation

kBuzzerCenterMaxHz #

uint32_t kleidos::hal::sound::kBuzzerCenterMaxHz
inlineconstexpr

Highest center frequency a board may declare: the top pitch of the catalog (kRatioFifthAbove) must still be one the timer makes.

kCatalog #

std::array<Entry, kSoundCount> kleidos::hal::sound::kCatalog
inlineconstexpr

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 #

uint8_t kleidos::hal::sound::kCeilingHalfDb
inlineconstexpr

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 #

std::array kleidos::hal::sound::kErrorNotes
inlineconstexpr

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 #

std::array kleidos::hal::sound::kLockNotes
inlineconstexpr

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 #

uint16_t kleidos::hal::sound::kLowestHz
inlineconstexpr

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 #

std::array kleidos::hal::sound::kNavEdgeNotes
inlineconstexpr

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 #

uint32_t kleidos::hal::sound::kPwmAttackDivisor
inlineconstexpr

A Envelope::Soft step's first slice plays at its duty over this. At the default volume that is a pulse of 4 to 6 microseconds, which a buzzer's coil may not answer: the note is then one slice shorter and no softer.

kPwmMaxFrequencyHz #

uint32_t kleidos::hal::sound::kPwmMaxFrequencyHz
inlineconstexpr

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 #

uint16_t kleidos::hal::sound::kPwmSliceMs
inlineconstexpr

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::Soft step is built from them (kPwmSoftMinMs). Raising it is therefore not a change of one number: the shortest soft step grows with it, and the catalog's steps shorter than that (the 30 ms notes of 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 #

uint32_t kleidos::hal::sound::kToneTailMarginMs
inlineconstexpr

Silence the tail adds to the ring, in milliseconds: the margin that keeps the last tone sample out of what a pause discards.

kUnlockNotes #

std::array kleidos::hal::sound::kUnlockNotes
inlineconstexpr

Unlock: the signature. A rising four-note bell arpeggio that rings out. Locate plays it twice.

kUnlockSteps #

std::array kleidos::hal::sound::kUnlockSteps
inlineconstexpr

Unlock: four notes rising to the center, where the last is held. Locate plays it twice.

Back to the top