Forums > MaxMSP

Pitch Tracking with a Guitar

February 12, 2007 | 5:37 am

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


February 12, 2007 | 6:00 am

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
>


February 12, 2007 | 6:48 am

fiddle?


February 12, 2007 | 7:18 am

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?
>


February 12, 2007 | 7:23 am

http://www.maxobjects.com/?v=objects&id_objet=977&requested=fiddle&operateur=AND&id_plateforme=0

fiddle~ is an external for pitch-tracking.


February 12, 2007 | 7:50 am

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


February 12, 2007 | 7:59 am

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

Bryan

http://www.techniquolor.com

http://www.ksod.net


February 12, 2007 | 8:19 am

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
>


February 12, 2007 | 9:54 am

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
> >
>


February 12, 2007 | 10:14 am


February 12, 2007 | 1:50 pm

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


February 12, 2007 | 3:18 pm

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;


February 12, 2007 | 3:21 pm

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;
}

}

}


February 12, 2007 | 7:39 pm


February 13, 2007 | 5:13 am

what do you mean by mxj quickie object?


February 13, 2007 | 5:47 am

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


February 13, 2007 | 2:02 pm

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.


February 13, 2007 | 8:59 pm

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


February 14, 2007 | 7:30 am

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


February 19, 2007 | 4:03 pm

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?


February 19, 2007 | 4:42 pm

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


Viewing 21 posts - 1 through 21 (of 21 total)