1 / 4
Software

Sound Bath SoundBath — Handheld Singing Bowl · Six-Instrument Meditation Sound Machine200190

This page was translated by AI and may differ from the original
感知交互

Turn a 4‑inch screen ESP32 handheld into a “portable meditation instrument”: touch to play a singing bowl, shake to trigger a fruit‑shell ra…

5872

Turn a 4‑inch screen ESP32 handheld into a “portable meditation instrument”: touch to play a singing bowl, shake to trigger a fruit‑shell rattle, long‑press the side button to hear a rain stick cascade. All sounds are synthesized in real time, with no sample files.

What It Can Do

InstrumentPlay MethodSynthesis Method
Singing BowlPress left touch key, or tap the screenModal resonance (multiple harmonics overlay)
HandpanTouch different notes on the handpan pageModal resonance + percussive transient
KalimbaPluck keys on the kalimba pageModal resonance
Rain StickHold right touch key / hold screen on rain stick pageGranular synthesis (grain cascade)
Wind ChimePluck on wind chime pageGranular synthesis (metal tube collisions)
RattleShake the device itselfGranular synthesis (IMU‑driven energy density)
  • Each instrument has independent volume (bottom‑screen volume bar, 11 levels), supports mute
  • Stereo field: grains/sand particles randomly distributed left‑right; the harder the rattle, the “wider” the sound
  • Full‑range loudness compensation from 220 Hz ~ 4 kHz, allowing the small speaker to still reveal low‑frequency bowl tones

Hardware

  • Main controller: ESP32‑S31 (RISC‑V), ESP‑IDF 6.2
  • Screen: 4‑inch touch screen (CST9220 touch, LVGL renders the entire UI, no image assets)
  • Audio: ES8311 codec + onboard speaker, I2S output 48 kHz
  • Sensors: BMI270 six‑axis IMU (rattle energy envelope + impact detection), bq27220 power monitor
  • Interaction: 2 touch keys (singing bowl / rain stick) + screen touch + motion shake

The audio engine runs in an independent task: the modal resonator (singing bowl/handpan/kalimba) and the granular engine (rain stick/wind chime/rattle) share a pool of 32 grains, processing one frame every 5 ms, with soft limiting on the output.

Pitfall Review (the most valuable part of this article)

1. Dual‑pole resonator coefficient formula written incorrectly → signal divergence → full device crash

The rendering equation is y = a·y1 − r·y2; the correct coefficients should be:

rr = expf(-13.82f / (fs * t60));   // single‑pole decay radius
a  = 2.0f * rr * cosf(theta);      // ❌ the wrong version omitted rr
r  = rr * rr;                      // ❌ the wrong version used exp(...) itself

The faulty version pushes the poles outside the unit circle: low‑frequency, short‑decay grains (rain stick < 2 kHz, rattle ≈ 700 Hz) produce exponentially diverging output → inf → NaN → the DC blocker state gets contaminated by NaN → permanent mute (the screen stays alive, but no sound); the diverging energy spikes can also pull down the USB power → full device crash. Strangely, the long‑decay low‑frequency instrument (singing bowl) stays stable, making the issue appear to occur only with the right key, misleading the debugging direction.

2. Once NaN enters the DC blocker it mutes forever

The DC blocker state persists across frames; a single NaN causes all subsequent outputs to become NaN. Fix: add a guard at the output stage, zero the sample when it is not finite and reset the blocker state.

3. Touch keys cannot be read as GPIO

During debugging I changed the key from touch‑FSM mode to GPIO mode to avoid crashes, but the touch pad is not a button, so the GPIO always reads 1, muting the singing bowl. The touch pool must use the touch FSM; don’t take shortcuts.

4. Device ownership lock

After a development gateway session crashes, the device remembers the dead session’s owner UUID, causing new session firmware uploads to be rejected. mosaico.py iris reconcile can reset ownership after all original sessions have stopped.

Known Limitations

  • The speaker is a small buzzer; the singing bowl’s ultra‑low‑frequency overtones rely on loudness compensation “hints”, and sound is more complete with headphones.
  • Rattle density caps at 250 grains per second; vigorous shaking may fill the grain pool (hardware lifetime guard prevents lock‑up).
  • Firmware is unsigned (community contribution package); flashing goes through the system update channel.

Build and Flash

# Compile + package + flash (requires ESP-Mosaico environment)
python build_sb2.py && python package_sb.py
python mosaico.py iris system-update --skip-build \
  --project projects/soundbath --device-id <your device ID>

The attached soundbath-v1.1.0.irisfw is a system update package and can be flashed directly via the ESP‑Iris device’s “System Update” entry.

License: Apache-2.0 · Feel free to discuss timbre parameter tuning in Issues

Comments (0)