8 ms·
Show HN: Are you playing your violin (viola, guitar, etc.) in tune?
- ctrager 6y agoI 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.
- 2data222 6y agoHey, 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 ;)
- jtanderson 6y agoVery 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?
- InitialLastName 6y agoYou 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
- ctrager 6y agoFFT is configurable at the bottom of the page, but for me it gets unpleasantly laggy if I make it bigger than 4096
- InitialLastName 6y agoYep, that's the tradeoff. As with seemingly everything else, you can thank Claude Shannon for that.
- loco5niner 6y agoWay cool. Just tried it with my voice, and it actually tracked really well. Impressively kept up with me on the scales, but mostly red and blue, lol.
- ctrager 6y agoYou must have a very pure voice!
- loco5niner 6y agoDon't know about that, but I do have good vocal control :-)
- wsinks 6y agoPlay with the sensitivity up between 20-40. It should even out the red and blue for you!
- jacquesm 6y agoUI suggestion: exaggerate the 'flat/sharp' by drawing the note higher or lower on the stave and turn it green when it is in tune.
- shhsshs 6y agoAre 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!
- jacquesm 6y agoMoving 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.
- wsinks 6y agoI'm an avid whistler, and have always wanted this exact thing. Thank you for making something so quick and responsive! (chrome, Mac Catalina) 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.
- ctrager 6y agoBoth 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.
- deleted 6y ago[deleted]
- adonovan 6y agoI 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.
- ctrager 6y agoEven though I wrote the app, I agree with your teacher about devices, but no conscious thought?.
- analog31 6y agoI'll check it out with my cello when I'm not in a meeting. ;-) Of course we'll eventually need tenor and bass clefs, but certainly not an obstacle.
- jtchang 6y agoCool. I tried it with my viola but noticed the notes didn't appear correctly on the staff. Also it did jump a bit when I was playing a C major scale. Could you make the staff and notes a big larger? The colors also are really difficult to discern. I like it!
- ctrager 6y agoI'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.
- toxik 6y agoI'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?
- ctrager 6y agoI 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.
- dr_dshiv 6y agoI 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
- cousin_it 6y agoNote 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!
- ctrager 6y agoYes, 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.
- analog31 6y agoI 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.
- matiasb 6y agoAwesome!
- singingfish 6y agodoes it support transposing instruments? The sax - especially the soprano - can be very tricky to play consistently in tune.
- ctrager 6y agoI 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.
- InitialLastName 6y agoYou'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.
- ctrager 6y agoJust FYI, notice the configurable "Sensitivity" setting. The default of 12 let's you miss by about a quarter of a tone (half step) either way.
- InitialLastName 6y agoI'm just saying that if they're playing moderately accurately, the note will read transposed, but it will be correctly annotated as sharp or flat.
- singingfish 6y agoIt's not too bad usually, but correcting for drift within the instrument and over time as it literally warms up is a thing.
- jacquesm 6y agoThe 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.
- whiw 6y agoGreat 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.
- munificent 6y agoNot a DSP expect by any means, but I think you can do better pitch detection without using an FFT. Instead, you want something like auto-correlation: https://en.wikipedia.org/wiki/Autocorrelation https://en.wikipedia.org/wiki/Autocorrelation
- whiw 6y agoI'm not sure it is better, unless you can do autocorrelation in hardware without using an fft. This option is unavailable on standard PCs. If done in software then a simple implementation of autocorrelation is O(n^2). An efficient implemementation is O(n.log(n)) (it uses two ffts).
- costcopizza 6y agoA good amount of early Rolling Stones and Beatles records are not in tune, so I’m not either.
- elihu 6y ago> const r = Math.pow(2.0, 1.0 / 12.0); 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).
- ctrager 6y agoYou might enjoy this article: https://stringsmagazine.com/perfect-fifths-a-few-thoughts-on-tuning-your-viola-violinists-cellists-invited/ https://stringsmagazine.com/perfect-fifths-a-few-thoughts-on...
- phkahler 6y agoI 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.
- titzer 6y agoThat'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!
- 6y ago
- Finnucane 6y agoI play banjo, so, no.
- ctrager 6y agoThat's included in "etc"
- rcheu 6y agoI use http://intonia.com/index.shtml http://intonia.com/index.shtml for this purpose. It's available on Android/iOS as well. 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 6y agoI've tried it. It's all the good things that you say, but it's kinda hard to use/read. I was aiming at something that would be easy, immediate, fun.
- KyleBrandt 6y agoIt 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.