Author |
Message |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Jun 05, 2008 12:00 pm Post subject:
Keyboard trainer Subject description: Test your pitch game |
 |
|
Here's a little game I've made: the ChucK program will play one or more notes and you're supposed to play back the same notes on your MIDI keyboard. If you press the S key, statistics are printed out. You configure stuff at the top of the file (parsing parameters is a nuisance and ChucK code is easily read anyway). The app prints up to MIDI_DEVICE_AMOUNT of devices on startup, so you'll know what to input into MIDI_DEVICE to make things work.
You can change the difficulty under the "Level variables" comment. I managed to keep around 50% hit ratio with max_small_step = 3, max_large_step = 5 and note_succession = 5. It's pretty challenging stuff (for me at least), but I've heard that you're supposed to be able to train pitch hearing, so maybe this app can be useful for that.
If you're feeling adventurous, try the scale_switch (if set to 100% notes are all over the twelve keys - impossible!) Oh yeah, there are some chord variables in there, but i haven't implemented those yet (don't know if I dare). Also, I planned making levels of increased difficulty, but I don't know if I want that anymore.
Maybe there are some piano teachers here with insight that could add some more pedagogic lessons to this? This feels like an obvious application - have you seen apps like this elsewhere?
/Stefan
Description: |
|
 Download (listen) |
Filename: |
keyboard_trainer.ck |
Filesize: |
7.66 KB |
Downloaded: |
505 Time(s) |
_________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Thu Jun 05, 2008 12:45 pm Post subject:
|
 |
|
I've tried an easier version where the computer plays the base C of the octave in question, an identifying note of that octave and finally the note you're supposed to guess.
So if you're supposed to guess the midi note 67 then the base C would be 60 and the identifying note would be 65 ( = 60 + 5 ) because 60 is the fifth (5) octave.
Computer plays: 60 - 65 - 67 (or C - F - G)
This way each note has an identity based on how those three notes sound together. I think it helps memorizing them too. _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Thu Jun 05, 2008 2:16 pm Post subject:
|
 |
|
Antimon, I skimmed thru your code. Comments? We don't need no stinkin' Comments! Haha that's from an old western movie. I enjoy all those nested phrases and understandable nomenclature.
If I were gonna do it, I'd do it with guitar and I'd start with level one in which you must pluck the right string. No left hand at all, just get the string right. Then I'd work up in complexity until reaching a Guitar Hero - like gameplay.
Wow this could be an advancement for ChucK in a way. A ChucK application that gives you a "Guitar Here" gaming experience with a *real* guitar! Wicked, dude!
As a matter of fact, I know a guy with a guitar and lots of time to program ChucK - it's me! To speak the truth, I've been laxing interest in the guitar practice out of boredom and slow progress, but if I had a game that could do this... hmmm! Maybe then my sweat blessing would come true and I'd be flying up and down the fretboard. Plus what better way to expand the ChucK user base than to offer a Guitar Hero - like package!
I think I'll code something up tonight. Thoughts, suggestions? _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Jun 05, 2008 3:36 pm Post subject:
|
 |
|
@frostburn: that sounds like a great lesson, and it wouldn't be hard to implement. Good for practicing other scales too, I imagine.
@inventor: nice idea! I've seen your posts about guitar experiments. All those teens (sometimes it seems like half the young male population around here) dreaming of being heavy metal stars would probably faint of joy if they saw something like a Bon Jovi solo-practicing program.
Yeah, I usually forget to comment my code thoroughly. The aim is to have self-explanatory code, but I often over-estimate those abilities, as I am reminded constantly when returning to old projects.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Thu Jun 05, 2008 3:55 pm Post subject:
|
 |
|
Antimon wrote: | @inventor: nice idea! I've seen your posts about guitar experiments. All those teens (sometimes it seems like half the young male population around here) dreaming of being heavy metal stars would probably faint of joy if they saw something like a Bon Jovi solo-practicing program.
/Stefan |
Stefan, glad you took my "comment" lighty, haha! A good ChucKist needs a good sense of humor.
I've given some thought to the program this evening. First of all, you start in a tuning level for which you get one point for each correctly strummed open-string note. You are free to advance levels up or down to match your desired skill attempt. Other levels include:
Code: |
o levels include:
o tune the guitar
o pluck the open string
o strum the chord
o pluck the fretboard note
o switch from chord to chord
o play easy songs
o play other songs
|
You get plus and minus points so if you're playing at your level your score might climb, but if you're above your level, you could get negative scores. Staying on easy levels too much is not rewarding because points awarded escalate exponentially with level.
I plan to create a fretboard in MAUI for this one. This will be the ChucKist version of Guitar Hero, haha! Any other ideas? _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Fri Jun 06, 2008 10:42 am Post subject:
|
 |
|
Well, I went ahead and did it, coded up 400 lines of MAUI code to create ChucK Guitar Hero. You'll see in the screen shot a scoreboard window with exit button and level selector, plus the fretboard. When an open string (indicated by fret 0) opens up, you play that note and if you do it right, ChucK hears the note and scores you a point. After a certain time (about 10 seconds) a negative point is added to the player score. So you gotta keep up, mistakes are tolerated, but there are limits to the forgiveness. Thoughts or suggestions anyone?
Description: |
Image of Guitar Hero, version 1 |
|
Filesize: |
231.43 KB |
Viewed: |
398 Time(s) |
This image has been reduced to fit the page. Click on it to enlarge. |

|
Description: |
The first version of ChucK Guitar Hero |
|
 Download (listen) |
Filename: |
Guitar_Hero1.ck |
Filesize: |
13.7 KB |
Downloaded: |
439 Time(s) |
_________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Jun 07, 2008 12:54 am Post subject:
|
 |
|
Antimon wrote: | All those teens (sometimes it seems like half the young male population around here) dreaming of being heavy metal stars would probably faint of joy if they saw something like a Bon Jovi solo-practicing program.
|
Ha! You evidently never set Guitar Hero loose on a girl! One female friend of mine let the dinner I so lovingly cooked get cold because of that game.
The annoying thing is that both my house-mates actually play real guitars as well so I'm a bit behind on them. At least Activision (who made GH) also trademarked "TurntableHero" or "DJHero" or some such name. I'll need that, Beatmania was never released in Europe beyond the crappy PS1 version.
@Inventor; GO! With dropping interface LED's! Great stuff. Regarding missed "correct" notes, considering that the issue in detecting right notes likely is that the fundamental doesn't turn out to be the loudest frequency (didn't look at your code yet) couldn't you give it a second try and see if perhaps the loudest frequency is one or two harmonics up? Then still call the note correct? _________________ Kassen |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 3:17 am Post subject:
|
 |
|
Kassen wrote: | @Inventor; GO! With dropping interface LED's! Great stuff. Regarding missed "correct" notes, considering that the issue in detecting right notes likely is that the fundamental doesn't turn out to be the loudest frequency (didn't look at your code yet) couldn't you give it a second try and see if perhaps the loudest frequency is one or two harmonics up? Then still call the note correct? |
Well, I have to play it more to get a real feel for it, but yes, that seems to be one of the primary failure modes. All I have is a simple algorithm for starters: a high-Q BPF centered at the desired note frequency. I use a running average on the frequency and observe it five times before calling it correct. I think I need to also attenuate nearby frequencies with a band-reject filter or somesuch thing. Anyway, I'll play with it - it is fun to play! My best score so far is 35, what's yours? _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Jun 07, 2008 3:26 am Post subject:
|
 |
|
Why not use FFT? _________________ Kassen |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 5:01 am Post subject:
|
 |
|
Kassen wrote: | Why not use FFT? |
Well, there's a reason. When I tried to use FFT to create a guitar tuner i found that it was very coarse or required a huge sample set to get down to that resolution. Also it is computationally expensive. However, yes, FFT is one of the tools in our toolbox to try out. First, though, i used band reject filters to reject unwanted armonics and they worked great. I looked on my scope and it turns out that the low "E" string has tons of energy in the third harmonic, the period looks more like the letter "m" than anything else, with an extra zero-crossing peak in the middle. Yuck!
So I added three band reject filters and they took care of that. I'm still getting some false positiiiives, but at least the basic notes are correctly identified. I'll keep workng on it... _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 10:00 am Post subject:
|
 |
|
Then again... I've experimented some more with it and proper note detection remains a mystery. Maybe your ealier idea of "riding the RMS" will be handy, and also the FFT may be useful even without the frequency accuracy. I'm going to have to really think this one out to make it work. PLEASE offer any suggestions you may have! Also, gameplay suggestions like "it would be cool if..." are welcome! _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
blue hell
Site Admin

Joined: Apr 03, 2004 Posts: 24468 Location: The Netherlands, Enschede
Audio files: 297
G2 patch files: 320
|
Posted: Sat Jun 07, 2008 10:18 am Post subject:
|
 |
|
Some wild ideas ... no idea if it would or could work.
How about successive FFT detail-ation, do a rough transform to see where your peak is and then zoom in on that frequency interval only with twice the detail. You might have to code your own transform here ...
Or how about deducting a fundamental from a range of peaks. Tricky if only odd harmonics would be present ... _________________ Jan
also .. could someone please turn down the thermostat a bit.
 |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 10:34 am Post subject:
|
 |
|
Blue Hell wrote: | Some wild ideas ... no idea if it would or could work.
...
Or how about deducting a fundamental from a range of peaks. Tricky if only odd harmonics would be present ... |
Yes, something along those lines might work. I did some research and found out that the following list contains all of the possible fundamentals:
Code: |
[82.407, 87.31, 92.50, 98.00, 103.83,
110.00, 116.54, 123.47, 130.81, 138.59,
146.83, 155.56, 164.81, 174.61, 185.00,
196.00, 207.65, 220.00, 233.08,
246.94, 261.63, 277.18, 293.67, 311.13,
329.63, 349.23, 369.99, 392.00, 415.30,
440.00, 466.16, 493.88, 523.25, 554.37,
587.33, 622.25, 659.26, 698.46, 783.99,
830.61, 880.00, 932.33, 987.77, 1046.50,
1108.73, 1174.66, 1244.51, 1318.51, 1396.91,
1479.98] |
All detected frequency peaks will be those or harmonics thereof, I would think.
Also I'm realizing that for the game to be fun and to really teach guitar, it has to recognize chords - so not just individual notes but full chords. Perhaps having an amplitude profile for each frequency and subtracting profiles one at a time would work. I don't know, clearly this is no easy task.
But it's worth it to create a Guitar Practice / Real Guitar Hero style game. More ideas, please, I need 'em! _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 10:38 am Post subject:
|
 |
|
A comb filter, though new to me, sure looks interesting...
http://en.wikipedia.org/wiki/Comb_filter
it could pick out an individual string based on its fundamental frequency...
Things that make you go hmmmm..... _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 11:45 am Post subject:
|
 |
|
Hot dog! The comb filter worked. I just comb filtered with negative feedback and positive coefficient at the expected freqency, and it created a guitar signal grabber thingie! Then I just take the RMS and divide it by the overall signal to get a ratio that can be compared to a threshold. There are rare occasions when I get a false success note, but those are tolerable. Whew, with the right inspiration and a little Wikipedia, that problem is solved! _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sat Jun 07, 2008 12:21 pm Post subject:
|
 |
|
Inventor wrote: |
Kassen wrote: |
Timewarping Frostburn wrote: | Nested quotes are fun! |
Why not use FFT? |
Well, there's a reason. When I tried to use FFT to create a guitar tuner i found that it was very coarse or required a huge sample set to get down to that resolution. |
Actually even short windowed FFT can detect frequencies pretty well if you can do the math on phase shifts between hops.
I think I could work on my FFT pitch tracker a little more and post it for you. (Don't hold your breath though, it still has some nasty quirks to be worked out)
Btw. shouldn't there be a text based version of Guitar Zero for us Linux chuckers. _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 12:49 pm Post subject:
|
 |
|
Frostburn wrote: | Btw. shouldn't there be a text based version of Guitar Zero for us Linux chuckers. |
Haha, I thought of Guitar Zero also, but I dunno what to call it. Guitar Zero would be OK for now. I'll see if I can strip off the GUI and make a text version! _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sat Jun 07, 2008 2:05 pm Post subject:
|
 |
|
The improvement my FFT pitch tracker needed turned out to be too expensive computationally... Scrap that... sorry.
@feature requests: ChucK needs a fundamental extractor UAna.
I tried the Linux version... my score just keeps going up no matter what I do. How is it supposed to work? _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 2:21 pm Post subject:
|
 |
|
Frostburn wrote: | I tried the Linux version... my score just keeps going up no matter what I do. How is it supposed to work? |
If you do nothing, the score should slowly go down. Perhaps you are playing the radio or TV? I noticed that when I played heavy metal songs, my score went up in response to the music. It may be necessary to adjust the signal_threshold and noise_threshold variables to suit your volume and background noise. The noise_threshold value says any signal below this threshold is ignored, and the signal_threshold value says what the comb filter output to signal output ratio should be for a correctly scored note.
I would guess that there may be more noise in your setup/microphone or whatever, so random room noise is being considered as guitar signal. Hmmm this can be tweaked out but the algorithm should be more robust for sure!
Please let me know if you can adjust it so that it works, thanks. _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 2:43 pm Post subject:
|
 |
|
Hmmm, it occurs to me that the algorithm may be flawed. For a desired guitar signal, the comb filter output divided by the overall signal output would be greater than 5 because the algorithm is working. However, any noisy input will also pass the algorithm because of the gain of the comb filter.
I still think the comb filter is the cat's meow for this application, but clearly a guitar game that just adds up scores in response to arbitrary music/noise is lame and needs some work! Getting there, just not there yet. Suggestions welcome as always. _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sat Jun 07, 2008 2:51 pm Post subject:
|
 |
|
Distortion can do the trick of producing the missing fundamental.
I verified with the following patch:
Code: | //TriOsc with filters and distortion
TriOsc t => BRF bfr => Gain div => BPF bpf => dac;
bfr => Gain sum => div; 4 => div.op; //output(t) = t/(1+abs(t))
Step unity => sum; 1.0 => unity.next;
bfr => FullRect abs => sum;
t.freq() => bfr.freq;
2.0 => bfr.Q; //Get rid of the fundamental
t.freq() => bpf.freq;
10.0 => bpf.Q; //Only pass the fundamental through
while(ms => now){
bfr.gain()+0.005 => bfr.gain; //Listen how distortion recovers the missing fundamental
} |
The lowest frequency that a distortion patch can produce is the greatest common divisor of the input frequencies. For a single harmonic voice this is the fundamental. I need to test a bit more to see if it handles noisy input well.
If you only play just tuned chords (so that they have a GCD) distortion with a band pass filter on the GCD frequency might do the trick of detecting them... But then you could cheat by playing bass notes instead.
EDIT: @Inventor: Just compare the signal's strength to the comb filtered signal's strength. If the unfiltered signal is too strong then the player is cheating by blowing in to the microphone. _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 3:44 pm Post subject:
|
 |
|
Frostburn wrote: | EDIT: @Inventor: Just compare the signal's strength to the comb filtered signal's strength. If the unfiltered signal is too strong then the player is cheating by blowing in to the microphone. |
@Frostburn: I tried your code and didn't fully understand it, but sure enough you hear a signal emerging from nothing. Also, I tried something similar to what you said above. Actually I took the ratio of the signal strength of the feedback vs. feedforward comb filters. One grabs the harmonics and the other grabs everything else. It works great!
I even tried playing various rock music with and without guitar picking, and the background noise didn't hurt a thing. Some mild peculiarities remain, such as the high e string is tougher to detect, plus there are rare false readings, but overall the comb filter approach is quite pleasing.
Thanks for your help, Frostburn! Now to do more with the program, hehe... _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 07, 2008 11:34 pm Post subject:
|
 |
|
I've got the Guitar Zero game to revision 9 which seems fairly stable, so I am posting it in both Linux/PC test form and Mac MAUI form. The Linux/PC version just stays in Level 1 while the Mac version starts in Level 0 and you can advance levels with the level button.
The program tells you a string number and a fret number and you are to play that note on your 6-string guitar through your guitar amp and let the computer's microphone hear the note. If correct the computer will beep, print an updated score, and advance to the next note. If incorrect you still have time to type the next note (total of one second) before the timeout, a buzzer sound, and an updated score.
I'm open to suggestions as to what to do next with it. Enjoy!
Description: |
|
 Download (listen) |
Filename: |
Guitar_Zero_Text9.ck |
Filesize: |
6.25 KB |
Downloaded: |
316 Time(s) |
Description: |
Guitar Zero for Mac miniAudicle |
|
 Download (listen) |
Filename: |
Guitar_Zero9.ck |
Filesize: |
16.49 KB |
Downloaded: |
279 Time(s) |
_________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
|