Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building a Better Erhu Tuner: Why Auto correlation Beats Standard Pitch Detection in the Browser

If you've ever tried building a web-based instrument tuner using the Web Audio API, you probably started where most of us do: feeding microphone data into an AnalyserNode, running a Fast Fourier Transform (FFT), and looking for the highest frequency peak. It’s a classic, straightforward approach. And for synthesized tones or simple plucked strings, it works reasonably well. But recently, I built…

Abstract editorial illustration

Creating a more accurate erhu tuner for web-based instruments presents challenges due to the unique nature of bowed strings. Traditional tuners using frequency-domain Fast Fourier Transform (FFT) fail to accurately detect pitches in such cases. This article explains why time-domain Autocorrelation proves more effective for erhu tuners, and how to implement it in a modern web environment.

The inherent non-periodic nature of bow noise, combined with complex harmonics generated when the horsehair rosin contacts the steel string, confuses basic frequency detection techniques like zero-crossing algorithms and FFTs. As a result, these standard methods suffer from erratic readings and a high level of uncertainty. The Autocorrelation algorithm offers a solution by remaining within the time domain.

It works by sliding a copy of the waveform over itself to compare the overlapping segments. At each shift, the algorithm calculates a correlation peak which indicates the repeating cycle length of the soundwave. By dividing the sample rate by the found lag, the fundamental frequency in Hertz can be accurately derived. The key benefits of this method for bowed instruments lie in its ability to filter out irrelevant noise from the scratchy bowing action and concentrate on the consistent periodicity of the string's fundamental frequency.

Implementing this technique within a web browser requires offloading computations from the main UI thread to an AudioWorklet thread in modern browsers. By doing so, the processing remains real-time and isolated from other tasks like DOM manipulation, ensuring minimum lag. One potential pitfall of Autocorrelation is the "Octave Error" where it may mistakenly interpret the pitch as one octave lower than actual due to alignment with higher harmonics.

To tackle this issue, heuristics like peak picking are employed—selecting only the most significant and stable correlation peak while filtering out false positives. In conclusion, switching from traditional FFT-based pitch detection to time-domain Autocorrelation can drastically improve the reliability and precision of an erhu tuner.

Its robustness against bowing irregularities and non-periodic noise makes it an ideal choice for developers seeking accurate pitch detection for organic musical instruments in web environments.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Observer: The YouTube Subscribe Pattern

You subscribe to a YouTube channel and hit the bell. Now, whenever the creator uploads, you get notified automatically. You don't sit there refreshing every five minutes asking "new video yet?" The…

More from Sunday 2 August →