SoundChipSimulator

Example of the component fdivitto/fabgl v2.0.0
# SoundChipSimulator

Plays a catalog of **retro sound effects** generated by a small software "sound chip" (ADSR envelope + frequency
sweep) built on top of `fabgl::SoundGenerator`. By Carles Oriol.

The name of each effect is printed on screen while it plays: *shot*, *boom*, *pong*, *pic*, *tuc*, *piu*,
*fiu fiu whistle*, *fiu fiu serpentina*, *motor*, then musical scales (*escala*, *escala_inc* with the three
frequency sweep modes, *escalax*) and chords (sequential, overlapping and strummed). The sequence repeats forever.
There are no controls.

## The sound descriptor

Each effect is a `playsounddata` structure:

```cpp
{ attack_ms, decay_ms, sustain (0-127), release_ms, wave, volume (0-127), duration_ms,
  freq_start, freq_end, modfreq }
```

- `wave`: `WAVE_SQUARE`, `WAVE_SINE`, `WAVE_TRIANGLE`, `WAVE_SAW`, `WAVE_NOISE`
- `modfreq`: how the frequency moves from `freq_start` to `freq_end`: `MODFREQ_NONE`, `MODFREQ_TO_END` (whole
  duration), `MODFREQ_TO_RELEASE` (until the release phase), `MODFREQ_TO_SUSTAIN` (during attack and decay)

`playSound()` plays a sound asynchronously (in its own task, so several sounds can overlap); `syncPlaySound()`
waits until it ends. Copy these two functions to add the same effects to your games: they are used by
[DirectVGA_ElMuro](../DirectVGA_ElMuro) and [ClassicRacer](../ClassicRacer).

## What it demonstrates

- `fabgl::SoundGenerator` with waveform generators attached and detached at run time
- Envelopes and frequency sweeps done by changing volume and frequency of a generator while it plays

## Hardware

- VGA output (default pins)
- Audio output on GPIO25

## Build

See [Building the examples](../../../README.md#building-the-examples) in the main README.

To create a project from this example, run:

idf.py create-project-from-example "fdivitto/fabgl=2.0.0:SoundChipSimulator"

or download archive (~4.92 KB)