53#define AUDIO_STEP(hz, end, ms) \
54 { (uint8_t)(((hz) + 10) / 20), (uint8_t)(((end) + 10) / 20), (uint8_t)(((ms) + 1) / 2) }
57#define AUDIO_REST(ms) { 0, 0, (uint8_t)(((ms) + 1) / 2) }
63#if defined(__riscv) && !defined(CHSIM)
64#define AUDIO_STEPS(name) static const audio::Step name[] __attribute__((section(".rodata.audio." #name)))
66#define AUDIO_STEPS(name) static const audio::Step name[]
83#define AUDIO_EFFECT(steps, flags) { steps, (uint8_t)(sizeof(steps) / sizeof((steps)[0])), (uint8_t)(flags) }
106void sfx(uint8_t
id, uint8_t semitones);
109template <
class E>
inline void sfx(E e) {
sfx((uint8_t)e); }
113template <
class E>
inline void sfx(E e, uint8_t semitones) {
sfx((uint8_t)e, semitones); }
121void blip(uint16_t hz, uint16_t ms,
bool soft =
false);
126void note(uint16_t hz, uint16_t ms, uint8_t priority);
144void music(
const uint8_t *score,
bool loop =
true);
190extern uint8_t simLast;
Sound effects, music and the status LED.
Definition Audio.h:39
Led
Status LED (PB9) patterns, for wins. Timed in update() ticks.
Definition Audio.h:179
@ LED_PARTY
Fast blinking for about 4 seconds at 60 fps.
Definition Audio.h:183
@ LED_OFF
Off.
Definition Audio.h:180
@ LED_BLINK
One blink (12 ticks).
Definition Audio.h:181
@ LED_TRIPLE
Three blinks.
Definition Audio.h:182
bool on()
Whether sound is on.
@ SOFT
A narrow pulse: quieter than everything else (clocks, ticks).
Definition Audio.h:71
@ GLIDE
Sweeps change pitch at a cycle's end instead of restarting it.
Definition Audio.h:72
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:133
@ MUSIC_OFF
No music (held where it is).
Definition Audio.h:134
@ LEAD
The melody (channel 0) plays; the others fill only its real rests.
Definition Audio.h:136
@ ARPEGGIO
A score's sounding voices take 6 ms turns (the default).
Definition Audio.h:135
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:75
uint8_t n
Number of steps.
Definition Audio.h:77
const Step * steps
The step table (AUDIO_STEPS()).
Definition Audio.h:76
uint8_t flags
Priority 0-15, ORed with SOFT and GLIDE.
Definition Audio.h:78
A melody: one line of notes, easy to write by hand.
Definition Audio.h:155
uint8_t gapMs
Silence at the end of each note, in milliseconds.
Definition Audio.h:159
const uint8_t * notes
(MIDI note, length) pairs.
Definition Audio.h:156
uint8_t count
Number of pairs.
Definition Audio.h:157
uint8_t unitMs
Milliseconds per length unit.
Definition Audio.h:158
An effect step in three bytes.
Definition Audio.h:44
uint8_t ms
The length in 2 ms units.
Definition Audio.h:47
uint8_t endHz
The pitch it sweeps to, in 20 Hz units; 0 = none (holds hz).
Definition Audio.h:46
uint8_t hz
The pitch in 20 Hz units; 0 = a rest.
Definition Audio.h:45