4 ms·
I'm not any sort of scientist - everything I know about the topic I learned from trying to code this thing - but don't think of the sound wave coming from your
by ctrager 6y ago
I'm not any sort of scientist - everything I know about the topic I learned from trying to code this thing - but don't think of the sound wave coming from your viola as a simple sine wave. It's way more complex than that, with all the overtones/harmonics happening in addition to the note you think you are playing. The logic for deciding which pitch you are playing is fuzzy, and you can tweak the logic with the settings at the bottom of the page.
- aspaceman 6y agoNah you got it. There's a form of synthesizers where you start with simple sin waves that sounds electronic and mechanical. You layer various overtones on it to create more realistic sounds. Gettign the same richnesss as a real instrument is tough since there tends to be aspects of "sub-structure" for lack of another word. Really cool stuff.
- klyrs 6y agoThis is quite interesting stuff! A bowed string is nowhere near a sine wave -- it's approximately a sawtooth wave! The reason for this is that the string sticks to the bow (traveling relatively slowly) until the tension of the string overwhelms the coefficient of static friction, where it quickly slips (the jump discontinuity) across the bow until the relative velocity of the string drops enough to stick again. https://www.physicscentral.com/explore/action/fiddle.cfm https://www.physicscentral.com/explore/action/fiddle.cfm
- jakear 6y agoSo a sine wave convolved with a sawtooth? But the sine’s frequency is what would matter, as it’s the string’s resonant frequency. (This is why pizzacato works) The sawtooth is just for flavor.
- jacquesm 6y agoHave a look at the logic inside a program called 'Entropytuner', it is used for pianos but it will give you a lot of hints about good monophonic pitch detection.
- ctrager 6y agoI downloaded the source code and am hunting around but I haven't stumbled upon the pitch detection logic. Do you know what file, functions?
- jacquesm 6y agohttps://gitlab.com/tp3/Entropy-Piano-Tuner/-/tree/master/modules/core/analyzers https://gitlab.com/tp3/Entropy-Piano-Tuner/-/tree/master/mod... Also, for low frequencies with lots of overtones look into autocorrelation, that works quite well and can be efficient if you program it right.
- ctrager 6y agoThe code is waaaay over my head, but I see a function called "findAccuratePeakFrequency". Is that using as input something like an array where each occurrence represents a frequency and the value represents the loudness at that frequency? When I first tried to use WebAudio for my little app I tried using input like that and simply looking for which frequency bucket had the highest number. That didn't work well at all. Is this function, though, using the same kind of input but using more complicated math to get a better answer? Then I switched to very simple autocorrelation and then I switched to a fancier autocorrelation-based method called "Yin". Also, There's also a comment "The logarithmically binned spectrum has a resolution of one cent". Does that mean that there is a bucket for each 1 cent? When I was using WebAudio I think the the buckets were something like 14 units of frequency apart (hz?), and I didn't discover a way to get finer resolution.
- jacquesm 6y agoThe problem with FFTs is that for the lower frequencies you have very few bins, but at the higher end you get ridiculous accuracy and there is no easy way to make this more linear. Binning on the high end saves some space but doesn't make the low any more accurate. So you need to run multiple methods in parallel and decide based on the very rough distribution of the energy in the spectrum which method has the biggest chance of success, or, alternatively, to use the output of both methods to drive some logic that will assign a weight to the output of each. It's a tricky problem, to put it mildly. Also, this is the simplest form of the problem, doing this accurately for multiple pitches at once is much harder. Another source of inspiration is the 'onsets and frames' software that powers some automated transcription software: https://github.com/magenta/magenta/tree/master/magenta/models/onsets_frames_transcription https://github.com/magenta/magenta/tree/master/magenta/model... I think if this code is over your head that maybe a good introduction course on signal processing would be a nice thing to have under your belt. Best of luck!