Pitch Tracking with a Guitar

Feb 12, 2007 at 5:37am

Pitch Tracking with a Guitar

I am trying to create a simple flash game that is controlled by playing specific notes on an electric guitar. I assume that I need to have some sort of pitch tracking program involved. Does anybody have any idea how I might go about doing this? Thanks.

-Derek

#30240
Feb 12, 2007 at 6:00am

fiddle~

On 2/11/07, DerekJ wrote:
>
> I am trying to create a simple flash game that is controlled by playing specific notes on an electric guitar. I assume that I need to have some sort of pitch tracking program involved. Does anybody have any idea how I might go about doing this? Thanks.
>
> -Derek
>

#96205
Feb 12, 2007 at 6:48am

fiddle?

#96206
Feb 12, 2007 at 7:18am

sorry for the ambiguity, there is an external by Miller Puckette
called fiddle, you can download it from the maxdatabase,

http://www.maxobjects.com/?PHPSESSID=f2b2a6b357376634fbe5341c5b8cd6a0&PHPSESSID=f2b2a6b357376634fbe5341c5b8cd6a0&request=fiddle&operateur=AND&id_plateforme=0&Submit=OK

this gives you midi pitch, db amplitude and other features you may
find interesting for your purposes, take a look at the help files.

j

On 2/11/07, DerekJ wrote:
>
> fiddle?
>

#96207
Feb 12, 2007 at 7:23am
#96208
Feb 12, 2007 at 7:50am

thanks alot! now anybody know how to make this control a flash video game? haha …anybody?

#96209
Feb 12, 2007 at 7:59am

you could also try [yin~] from the ircam library. I like that object more.

Bryan

http://www.techniquolor.com

http://www.ksod.net

#96210
Feb 12, 2007 at 8:19am

yes i heard it is better, although i don’t know why, but it isn’t
freely available, if someone knows why, a deep explanation would be
highly appreciated.

J

On 2/11/07, Bryan Teoh

wrote:
> you could also try [yin~] from the ircam library. I like that object more.
>
> Bryan
> –
> http://www.techniquolor.com
> http://www.ksod.net
>

#96211
Feb 12, 2007 at 9:54am

by the way, not why is it not free, but why is it better, if it is…

On 2/12/07, Jaime Oliver wrote:
> yes i heard it is better, although i don’t know why, but it isn’t
> freely available, if someone knows why, a deep explanation would be
> highly appreciated.
>
> J
>
> On 2/11/07, Bryan Teoh

wrote:
> > you could also try [yin~] from the ircam library. I like that object more.
> >
> > Bryan
> > –
> > http://www.techniquolor.com
> > http://www.ksod.net
> >
>

#96212
Feb 12, 2007 at 10:14am

#96213
Feb 12, 2007 at 1:50pm

DerekJ wrote:
> thanks alot! now anybody know how to make this control a flash video
> game? haha …anybody?

flash?


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#96214
Feb 12, 2007 at 3:18pm

The other object is pitch~ (or analyzer~) by Tristan Jehan.

I have a running average patch that uses that. It may not load analyzer~ so you’d have to get that from his website. You could build the same using yin~

Does anyone have any thoughts about the merits of yin~ versus say fiddle~ or analyzer. I’m also interested in guitar pitch detection.

Cheers,
Andrew

p.s. here’s the patch if you’re interested..

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 150 521 34 196617 % 12;
#P window setfont “Sans Serif” 20.;
#P number 150 557 53 20 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont “Sans Serif” 9.;
#P newex 158 493 27 196617 + 8;
#P message 189 358 34 196617 reset;
#P number 158 472 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 104 354 61 196617 average $1;
#P window setfont “Sans Serif” 18.;
#P number 103 320 35 18 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont “Sans Serif” 9.;
#P message 63 404 74 196617 print_average;
#P message 88 379 32 196617 print;
#P flonum 387 535 77 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 157 397 90 196617 mxj pitchmatrix2;
#P newex 283 616 124 196617 mxj quickie pitchmatrix2;
#P user ezdac~ 134 252 178 285 0;
#P user multiSlider 651 163 164 355 -96. 30. 25 2681 47 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P message 193 104 30 196617 open;
#P message 254 98 14 196617 1;
#P message 152 86 14 196617 0;
#N sfplay~ 1 120960 0 ;
#P newobj 199 195 44 196617 sfplay~;
#P newex 195 315 246 196617 analyzer~ 2048 512 4096 blackman70 0 1 10 3 list;
#B color 6;
#P window linecount 3;
#P comment 30 329 60 196617 frames for running average;
#P window linecount 1;
#P comment 80 570 100 196617 E string FRET;
#P window linecount 3;
#P comment 278 566 100 196617 you’ll need to code the mxj object quickie;
#P window linecount 6;
#P comment 420 604 100 196617 double click this , then paste in the Java code – will post that on the forum. Then click on Java > Compile;
#P connect 4 4 9 0;
#P connect 12 2 13 0;
#P connect 16 0 17 0;
#P connect 7 0 5 0;
#P connect 8 0 5 0;
#P connect 6 0 5 0;
#P connect 5 0 10 0;
#P connect 5 0 4 0;
#P connect 19 0 12 0;
#P connect 14 0 12 0;
#P connect 15 0 12 0;
#P connect 17 0 12 0;
#P connect 4 6 12 0;
#P connect 22 0 21 0;
#P connect 18 0 20 0;
#P connect 12 0 18 0;
#P connect 20 0 22 0;
#P window clipboard copycount 23;

#96215
Feb 12, 2007 at 3:21pm

You’ll need this Java code – click on the MXJ quickie object and delete what’s there, replace with this, click Java > compile. Should be green. Then MXJ pitchmatrix2 will load up.

It could help you get round the problem of having too many other notes show up. If you increase running average to say 20, then you’ll get less noise.

Hope that helps.
Andrew

/////////CODE /////////////

import com.cycling74.max.*;

public class pitchmatrix2 extends MaxObject
{

private int pitch_index = 0;
private float[] recent_pitch_array = new float[1000];
private float[] recent_pitch_amplitude = new float[1000];
private int [] rounded_pitch_array = new int[1000];
private int[] running_average_array = new int[1000];

private int round_pitch_int = 0;
private float recent_pitch_float = 0f;
private float recent_pitch_amplitude_float = 0f;
private int average_width = 5;

private int[] pitch_counter = new int[100];
private int running_average_int = 5;
private int last_pitch_integer = 99;

private int present_running_average;

private static final String[] INLET_ASSIST = new String[]{
“inlet 1 help”
};
private static final String[] OUTLET_ASSIST = new String[]{
“outlet 1 help”
};

public pitchmatrix2(Atom[] args)
{
declareInlets(new int[]{DataTypes.ALL, DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL, DataTypes.ALL, DataTypes.ALL});

setInletAssist(INLET_ASSIST);
setOutletAssist(OUTLET_ASSIST);

}

public void bang()
{post(“Bang”);
}

public void inlet(int i)
{
}

public void inlet(float f)
{round_pitch_int = Math.round(f);
post(“float rounded to “+round_pitch_int);
}

public void list(Atom[] mylist)
{
if (pitch_index<999){

Atom a;
a = mylist[0];
recent_pitch_float = a.getFloat();
recent_pitch_array[pitch_index] = a.getFloat();
a = mylist[1];
recent_pitch_amplitude_float = a.getFloat();
recent_pitch_amplitude[pitch_index] = a.getFloat();

///////// RUNNING AVERAGE CODE //////////////
round_pitch_int = Math.round(recent_pitch_float);
pitch_counter[round_pitch_int] += 1;
//post(pitch_index+” counter :”+round_pitch_int+” total “+pitch_counter[round_pitch_int]);
if ( (pitch_index – running_average_int)>=0 ){
last_pitch_integer = Math.round( recent_pitch_array[ (pitch_index - running_average_int)] );
//post(“last pitch “+last_pitch_integer);
pitch_counter [ last_pitch_integer ] -= 1;
}//end if

int max_index = 99;
int maximum = 0;
//get max///
for (int j = 99; j > 0; j–){

if (pitch_counter[j] > maximum ){
max_index = j;
maximum = pitch_counter[j];
// post(“new max :”+maximum+” at “+j);
}//end if
}//end for

running_average_array [ pitch_index ] = max_index ;
if (max_index != present_running_average){
post(pitch_index+” running av. = “+running_average_array [ pitch_index ]);
present_running_average = max_index;
}
//recent_pitch_amplitude[pitch_index] = mylist[1];

//post(“Pitch “+recent_pitch_array[pitch_index]+” ampl:”+mylist[1]+” index:”+pitch_index);
pitch_index += 1;

//post(“Round int :”+round_pitch_int);
outlet(1, round_pitch_int);
outlet(2, recent_pitch_amplitude_float);
outlet(0, max_index);
}//end if pitch<999
else{
pitch_index = 0;
for (int y =0; y<100; y++){
pitch_counter[y] = 0;}

for (int y = 0; y<1000; y++){
recent_pitch_array[y] = 0;
recent_pitch_amplitude[y] = 0;
}
}//end else
}

public void print()
{int k = 0;
while (k< = pitch_index){
post(k+ ” Pitch :”+Math.round(recent_pitch_array[k])+” Amplitude :”+recent_pitch_amplitude[k]);
k++;
}//end while

}

public void print_average()
{int k = 0;
while (k< = pitch_index){
post(k+ ” Pitch :”+running_average_array[k]);
k++;
}//end while

}

public void average(int i){
if (i > 0 && i<100){
running_average_int = i;
post(“Running average over “+i+” frames”);}
}

public void reset(){
pitch_index = 0;
for (int y =0; y<100; y++){
pitch_counter[y] = 0;}

for (int y = 0; y<1000; y++){
recent_pitch_array[y] = 0;
recent_pitch_amplitude[y] = 0;
}

}

}

#96216
Feb 12, 2007 at 7:39pm

#96217
Feb 13, 2007 at 5:13am

what do you mean by mxj quickie object?

#96218
Feb 13, 2007 at 5:47am

thanks for all the help everybody. and when i said “Flash Game” I meant a game created with Macromedia Flash. I just acquired Flash and I’m not familiar with the different formats yet. I suppose I would work with whatever format goes best with Max/MSP. Any suggestions? Thanks again

-Derek

#96219
Feb 13, 2007 at 2:02pm

Hi,

mxj is Max’s way of incorporating Java – so you can write your own objects but in Java, which is easier to learn than C.

You could try it on the code here or say try the following

1.type in a new box:

mxj quickie firstobject

2. now double click on it.

that will open a console with some code stuff in

3. in the code add the following to the bang section:

public void bang(){

post(“hey, first mxj object works”);

}

4. now click on JAVA > COMPILE

5. new console opens, click compile

6. Should come up green (no errors)

7. back in the max patch, make an object

mxj firstobject

8. send a bang to it.

9. look in the max printout screen

10. Note: if you now change the object. You need to delete it and paste it back to the screen for changes to take effect.

Check it out!

Cheers,
A.

#96220
Feb 13, 2007 at 8:59pm

On 13-Feb-2007, at 15:02, Andrew Robertson wrote:

> in Java, which is easier to learn than C.

Debatable. Granted, your example is quick, but by the time you want
to do something complex, it is often just as efficient to copy a
working C project and edit the processing routines.

YMMV. But I would think twice before making blanket statements. And
learning the *language* is definitely not easier than C.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#96221
Feb 14, 2007 at 7:30am

DerekJ wrote:
> thanks for all the help everybody. and when i said “Flash Game” I
> meant a game created with Macromedia Flash. I just acquired Flash
> and I’m not familiar with the different formats yet. I suppose I
> would work with whatever format goes best with Max/MSP. Any
> suggestions?

If you are fluid with Flash, you can do it in Flash and connect to Max
with a flash external. (find it through maxobjects.com as always)

I would do all straight in Max, because I don’t know Flash. (And I am
mostly slightly annoyed whenever I come across Flash “enhanced” web
sites, though there do exist exceptions to that rule… ;-)

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#96222
Feb 19, 2007 at 4:03pm

I am trying to do something similar so i have been reading your notes but it when i tried to go into the java console and compile it says Error: Unable to find java compiler C:Program FilesJavajre1.5.0_11/bin/javac.exe do you know what that means?

#96223
Feb 19, 2007 at 4:42pm

Hi,

That would seem to indicate that you don’t have the Java compiler installed. that’s needed so the computer can turn your code into a working program.

To get this, go to the SUN website

I think, here:

http://java.sun.com/j2se/1.4.2/

then try.

Also, re Java being easier than C – I take your point. I’d like to learn C, particularly for Max object and routines. It probably is possible to get going using existing objects – can you give me any pointers? (no pun intended) I’ve found Java very manageable. I guess I was just being positive about the fact that you can pick up the ability to program quite quickly.

Cheers,
Andrew

#96224

You must be logged in to reply to this topic.