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).
I think you mean the reverse; equal temperament "just works" regardless of key and doesn't require configuration, whereas JI you have to specify a key, and there are many possible scales depending on which of infinitely many notes you want to include.
It's a tradeoff between convenience and optimally consonant harmonies. ET makes a lot of sense for guitar because you have fixed frets (though JI guitars do exist), but violin can be played in any intonation so there's less reason to use ET unless you're accompanying an ET instrument like piano or guitar.
It's more that they're equally out of tune in every key. What actually sounds "best" for a given key (though certainly a little strange and unusual given the pervasiveness of equal temperament) would sound quite out of tune in other keys.
With pianos there are actually two things going on. They're tuned approximately to 12-tone equal temperament, but also the octave is stretched due to the inharmonicity inherent in the strings. (In the middle-range the strings are pretty well behaved, but in the high treble they start acting more like metal cylinders than ideal strings, and the bass has wound and double wound strings to similarly mess things up. The result is that the harmonics of piano strings aren't exactly multiples of the fundamental frequency, and so the tuning is stretched so that harmonics of lower notes more closely match the fundamentals of higher notes.)
There are plenty of people that care about convenience. Pianos are generally tuned to equal temperament. If that's what you're saying sounds good to humans, why bother with all the fancy stuff?
Well, just intonation generally sounds better to humans. A person playing violin would tend to naturally migrate to JI voicings of intervals whether they're consciously doing it or not. So, a tool that tells you whether you're "in tune" or not should ideally not tell someone they're out-of-tune when if they play in perfect JI.
On the other hand, if the goal is to just be in the general ballpark and accuracy of +/- 15 cents or so is just rounding error, then ET is probably fine. (My own violin skills are pretty rudimentary, so ET would be good enough. But if I were better I'd probably want a JI tuner.)
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
>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.
What about consonance and dissonance? We have both the math and the music theory for those. Wouldn't that be a measure of harmoniousness?
It's complicated. We can calculate the dissonance (e.g., harmonic entropy) for specific note combinations, but even the best models of consonance and dissonance don't correspond perfectly with human ratings -- nor can be applied to complex sounds.
There isn't a meter capable of showing how consonant or dissonant a song is, at any point in time -- or for the song as a whole.
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.
That's a good way to tune your ears, too. For G you can use an electric tuner and just memorize the slight dissonance between G and B.
I do highly recommend getting a clip-on electronic tuner, because if you want to change tunings quickly or you want to do drop D on a floating bridge, you are gonna need it!
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 ;)
Both my kids are software developers. I'm always trying to impress them. I copy/pasted your comment into our family WhatsApp channel to see if they would say, "Gee Dad, you are so cool!", but so far crickets.
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?
You need a longer FFT window to discern lower frequencies. Assuming a 44.1k sample rate and the default window size of 4096, you only get 10Hz buckets. Given that the low E is 82Hz, you effectively can't distinguish it from the D# at 78Hz and the F at 87Hz
Are you suggesting moving the tail higher/lower on the staff, or the whole note? The note should certainly not move up/down, though I think moving the tail would be cool!
Moving the note is a very good indication that it is off. You know you're playing a 'D', then you move the note until it is shown as a 'D' and green. Simplest user interface there could be.
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.
I play cello and double bass, the latter semi-pro.
What's more important is thinking about what has to happen. It requires your ears, brain, and body, to all work together, to put the right finger in the right place, consistently. Because you can't be in tune without being consistently in tune. Developing consistency is also what makes it possible to figure out what you're actually doing wrong, and correct it.
I think singing is a good exercise for ear training. There are YouTube recordings of virtually the entire student violin repertoire. Sing along. Get the tune in your head. Also, you can work on this any time, even away from the instrument.
Often overlooked is that intonation is intimately tied to technique because of the consistency factor. There are many schools of technique, but if you just pick one -- typically your teacher's -- and correct yourself when you deviate from it, you will become more consistent, and this will put you in control of playing in tune.
When I'm playing, and notice that I'm out of tune in a particular passage, I analyze what I'm doing wrong with my technique. This is something that never becomes "good enough," but is a lifelong compulsion. They interviewed Ray Brown near the end of his life, and asked why he still needed to practice. He said: "I still need to improve my intonation." That was from a master whose intonation was considered to be impeccable.
Now here's my contrarian view about temperaments. Engineers get worked up about them, but most musicians are ambivalent. Intonation transcends temperament because it has to do with controlling your body and sounding good. Only keyboard and electronic instruments have definite temperaments. String instruments have useful harmonic intervals in some keys (the "fiddle keys") but not others. Wind instruments are all over the place. I don't think there's a meaningful concept of "temperament" in an orchestra or jazz band. But when everybody is in tune, the band has a more powerful sound.
As a final comment: An adult should not expect to make progress at the rate that kids can. And I advise adult beginners to just avoid double stops -- they are not important enough to justify the mental and physical trauma.
Speaking of trauma, may I vent? So, my wife (my target audience for this app) is in the next room practicing even as I write this. It doesn't annoy me that she's out of tune. It annoys me that she doesn't stop, back up, correct when she plays a note badly out of tune. She can sing the pieces very accurately, but when she plays she is so lenient on herself. I don't get it, because in general she's kinda a detailed oriented perfectionist person who, not to stereotype, grew up in a a country known for detail-oriented perfectionism. I try to teach her (by shouting at her from the next room usually) to isolate the passages she gets wrong and then practice them super slowly. This is all really great for us as married pandemic housemates.
My spouse is also learning violin. Granted, dynamics vary from one family to the next, but still... you can't be her teacher. Likewise for parents of kids who are learning.
Imagine a code editor that, if it detects a syntax error, automatically erases the entire line, flashes some random pattern on the entire screen, and makes you start over.
It's brutal, because you're flooded with multiple concepts and difficult physical skills all at once, including tone production, intonation, reading, just hitting the right note instead of a wrong one, and so forth. Working on one thing may require blocking the other things out of your mind.
Learning a stringed instrument as an adult is very hard. I'm awed by anybody who can do it.
There's a great electric bass teacher named Jeff Berlin, who has also written about teaching, and he mentioned that he doesn't stop his students when they make mistakes, because correcting mistakes is something they can figure out on their own.
depends what the goals are. ideally yes, you would stop and focus on a difficult part to get it right. stopping and replaying the measure every time you make a mistake can create bad habits though. if you ever find yourself performing (especially in a group!), you want to be able to keep going after a mistake. nine times out of ten the audience won't notice a wrong note as long as you don't break the rhythm.
Speaking for myself (I've played violin for a long time) - it's simply more fun to keep going even if you know it's not the best way to learn. Stopping and making corrections, even if it is "better", can take a good bit of the fun out of it.
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.
Amusingly, I've seen violas da gamba that have double frets for handling temperaments in different keys. And there are some bagpipes that don't have a diatonic scale at all.
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.
This 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.
So 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.
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.
Have 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.
The 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.
The 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:
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.
I've got a yamaha bari that is amazingly consistently in tune with itself. My cheap soprano, less so, but there is a place for a loud bluesy slightly out of tune oboe from time to time.
A baritone has one advantage: it is so large that the relative precision with which it is constructed is high in relation to the frequencies that it puts out so being out a half millimeter on a valve seat will not immediately have a huge effect.
Also: have you ever thought about how undefined the frequency of a sax really is? The seal is a large, round flap that drops down over a circular hole with a raised edge. Even if you open it fast there is a gradient there and no matter what you do the hole itself is shaped to practically guarantee a different frequency response for every part of its circumference! It's a miracle it works at all (same goes for flute, oboe and clarinet).
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.
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).