| Author |
Message |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sun Jun 08, 2008 4:27 am Post subject:
|
 |
|
I worked a bit on the distortion approach and I've gotten to the point where my algorithm detects the correct pitch of my voice except for the vowel 'ah'.
The idea is to first filter the signal to emphasize low frequencies, then distort it to produce a stronger fundamental and finally filter it again to emphasize the fundamental even more.
So schematically:
| Code: | | adc => pre_filter => distort => post_filter => pitch_detection; |
For the distortion I use the sgn function and I detect the pitch from positive zero crossings of the output.
I'll work a bit more on this and post the results if they're any good. _________________ To boldly go where no man has bothered to go before. |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Sun Jun 08, 2008 10:08 am Post subject:
|
 |
|
It works pretty well except there is a warbling to the output sound. Still, another useful tool in detecting guitar notes.
My next scenario is as follows: The program has instructed the player to play a chord. The player plays a chord which may or may not be correct. How does the program determine if the correct chord has been played? I am thinking of using multiple comb filters for this, what do you think? Maybe instead I should use this distortion technique? I dunno, there is plenty of time to think about it. _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sun Jun 08, 2008 10:49 am Post subject:
|
 |
|
I think the comb approach is better for chords and even for single voices.
After all with games like these we are dealing with pitch verification which is easier than pitch detection.
I'll have to try the comb myself to get a feel on it. _________________ 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: 270
|
Posted: Sun Jun 08, 2008 11:34 am Post subject:
|
 |
|
| Frostburn wrote: | | I'll have to try the comb myself to get a feel on it. |
The wiki on it was excellent, dumbed it down enough so that even I could understand it, haha!
http://en.wikipedia.org/wiki/Comb_filter _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Sun Jun 08, 2008 1:25 pm Post subject:
|
 |
|
I tried it and it worked! Of course, I can't hold a tune but the indicator definitely changed as I applied audio to the microphone. These little games are fun! _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sun Jun 08, 2008 2:29 pm Post subject:
|
 |
|
I'd like to see someone make an algorithm that can detect/verify this on a real guitar.
Now that would be a live coding performance. _________________ 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: 270
|
Posted: Sun Jun 08, 2008 3:05 pm Post subject:
|
 |
|
Yes, that would be cool, perhaps with a bunch of comb filters all firing off in response to the song.
I want to add chords and then songs to Guitar Zero, but maybe that's asking a lot. The good news is that the song is known so that the filters can be set according to the chord or note that is expected. One major difference between Guitar Zero and Guitar Hero is that Hero reduces the instrument to five notes, while Zero preserves the full fretboard. This does, however, conceal future notes so that there is no stream to anticipate like in Hero. That's OK though. I dunno, I'll keep thinking about it and working 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: 270
|
Posted: Mon Jun 09, 2008 11:43 pm Post subject:
|
 |
|
I've got chords added to Guitar Zero now, though it's MAUI only now due to the complexity of maintaining two versions. Come on DEV TEAM, let's get that MAUI release out there! Patience is a virtue, sigh.
Anyway, I've now even added some rudimentary song learning capability and I have part of AC/DC's "Back in Black" song in there (what can I say, I'm a rocker).
The comb filters are working quite well. I switched to your recommendation, Frostburn, of dividing the comb-filtered signal by an unaltered signal to obtain a number that can be compared to a threshold. It's touch-and-go and could use some more work, but for now it's doing quite well.
The latest version can be found on my music web page which is here:
http://www.freedomodds.com/music/
Cheers! _________________ "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: 270
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Tue Jun 10, 2008 4:27 pm Post subject:
|
 |
|
I figured out the theta thing, i was casting to an int instead of a float, duh! I also added a vertical LED meter that continuously displays how close your sound is to passing the threshold of acceptance for a good note/chord. I also adjusted the filters a little and did some cleanup stuff. Aside from adding more chords and more songs, I'm not sure what to do with the program's development right now, so I'm asking for suggestions.
That goes for a whole new program too. If anyone can imagineer a good guitar-driven game that teaches, I might take a try at coding it up. Just let me know if you have any ideas. Can you tell I'm a little bored?
Oh, p.s. I found that playing some songs will actually trigger the note/chord detection, be it due to incorrect detection or due to the fact that the songs actually contain the note/chord being asked for by the program. "Pick up the Pieces" by Average White Band from the 70's is particularly good at playing Guitar Zero, and interestingly "Back in Black" by AC/DC does not play its own song very well in Guitar Zero, most likely because of timing delays. There I go rambling again... Cheers! _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Wed Jun 11, 2008 4:16 am Post subject:
|
 |
|
| Inventor wrote: | | Oh, p.s. I found that playing some songs will actually trigger the note/chord detection, be it due to incorrect detection or due to the fact that the songs actually contain the note/chord being asked for by the program. |
Have you made sure that:
a) Just blowing to the microphone doesn't generate positives.
b) Just playing one note of the chord isn't considered correct.
For a) you need the determine the "noise score" of your pitch detection patch and adjust the thresholds accordingly.
For b) you have to make sure that each comb has sufficient energy.
I noticed that on my patch noise gives a filtered/input ratio of 0.5 so I set the positiveness threshold to 0.75.
For chords I'd check that each string has filtered/input ratio of at least 0.5/number_of_strings and that the total filtered/input ratio is above 0.75.
I also noticed that you have in your code something like:
I don't know how that flies but string is the name of the character string type... ChucK shouldn't allow it to be used for anything else like the name of a variable here. _________________ 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: 270
|
Posted: Wed Jun 11, 2008 5:46 am Post subject:
|
 |
|
Frostburn, thanks for your time in looking at my code! You really have an eye for detail. I fixed the string problem (or potential future problem) by changing all references to str instead of string. As for blowing into the microphone, it does cause false positives if i get real close like two inches away and blow hard on it, or if i rub it with my thumb. Also, I did the other test and yes, just plucking one string of a chord will complete the chord! Darn darn darn!
I multiplied the acceptance threshold of the chords by the number of strings in the chord, but I can see that wasn't enough. The chord harmonics are all mixed together and the comb filter must not be being selective enough.
I have attached the latest source code. The comb filters begin at line 140. If you can spare a moment, would you mind just glancing over the filter implementation and/or thinking about it a little to offer some suggestions?
I know the thing sort of works because when I pluck incorrect strings it rejects them usually, even just one fret away, but that's individual notes. Chords are a different beast altogether. Thanks in advance if you can spare a moment to take a look, and thanks for your help already!
| Description: |
| The lates Guitar Zero source code |
|
 Download (listen) |
| Filename: |
Guitar_Zero23.ck |
| Filesize: |
30.57 KB |
| Downloaded: |
246 Time(s) |
_________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Wed Jun 11, 2008 7:02 am Post subject:
|
 |
|
Well for one thing you're using Delay instead of DelayL or DelayA, I suggest DelayA. You also forgot that feedback patches have one extra frame of delay.
So that's: second/freq - samp => my_DelayA.delay;
I need to study this pitch verification a bit more. I'll write a class that (hopefully) does it right and try to document it so that you can use it.
EDIT: I'm running to the problem where short bursts of noise create false positives... I'll work on it tomorrow. _________________ To boldly go where no man has bothered to go before. |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Wed Jun 11, 2008 4:27 pm Post subject:
|
 |
|
Wow, I tried it and it works great! I see what you mean about combs not differentiating between frequency multiples. Let's say we have your 12-comb filter running and we get a positive indication on one comb. Can we then post-process the output of that comb with band-pass filters or better yet an FFT to determine the octave of the note?
You see, I avoided an FFT approach because of frequency selectivity, however once we know the accurate frequency then the FFT peaks can be approximate in frequency bin placement.
Alternatively can we post-process a comb output with your warbling technique that you demonstrated earlier in this thread to enhance the fundamental?
Well, I'm sure you are giving these options some thought already. One thing to keep in mind is that in the particular application we can have a pause between notes to clear out the comb filter's delay line, which is what I am doing in my Guitar Zero program. This might be helpful if you end up needing a computaionally prohibitive amount of circuitry. We could just create a single filter and give it time to clear out between notes.
Thanks so much for the collaboration, Frostburn, this should really help to improve Guitar Zero and be a fine addition to your toolbox as well! _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Thu Jun 12, 2008 3:11 am Post subject:
|
 |
|
All I can say right now that surprisingly a chord acts as if it was more than just the sum of it's parts. But maybe that's the whole point of melodic music. You don't hear individual notes, you hear harmonies. It's just that we need to make our algorithm hear the notes from the harmonies.
EDIT: One part of the problem lies in the fact that the same chords sound different on different instruments.
EDIT: I'm running out of resources here. 12 combs is around the max my laptop can take at 48kHz. If only ChucK would allow different sampling rates in the same piece. :) I think I'd need over 50 combs to do even basic chord detection with a certain harmonic intersection method I had in mind...
I need to think of something more economical with fewer combs online... _________________ 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: 270
|
Posted: Thu Jun 12, 2008 4:10 am Post subject:
|
 |
|
Well, I think that perhaps you are solving the more difficult problem first instead of tackling the easier one first. Let's say that we *know* what note or notes are being provided by the guitar, and just build a detector for that. In this way we only need one comb filter instead of 12. That would be good enough to work with Guitar Zero, and we can later expand it to the general case. Good idea or no? Just a suggestion. Thanks again for the collaboration, you are more theoretical and more academic than I am, so I appreciate your abilities Frostburn. _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Thu Jun 12, 2008 4:29 am Post subject:
|
 |
|
Hmm... maybe I'm approaching this from the wrong angle.
Let's try it in the reverse.
Is this correct?
The input signal is a chord of three notes X, Y and Z if all of the following is true:
1) The input signal has a certain amount of energy so it is above the static noise threshold.
* We take frequencies corresponding to X out of the signal.
2) The signal still has some energy.
* We take Y out.
3) The signal still has some energy.
* We take Z out.
4) The signal has lost all of its energy. (Or is bellow a certain threshold).
If the process fails at 4) then the input is noise or an erroneous chord.
If it fails on 1), 2) or 3) then it didn't have enough notes to make the chord.
All we need is feedforward combs with alpha == -1.0 and some envelope followers.
Gotta try this one out.
EDIT: Oops. A signal of pure Z is considered a chord by the above algorithm sketch. Back to the drawing board.
EDIT2: How about this:
Stage one:
Test if the signal is pure X, Y or Z.
Stage two:
Test if the signal is a pure combination of ( X and Y ), (X and Z) or (Y and Z).
Stage three:
Test if the signal is pure (X, Y and Z)
Stages one and two need to fail but stage three needs to succeed for the signal to be a chord of (X, Y and Z). _________________ 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: 270
|
Posted: Thu Jun 12, 2008 6:40 am Post subject:
|
 |
|
| Frostburn wrote: | EDIT2: How about this:
Stage one:
Test if the signal is pure X, Y or Z.
Stage two:
Test if the signal is a pure combination of ( X and Y ), (X and Z) or (Y and Z).
Stage three:
Test if the signal is pure (X, Y and Z)
Stages one and two need to fail but stage three needs to succeed for the signal to be a chord of (X, Y and Z). |
I like that one! Looks like a winner to me, except there can be up to six strings not just three. But I definitely like testing for pure notes.
Will the following help: I just made a thingie out of 12 comb filters for my talking guitar program that auto-selects which filter to use, sort of. It does a FWR and a LPF on each filter's output to estimate that filter's signal strength, then adds those all up to get a normalizer, then divides each filter output by the normalizer, then finally multiplies each comb's output by the divided (normalized) value. It's not as good as picking the strongest one, but ChucK doesn't have a pick the strongest one function that I know of. See the talking guitar thread for an audio sample of it that I'm gonna post right after this post. Just a thought for your consideration. _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Thu Jun 12, 2008 9:24 am Post subject:
|
 |
|
| Frostburn wrote: | I think I got it!
The attached chuck file should congratulate you only if you manage to pull off a major chord of C-E-G. |
Great news! I tried to test it, but I don't know what a major chord of C-E-G is, doh! It's not on my chord sheet. What string and fret numbers do I put my fingers on for that one? _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
blue hell
Former site admin

Joined: Apr 03, 2004 Posts: 24864 Location: The Netherlands, Enschede
Audio files: 353
G2 patch files: 320
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 270
|
Posted: Thu Jun 12, 2008 10:02 am Post subject:
|
 |
|
nope, wasn't on there either. I changed the frequencies to match the open 6th, 5th, and 4th strings on the guitar and it worked like a charm! It recognized all combinations of the any two or any one, plus all three. All possibilities of a three-note chord uniquely identified. Excellent work, Frostburn! You da man!
Now how do we generalize it so that it works with up to 6-string chords? we can't do all combinations of six strings. Maybe we just exclude the single chords and anything else passes? No, that's not it. I am confused. Unfuzzle me brain please!
| Code: | ____ 3 _
., _ ' `_ _______ ( )
--+-[---------.---(-)-----(@)----|-------|--.-----|-------------.-------|~--
| ] | |~ |~ (@) _ | | |} | |
--+-[-----|---+---|-------|--|--(@)---------+-----|----------|}-+---|---|---
|/ | | | | | |~ (@) _ | | _| .. | | | |
--Y-------|---+---|-------|--|--|---|---(@)-+-|>( )------|---|--+---|-------
/|_ _| | `=_| | | |~ | ~ |>(@) | _|
|-@-)---(@)---+-----------------|---|---|---+-------------------+-(@)-------
\_|/ ~ | | | | | ~
--+-----------"-------------------------|---"-------------------"-----------
|
._} --jw
|
_________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
|