56#define AUDIO_STEP(hz, end, ms) \
57 { (uint8_t)(((hz) + 10) / 20), (uint8_t)(((end) + 10) / 20), (uint8_t)(((ms) + 1) / 2) }
60#define AUDIO_REST(ms) { 0, 0, (uint8_t)(((ms) + 1) / 2) }
66#if defined(__riscv) && !defined(CHSIM)
67#define AUDIO_STEPS(name) static const audio::Step name[] __attribute__((section(".rodata.audio." #name)))
69#define AUDIO_STEPS(name) static const audio::Step name[]
86#define AUDIO_EFFECT(steps, flags) { steps, (uint8_t)(sizeof(steps) / sizeof((steps)[0])), (uint8_t)(flags) }
109void sfx(uint8_t
id, uint8_t semitones);
112template <
class E>
inline void sfx(E e) {
sfx((uint8_t)e); }
116template <
class E>
inline void sfx(E e, uint8_t semitones) {
sfx((uint8_t)e, semitones); }
124void blip(uint16_t hz, uint16_t ms,
bool soft =
false);
129void note(uint16_t hz, uint16_t ms, uint8_t priority);
147void music(
const uint8_t *score,
bool loop =
true);
193extern uint8_t simLast;
Sound effects, music and the status LED.
Definition Audio.h:42
Led
Status LED (PB9; PB10 on CHGame Rev1) patterns, for wins. Timed in update() ticks.
Definition Audio.h:182
@ LED_PARTY
Fast blinking for about 4 seconds at 60 fps.
Definition Audio.h:186
@ LED_OFF
Off.
Definition Audio.h:183
@ LED_BLINK
One blink (12 ticks).
Definition Audio.h:184
@ LED_TRIPLE
Three blinks.
Definition Audio.h:185
bool on()
Whether sound is on.
@ SOFT
A narrow pulse: quieter than everything else (clocks, ticks).
Definition Audio.h:74
@ GLIDE
Sweeps change pitch at a cycle's end instead of restarting it.
Definition Audio.h:75
void blip(uint16_t hz, uint16_t ms, bool soft=false)
One note made up on the spot (a typewriter, a click, a counter rolling).
void loopMusic(bool on)
Whether the music repeats.
void melody(const Melody &m, bool loop=true)
Play a melody under the effects (it replaces any score).
void setMusic(uint8_t mode)
Choose how music is rendered.
MusicMode
How music is rendered on the one pin.
Definition Audio.h:136
@ MUSIC_OFF
No music (held where it is).
Definition Audio.h:137
@ LEAD
The melody (channel 0) plays; the others fill only its real rests.
Definition Audio.h:139
@ ARPEGGIO
A score's sounding voices take 6 ms turns (the default).
Definition Audio.h:138
void setOn(bool on)
Turn sound on or off.
void update()
Run the LED patterns: once per logic tick.
void music(const uint8_t *score, bool loop=true)
Play a Playtune score under the effects.
bool playing()
Whether an effect is sounding.
bool musicPlaying()
Whether music is playing.
void note(uint16_t hz, uint16_t ms, uint8_t priority)
One note at a priority, like an effect.
void stopMusic()
Stop the music.
void led(Led pattern)
Start an LED pattern (replacing the one running).
void sfx(uint8_t id)
Play an effect.
void begin(const Effect *effects, uint8_t count, bool on=true)
Set up the speaker, the LED pin and the timer, with the game's effects.
An effect: its steps, and its priority with flags. Write them with AUDIO_EFFECT().
Definition Audio.h:78
uint8_t n
Number of steps.
Definition Audio.h:80
const Step * steps
The step table (AUDIO_STEPS()).
Definition Audio.h:79
uint8_t flags
Priority 0-15, ORed with SOFT and GLIDE.
Definition Audio.h:81
A melody: one line of notes, easy to write by hand.
Definition Audio.h:158
uint8_t gapMs
Silence at the end of each note, in milliseconds.
Definition Audio.h:162
const uint8_t * notes
(MIDI note, length) pairs.
Definition Audio.h:159
uint8_t count
Number of pairs.
Definition Audio.h:160
uint8_t unitMs
Milliseconds per length unit.
Definition Audio.h:161
An effect step in three bytes.
Definition Audio.h:47
uint8_t ms
The length in 2 ms units.
Definition Audio.h:50
uint8_t endHz
The pitch it sweeps to, in 20 Hz units; 0 = none (holds hz).
Definition Audio.h:49
uint8_t hz
The pitch in 20 Hz units; 0 = a rest.
Definition Audio.h:48