rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.88k stars 160 forks source link

Tuner tends to assume harmonic overtones or subtones when playing a tone #129

Closed Sahara150 closed 3 years ago

Sahara150 commented 3 years ago

When I e.g. sang an pure A (440 Hz) it tended to show 880 Hz from time to time. This probably happens, cause you take the biggest amplitude (just an assumption, didn´t go completely into your autocorrelate function). However the truly inputted frequency can also be recognized at the form of its higher frequency spectrum. (This way ambiguity errors could be prevented). Is mathematically kinda complex though.

rserota commented 3 years ago

You might be right, but I wouldn't know enough to improve the algorithm. If you think you can write a more accurate autocorrelate algorithm that's still fast enough, feel free to submit a pull request. The relevant code is in src/polywad.js, line 40.

gabeklavans commented 3 years ago

This probably happens, cause you take the biggest amplitude

If it's autocorrelation, amplitude shouldn't affect things too much, since it doesn't use the frequency domain to do detection. But, Autocorrelation detection methods can also get tripped up by complex wave forms with many inner-wave-patterns, likely the case for the voice.

I just recently found this repository and when I have some time in the coming weeks I'd like to try my hand at going in and implementing the YIN algorithm, which should be an even more accurate version of autocorrelation (that doesn't sacrifice speed). I also haven't inspected the current code yet, so maybe it's already using YIN lol but I'll poke around