|
You probably need to look at Fast Fourier transform to convert the input waveform into discrete levels for each 'note' currently being played.
|
|
|
|
|
THanks for the link. I'll read up on it. I've heard of FFT before but never understood it because I didn't have a particular application of it. Maybe I'll get closer to understanding this time.
|
|
|
|
|
FFT is a good technique to use but I am not sure how well it will work in this situation - using a Pi. You can probably get by with testing for fundamentals up to about 4K. The reasoning is the low E on a 4-string bass is ~40Hz, 80 for a guitar. Five octaves above that would be 2560Hz so, according to Mr. Nyquist, you need to sample at 5.1KHz minimum. Probably 6KHz or 8KHz would be better. If you do FFTs on 256 samples you would need to do 32 of them per second to keep up and that would mean bursts of data would come every 30mS. You will need to use the fastest Pi available to keep up with that. I might be thinking about this wrongly though.
There are a few free programs you can play around with to get an understanding of this. Here's one : Audio Spectrum Analyser[^] and here is another : Sound Frequency Analyzer[^]. I think there is source code for them available too.
|
|
|
|
|
That's really great info in your post. I'm going to read it again even more slowly.
The interesting thing is that this is not even running on an RPi. This is a MKR Zero which has a SAMD21 Cortex-M0+ 32bit low power ARM MCU (compared to RPi 3+ Quadcore ARM Cortex-A53, 64Bit)
|
|
|
|
|
The main things in there are the frequency range of interest which is summarized well on this page: Table of Musical Notes and Their Frequencies and Wavelengths[^] and the Nyquist sampling theorem which basically means you have to sample at a minimum of twice the frequency of interest. This is why the sample rate of CD audio is 44.1KHz in order to reproduce frequencies of up to 20KHz. That sample rate caused some other major issues but it was the best technology could do in the early 1980s.
|
|
|
|
|
Exactly.
The code shown will give a readout of the DC (static) input voltage, it will not tell you anything about the tone signal.
To sample the input at a decent frequency, forget about using analogRead(). It can't sample faster than about 9000 Hz. You will need to set the ADC in free-running mode and after the necessary code changes to support that, you then need to see how much RAM you have availble for sampling, and how fine-grained an FFT you can do on that given the limited processing power you have.
Let's assume that you can get a fine-grained FFT. If you play a single string on the guitar it will be fairly simple to determine the base frequency and convert that to MIDI. Now strike a chord. Now you have six different strings that all produce base frequencies and overtones and you need to deconvolute them.
To produce correct MIDI you have to do all this in real-time. The delay from string-played to MIDI-produced has to be below 10 ms if you want to use the MIDI signal to trigger a guitar synth or another instrument without noticeable delay. If you "only" want to record and can live with a fixed larger latency, fine, but you still have to be able to process all input in real-time.
One of my friends has a home studio and he uses a piece of software that can analyze all kinds of instruments and e.g. split a guitar voice into the respective strings and display what is played as finger settings. Really awesome, but of course, it costs .
You can buy dedicated hardware to plug into your guitar that outputs MIDI for around $100. Just saying ...
|
|
|
|
|
So have you realized yet that musical notes on the Western scale don't really correspond to any absolute frequencies?
They're relatively tuned, to each other on the scale by ratio, not to a fixed frequency. Even if you assume that A=440, what temperament are you going to use? Just intonation won't work out right on a fretted instrument, you know.
It's a complicated problem, aside from the programming. There are commercial products that do this, but they all involve compromises. Also, latency is a big problem with these things, so there's that too.
|
|
|
|
|
Right, I know there basically is a solid way to say XXX frequency is a particular note. I know that A=440Hz but then where do you go from there?
And yes, you are also correct about the latency issue because you have to do so much sampling and there is noise to deal with and all the rest. It is an interesting experiment to try and to think about though.
|
|
|
|
|
raddevus wrote: I know there basically is a solid way to say XXX frequency is a particular note
Not really, or at least only if you make certain assumptions. From the perspective of music theory that isn't correct at all.
Warning: below is a little clarification about technicalities and theory, but for the practical purposes of what you're doing you don't really need to take this into account for most cases. I think it's worth mentioning though while we're discussing notes and frequencies, because there are some misunderstandings here. And, yeah, I have a bit of a thing about this because it's a common misconception that bugs me.
You can easily find tables of frequencies matched to notes on the scale, but they are lies told for practical purposes and convenience. In reality, there is no defined frequency for any note, there are just arbitrary standards that can be--and often are--ignored by musicians in practice.
The A=440 thing is a relatively recent convention designed to make it easier for musicians to play together while being in tune with each other. It's just a convention, and it's far from universal. For the purposes of a MIDI pickup, though, it's safe to assume that A=440 unless the guitarist is into archaic or oddball tunings.
That's the easy part, though. The real problem is that the Western scale is based on ratio intervals between notes rather than any absolute pitches (frequencies), and the intervals change with each key, which can require the notes themselves to change frequency to be perfectly in tune for a particular key. That is, E-flat in one key may be a slightly different frequency than E-flat in another key, if you want perfect consonance with the other notes on the scale. You might think that's crazy, but it's true, and it's the reason for things like blue notes in jazz.
Microtonal instruments like voice, violin, trombone, etc. automatically adjust pitch for each key, because intonation is done by ear and your ear will tell you to adjust the intonation for each key, musicians do this automatically. But fretted and keyboard instruments are another story, they have discrete pitches that they can play with little wiggle room, and so the musician can't adjust on the fly and it's impossible to tune them so that they are in tune in every key.
This is why every piano in the world is out of tune, always, and if you don't believe me ask a piano tuner. The only way to make a piano truly in tune is to re-tune it every time you change the key being played in, but since that isn't practical pianos are normally tuned in such a way to spread the inaccuracies evenly over the whole range of the instrument to keep the problem minimal (this is called even temperament, and this is what those frequency-to-note tables are based on, and that's why those tables are lies).
So, no, there is no real mapping between frequencies and notes on the scale, not technically. But by convention and practicality much of this is hidden unless you have a good ear and/or an interest in music theory. The upshot, though, is that you should take those frequency/note tables with a grain of salt and not try to match the frequencies too exactly. However, using such a table should work just fine if you are using it with a guitar tuned to A=440 and even temperament. But it won't work for all cases, and anyway I think it's best to understand that notes aren't defined by frequencies if you're really going to get deep into this kind of thing.
modified 19-Oct-18 14:03pm.
|
|
|
|
|
That's a great read but my original statement was a mistake:
raddevus wrote: I know there basically is NOT a solid way to say XXX frequency is a particular note
I left out the word not. Oops.
I learned a lot about pitches, instruments, tambre from my time at Berklee College of Music and from David L Burge (Perfect Pitch Ear Training SuperCourse: Name EXACT Notes by Ear.[^]).
|
|
|
|
|
Haha!
Well, you gave me an excuse to go on a rant about even temperament, so that was fun at least
|
|
|
|
|
|
Bit shift 5 is the same as divide by 32. (only faster)
It is taking 32 samples, and calculating the average.
|
|
|
|
|
englebart wrote: Bit shift 5 is the same as divide by 32. (only faster)
It is taking 32 samples, and calculating the average.
Yes!! Nailed it on both accounts.
It's a nice little piece of code from the sample.
|
|
|
|
|
This picture is a screen shot of the default Git Bash console on my Windows 10 desktop. Does anybody, even on the Git maintainers team, honestly expect people to like these colors? What were they thinking when they picked them? Please tell me they were on drugs, and can't be held responsible!
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
|
Yes, it does. Long live the CGA color scheme.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
DBase IV
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I do... It took me a while to configure a similar configuration on my Debian. I would ditch the red though, on a black background it's eyeburning (discovered the hard way when I set up bash for a red on black text. 15 minutes later I was back to green on black).
GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
modified 4-Sep-18 4:20am.
|
|
|
|
|
den2k88 wrote: red though, on a black background it's eyeburning
The default Git bash colors are really terrible on Windows.
I had an issue even being able to see the text, just as you said...red on black background can barely even be seen.
I don't think the colors were ever "tested". Just like they were set and never looked at by the design team. Makes no sense at all.
I finally chose the dracula theme. That one should really be the default.
|
|
|
|
|
With the exception of red that is quite common in bash highlighting, even in full terminal mode I remember those colors.
GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
What do you think of Blue text on a Black background? Moreover, there are other low-contrast colors, too. It just sucks.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
The Chocolatey warning message shown here is much easier to read. IMO, their maintainers have a much better understanding of the principles of good color selection than do the Git maintainers. Though Chocolatey has some lapses, given their characteristics, I suspect they are actually caused indirectly by calls into PowerShell.
Several years ago, I made a study of console mode color combinations, for which I created a program that ran through every possible combination of foreground and background ConsoleColor settings. Maybe it's time for me to write about it.
David A. Gray
Delivering Solutions for the Ages, One Problem at a Time
Interpreting the Fundamental Principle of Tabular Reporting
|
|
|
|
|
The bluescreen isn't blue without a reason: You will find in a lot of books on graphic design that white on blue is one of the most readable color combinations. Black on yellow is another combination at the top of the list. I don't remember which of the two has the top score; it is a very close race.
So it should come as no big surprise that traffic signs very often are black on yellow or white on blue. Pink on black may catch your attention more easily, but if the text content is the essential thing, then green on black is far better, much more readable.
When I was still a student, I did all my programming green-on-black - we had no alternative (except for the card readers that were still available). A couple years later, black-on-white screens were introduced, but made no great success: Green-on-black, 25 lines of 80 chars, was the preferred choice until the arrival of VGA (and even a few years into the VGA era).
In my first job, when PCs had just been introduced, one of the old guys pointed to the Tandberg 2215 terminals: "Take a good look at these! You won't see anything that can match them, ergonomically, for the next ten years, at least." --- It turned out that he was right. Screens got more functions, more colors, more resolution, but it took more than ten years before we got the same readability, and even today, screens have higher functionality, but are no better ergonomically. (That is of course strongly affected by how we choose to use these screens - today, poor ergonomics are essentially caused by poor choices, not by screen technology.)
|
|
|
|
|
Black on yellow is tops I believe, that's why so many road signs are those colors.
|
|
|
|
|