CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Sound and LED

audio::: sound effects, music and the status LED. More...

Namespaces

namespace  audio
 Sound effects, music and the status LED.
 

Classes

struct  audio::Step
 An effect step in three bytes. More...
 
struct  audio::Effect
 An effect: its steps, and its priority with flags. Write them with AUDIO_EFFECT(). More...
 
struct  audio::Melody
 A melody: one line of notes, easy to write by hand. More...
 

Detailed Description

audio::: sound effects, music and the status LED.

A game lists its effects once, in the order of its own enum:

enum class Sfx : uint8_t { Cursor, Win, COUNT };
AUDIO_STEPS(CURSOR) = { AUDIO_STEP(2100, 0, 10) };
AUDIO_STEPS(WIN) = { AUDIO_STEP(2093, 0, 60), AUDIO_STEP(4186, 0, 170) };
const audio::Effect SOUNDS[] = { AUDIO_EFFECT(CURSOR, 0), AUDIO_EFFECT(WIN, 3) };
audio::begin(SOUNDS, (uint8_t)Sfx::COUNT); // in setup()
audio::sfx(Sfx::Win); // any time
audio::update(); // once per logic tick (the LED)
#define AUDIO_STEP(hz, end, ms)
An effect step: a pitch, the pitch it sweeps to, a length.
Definition Audio.h:53
#define AUDIO_STEPS(name)
Declare an effect's step table, kept in flash.
Definition Audio.h:64
#define AUDIO_EFFECT(steps, flags)
An entry of the effects table.
Definition Audio.h:83
void update()
Run the LED patterns: once per logic tick.
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