It looks like the app uses 12-tone equal temperament as the standard for "in tune". For violin it would probably be better to use a just intonation scale as the reference rather than ET. (ET major and minor thirds and sixths differ from just by about 15 cents.) Even better would be to be able to toggle between JI and ET.
A pretty good 12-tone just scale is to use 1:1, 9:8, 16:15, 6:5, 5:4, 4:3, 45:32, 3:2, 8:5, 5:3, 9:5, 15:9, and 2:1 is the octave. (Multiply the ratio by the frequency of whatever your root note is.) Though notably on a violin you run into a complication with the open E string. If the G string is 1:1 and the strings are all tuned in fifths, they're 1:1, 3:2, 9:4, and 27:8. 27:8 is octave-equivalent to the pythagorean major sixth 27:16 rather than the simpler 5:3 major sixth that goes better with the rest of the scale. So, if you go with a just scale there's a potential for people to be confused about why their open E string seems to be out of tune (and the answer is that unless they're deliberately trying to play a pythagorean major sixth it probably is).
The first scientific experiment in history* was on the topic of harmony/tuning. It was conducted by Pythagoreans who forged bronze chimes in different ratios of thickness, in order to demonstrate the generalization of Pythagorean number theory.
Yet, modern science still can't measure the harmoniousness of a song at a given point or overall -- we have neither the theory nor the math to do so. It is an active area of scientific research! I find that so cool.
* hypothesis-driven empirical test of a mathematical model
I tune my guitar by matching harmonics of adjacent strings. I dont recall which ones, but E-A, then A-D, D-G. Then take the 4x of low E and match open high E to it. Finally use harmonics to match B-E. This can leave G a bit off depending what you're playing. The E-E is a nice way across the gap.
I wrote this for my wife who is learning to play viola (I play violin at a barely endurable amateur level). It was to help her improve her intonation. As you play it draws the notes that you are playing on the musical staff, coloring them black for in tune, red for sharp, blue for flat.
It's one single html/javascript file, no server.
This page works on my Thinkpad/Ubuntu laptop, but won't work on my Android phone, I don't know why. It probably won't work if you try to sing into it rather than play an instrument because the human voice is so complex, in terms of its wave form. I guess. I'm a barely endurable amateur in this domain too. But if you have a musical instrument handy, it might entertain you for a few minutes.
I took up the violin just a few years ago---my midlife crisis: neither cheaper nor less noisy than a motorbike---and it's been fascinating to dive into the maths of music in a way that my school music teachers were never able to satisfactorily explain.
At first I too was tempted to build an app just like this, but when I mentioned this to my teacher, she made it very plain that the only way to learn intonation is: hear, move fingers, repeat. Anything that gets in the way of making that feedback loop as tight as possible---devices, tuners, even conscious thought---is a distraction. In hindsight I think she's right. Though I too am still a barely endurable amateur, my intonation has improved to the extent that it feels like I have grown a new organ in my brain that connects my ears directly to my fingers.
Hey, just wanted to let you know that this worked on my Android phone (Pixel 4 XL running stock Android 11 and in Chrome) after I granted microphone permissions. I whistled a few bars and was grossly out of tune so I know it's working ;)
Very nice work! There seem to be some issues for me with the lower strings on guitar: the low E registers as a B, for example. Higher strings seem to work well though. Not totally sure what's going on, but could probably be attributed to mic quality :)
Edit: after more playing around (heh) it does start to pick up the almost-E notes, F, G, etc. but is a little inconsistent. I tried monitoring the mic and even recording to play back what got picked up, and it sounds just as clear as the higher notes. Maybe something numerical happening in the Javascript fft?
Note that the most natural way to sing or play a fretless instrument isn't exactly 12 tone equal temperament. For example, if you play a major triad C-E-G as consonantly as possible, the frequency ratios C:E:G will be 4:5:6, which means 386 cents for C-E and 316 for E-G, instead of 400 and 300. The difference is quite audible. So be careful telling people they're 15 cents sharp or flat, as it's actually what makes the thirds and sixths in classical music sound so sweet!
Yes, sure. And TBH, even though I wrote this for my wife learning viola, I have since banned her from using it (don't worry - I have no power, she completely ignores my ban). I encourage her to use her ears rather than her eyes for monitoring her pitch, cuz, irl, that's what has to happen.
If you're playing Western music and you want to play in many different keys without re-tuning for each key, then you probably want to tune to equal temperament. If your goal is to play a single triad by yourself as consonantly as possible, then indeed, using small integer ratios is probably the way to go.
Great idea, I love the idea of getting real-time transcription of what I'm attempting to play.
As others have commented, it seems to struggle with the low E and A strings of guitar. Thinking about this:
1. The smallest note interval is from open low E (82Hz) up to the next semitone (82*(2^(1/12) -1)), which is about 5Hz. This gives the maximum bin width.
2. The guitar range is approx 4 octaves, ie up to about 330Hz. The min sampling freq must be double this.
3.In practice the bin edges wont line up with the semitone boundaries, so we ought to aim for bin widths smaller than half of 5Hz above, say 2Hz. This guarantees that a bin exists that doesn't cross semitone boundaries.
4. As lower frequencies probably wont be sampled across an integer number of cycles, spectral smearing will occur. This can be reduced by making the binwidth even smaller, and by use of windowing in the time domain.
5. My environment has background noise (eg computer fan). Unless the noise is filtered out pre-sampling (which it probably isn't for most users) then this will fold back into the signal of interest. Sampling at a higher rate than 2 x 330Hz would allow separation of the noise from the signal. I'm not sure what sample rate is used in the app. If the noise goes up to 4kz (I'm guessing) then this implies a sample rate of 8kHz to remove it.
6. From the above: sample at 8kHz for 1 second, use a window funtion to reduce spectral leakage. 8192 samples is a handy power of 2. Smaller sized ffts are likely to struggle to identify the right bin at lower frequencies, and/or have more noise in the signal band to confuse the peak detector.
7. An oscilloscope display would be handy to verify that signal levels were ok, and that noise isn't too intrusive.
It might be worth exploring some consistency measurements. So for example if a tune is in the key of C major, people can have fun arguing about what pitch E should exactly be. But if the note is repeated in the melody but played with changing pitch then generally it will sound out of tune.
So something like a variance of pitch per note measured at the end.
In particular, something like Bach's cello suites tend to highlight these sort of intonation issues.
It's not free, but I think the functionality is a bit better than this. It handles fast passages and can change temperament, show how off you were, etc.
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.
I'm a complete novice, but I remember hearing that we actually like to hear music ever so slightly off key. What does this analysis tool say for expert recordings?
I was interested in this so did some empirical work-- yes, people consistently prefer mild dissonance over perfect consonance -- at least with combinations of 3 sawtooth waves. Perfect consonance sounds colder while very slightly off tune sounds richer. It's an obvious effect (try it with a generator) but would be unrelated to violin playing
I think what you are referring to is "temperment", and a TLDR version of that topic would be that for tuning a piano so that it can sound in tune no matter what key, it is tuned to be evenly out of tune everywhere, aka, "equal temperment". This little app follows equal temperment. A string player playing unaccompanied solo might tend to play in a way that sounds better, aka, "just temperment", and so would seem to be out of tune according to this tool.
The sax can be a demon to play properly, it will warm up over the course of playing so you will end up going flatter and flatter as you play longer but you can correct for that with your embouchure or alternate fingerings.
If you can re-tune (fourth line 'F') after you've warmed up the instrument. You do that on that F because it is roughly in the middle of the range of the instrument meaning you'll be off the minimum on the other notes. If you tuned it on the highest or lowest note the other end would be off considerably.
The sax is a wonderful instrument but it is definitely a finicky one, I've never found one that had all the notes in tune when played without corrective measures, and I'm not even sure that it could be done, the flexibility you get in making it go sharp or flat on purpose comes with the price of having to correct almost every note you play.
You'll be unlikely to be more than a quarter-tone out of tune though, no? I used to practice saxophone with a tuner to enforce intonation consistency; I could intentionally bend notes further, but I don't recall the tuner ever picking me up on the wrong note when I was playing naturally.
I coded for transposing up or down by an octave, but not by other intervals. I imagine it wouldn't be hard for somebody to fork/modify the code to transpose by thirds, etc.
[+] [-] elihu|5 years ago|reply
It looks like the app uses 12-tone equal temperament as the standard for "in tune". For violin it would probably be better to use a just intonation scale as the reference rather than ET. (ET major and minor thirds and sixths differ from just by about 15 cents.) Even better would be to be able to toggle between JI and ET.
A pretty good 12-tone just scale is to use 1:1, 9:8, 16:15, 6:5, 5:4, 4:3, 45:32, 3:2, 8:5, 5:3, 9:5, 15:9, and 2:1 is the octave. (Multiply the ratio by the frequency of whatever your root note is.) Though notably on a violin you run into a complication with the open E string. If the G string is 1:1 and the strings are all tuned in fifths, they're 1:1, 3:2, 9:4, and 27:8. 27:8 is octave-equivalent to the pythagorean major sixth 27:16 rather than the simpler 5:3 major sixth that goes better with the rest of the scale. So, if you go with a just scale there's a potential for people to be confused about why their open E string seems to be out of tune (and the answer is that unless they're deliberately trying to play a pythagorean major sixth it probably is).
[+] [-] recursive|5 years ago|reply
The good thing about just intonation is that it's always the same. No configuration.
[+] [-] ctrager|5 years ago|reply
[+] [-] dr_dshiv|5 years ago|reply
Yet, modern science still can't measure the harmoniousness of a song at a given point or overall -- we have neither the theory nor the math to do so. It is an active area of scientific research! I find that so cool.
* hypothesis-driven empirical test of a mathematical model
[+] [-] phkahler|5 years ago|reply
[+] [-] ctrager|5 years ago|reply
This page works on my Thinkpad/Ubuntu laptop, but won't work on my Android phone, I don't know why. It probably won't work if you try to sing into it rather than play an instrument because the human voice is so complex, in terms of its wave form. I guess. I'm a barely endurable amateur in this domain too. But if you have a musical instrument handy, it might entertain you for a few minutes.
[+] [-] adonovan|5 years ago|reply
At first I too was tempted to build an app just like this, but when I mentioned this to my teacher, she made it very plain that the only way to learn intonation is: hear, move fingers, repeat. Anything that gets in the way of making that feedback loop as tight as possible---devices, tuners, even conscious thought---is a distraction. In hindsight I think she's right. Though I too am still a barely endurable amateur, my intonation has improved to the extent that it feels like I have grown a new organ in my brain that connects my ears directly to my fingers.
[+] [-] 2data222|5 years ago|reply
[+] [-] wsinks|5 years ago|reply
I found for me that with sensitivity at 20 I can hit every note perfectly! This is a fun tool to quickly go from a melody idea to a DAW now.
I'm very impressed, I've shared with my social as well because I thought it was so cool! Thank you for sharing your work.
[+] [-] jtanderson|5 years ago|reply
Edit: after more playing around (heh) it does start to pick up the almost-E notes, F, G, etc. but is a little inconsistent. I tried monitoring the mic and even recording to play back what got picked up, and it sounds just as clear as the higher notes. Maybe something numerical happening in the Javascript fft?
[+] [-] jacquesm|5 years ago|reply
[+] [-] loco5niner|5 years ago|reply
[+] [-] unknown|5 years ago|reply
[deleted]
[+] [-] cousin_it|5 years ago|reply
[+] [-] ctrager|5 years ago|reply
[+] [-] tshaddox|5 years ago|reply
[+] [-] whiw|5 years ago|reply
As others have commented, it seems to struggle with the low E and A strings of guitar. Thinking about this:
1. The smallest note interval is from open low E (82Hz) up to the next semitone (82*(2^(1/12) -1)), which is about 5Hz. This gives the maximum bin width.
2. The guitar range is approx 4 octaves, ie up to about 330Hz. The min sampling freq must be double this.
3.In practice the bin edges wont line up with the semitone boundaries, so we ought to aim for bin widths smaller than half of 5Hz above, say 2Hz. This guarantees that a bin exists that doesn't cross semitone boundaries.
4. As lower frequencies probably wont be sampled across an integer number of cycles, spectral smearing will occur. This can be reduced by making the binwidth even smaller, and by use of windowing in the time domain.
5. My environment has background noise (eg computer fan). Unless the noise is filtered out pre-sampling (which it probably isn't for most users) then this will fold back into the signal of interest. Sampling at a higher rate than 2 x 330Hz would allow separation of the noise from the signal. I'm not sure what sample rate is used in the app. If the noise goes up to 4kz (I'm guessing) then this implies a sample rate of 8kHz to remove it.
6. From the above: sample at 8kHz for 1 second, use a window funtion to reduce spectral leakage. 8192 samples is a handy power of 2. Smaller sized ffts are likely to struggle to identify the right bin at lower frequencies, and/or have more noise in the signal band to confuse the peak detector.
7. An oscilloscope display would be handy to verify that signal levels were ok, and that noise isn't too intrusive.
[+] [-] munificent|5 years ago|reply
https://en.wikipedia.org/wiki/Autocorrelation
[+] [-] whiw|5 years ago|reply
The remaining figures still look ok though.
[+] [-] KyleBrandt|5 years ago|reply
So something like a variance of pitch per note measured at the end.
In particular, something like Bach's cello suites tend to highlight these sort of intonation issues.
[+] [-] rcheu|5 years ago|reply
It's not free, but I think the functionality is a bit better than this. It handles fast passages and can change temperament, show how off you were, etc.
[+] [-] ctrager|5 years ago|reply
[+] [-] jtchang|5 years ago|reply
Could you make the staff and notes a big larger? The colors also are really difficult to discern.
I like it!
[+] [-] ctrager|5 years ago|reply
[+] [-] toxik|5 years ago|reply
[+] [-] dr_dshiv|5 years ago|reply
[+] [-] ctrager|5 years ago|reply
[+] [-] analog31|5 years ago|reply
[+] [-] singingfish|5 years ago|reply
[+] [-] jacquesm|5 years ago|reply
If you can re-tune (fourth line 'F') after you've warmed up the instrument. You do that on that F because it is roughly in the middle of the range of the instrument meaning you'll be off the minimum on the other notes. If you tuned it on the highest or lowest note the other end would be off considerably.
The sax is a wonderful instrument but it is definitely a finicky one, I've never found one that had all the notes in tune when played without corrective measures, and I'm not even sure that it could be done, the flexibility you get in making it go sharp or flat on purpose comes with the price of having to correct almost every note you play.
[+] [-] InitialLastName|5 years ago|reply
[+] [-] ctrager|5 years ago|reply
[+] [-] costcopizza|5 years ago|reply
[+] [-] Finnucane|5 years ago|reply
[+] [-] ctrager|5 years ago|reply
[+] [-] matiasb|5 years ago|reply