Audio · DSP / Recognizer working · Home triggers planned

Ocarina Listener

A Raspberry Pi that recognizes songs played on a real ocarina

Video placeholder Clip — playing Song of Storms on the ocarina, then the chime and the song

TL;DR

Inspired by Ocarina of Time and Majora's Mask, where playing a melody makes something happen. I play a real 12-hole ocarina near a microphone, a Raspberry Pi works out which notes I'm playing, and when they match a known song it plays a confirmation chime followed by the song itself. The long-term goal is to make each song a command for wireless devices around the house.

The Short Interview

QWhy build this?
A

Purely for fun, and to see if I could build a reliable recognition system. In the games, a melody is a command. I wanted the same thing in real life: play a song on a real ocarina and have the world respond.

QWhere is it headed?
A

The recognizer is the foundation. The plan is to add wireless ESP devices around the house that each react to a different song, so playing a particular melody performs a particular action. That part isn't built yet.

QIs this the same as the ocarina on stream?
A

They're siblings. This one hears a real instrument. The Chat Ocarina in my MBC streaming platform lets viewers "play" by typing notes in chat. Both turn input into a sequence of notes and match it against known songs, but this one has the much harder job of listening to air.

From Breath to Song

A constrained problem on purpose: one instrument, one note at a time and a known songbook. That's what makes reliable recognition possible on modest hardware.

Listen

Microphone

Small sample blocks, continuously

Audio queue

Decouples capture from processing

Understand

Energy gate

Ignore silence

Pitch estimate

aubio YIN, with confidence

Quantize

Hz → nearest note, octave-independent

Stabilize

A held note becomes one note

Match

Rolling buffer vs songbook

Respond

Input lock

Stop listening first

Chime

"Recognized"

Song

"…and it was this one"

Turning Sound Into Notes

Two gates
A note needs enough signal (amplitude) and a trustworthy pitch (confidence). A loud breath transient can fail the second gate, and a clean but quiet note can fail the first.
Pitch → note
Frequencies are converted to the nearest equal-tempered note, so slight breath-pressure drift still lands on the right note.
Octaves
Recognition ignores octave, so a brief octave mis-estimate doesn't become a wrong note.
Stability
A sustained note spans dozens of audio frames but counts as one note. Brief wobbles between neighbouring semitones are ignored.
Rolling buffer
Stray notes before a song don't matter. The matcher looks for a known melody at the end of what you've played, so there's no need to reset first.

Problems & Solutions

  1. 01

    It recognized its own song

    ProblemThe microphone could hear the chime and the song the Pi played back. With recognition still active, the playback was heard as new input, so a recognized song could retrigger itself. Even with recognition paused, microphone audio queued up during playback could fire a delayed retrigger once the pause ended.

    FixThe input lock is now taken the instant a song is recognized, before any sound plays. The note buffer is cleared, and audio captured during a four-second ignore window is drained and discarded instead of processed late. Listening resumes with fresh audio.

    LessonA feedback loop is a timing problem, not a pitch problem. No amount of threshold tuning fixes it. Lock first, play second, throw away what you heard in between.

  2. 02

    One long note, dozens of notes

    ProblemTreating each audio frame as a note filled the buffer with duplicates of a single held note.

    FixPer-frame estimates go through stabilization and deduplication, so only a settled, new note is accepted into the song buffer.

  3. 03

    Real instruments drift

    ProblemOn an ocarina, pitch depends on fingering and breath pressure, so the same note can measure differently every time. Room noise and reflections add to that.

    FixAmplitude and confidence gating, rounding to the nearest note and octave independence keep recognition stable without having to play perfectly.

“The goal is recognizing activation melodies, not transcribing music.”

When It Met MBC

On October 29, 2026, a real ocarina drove my MBC streaming platform's native song engine and browser overlay for the first time. In a focused qualification test, six played notes arrived, Song of Storms was recognized, the notes and confirmation rendered in the browser, and the song's audio unlocked, started and finished.

That test ran with zero Twitch connections, on purpose. It proved the physical-instrument path on its own, separate from the chat-driven version viewers use on stream.

Build Log

  1. Feb 2, 2026

    Done

    Project started on a Raspberry Pi 3B: pitch detection, note normalization, sequence matching and playback.

  2. Feb 5, 2026

    Done

    Fixed the playback feedback loop with an immediate input lock, buffer clearing, queue draining and a four-second ignore window.

  3. Oct 29, 2026

    Done

    A physical ocarina passes end-to-end qualification through MBC's native song engine and overlay (Song of Storms).

  4. Next

    Planned

    Wireless ESP devices around the house, each triggered by a different song.

The Setup

Photo placeholder Photo — the 12-hole ocarina and the Pi
Photo placeholder Screenshot — live pitch and note readout