Pitch Tracking with a Guitar

DerekJ's icon

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

jaime.oliver2's icon

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
>

DerekJ's icon

fiddle?

jaime.oliver2's icon

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

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

erichonour's icon
DerekJ's icon

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

tripnikk@gmail.com's icon

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

jaime.oliver2's icon

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
>

jaime.oliver2's icon

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

José Manuel Berenguer's icon
Stefan Tiedje's icon

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

Venetian's icon

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

Max Patch
Copy patch and select New From Clipboard in Max.

Venetian's icon

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

    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
else{
    pitch_index = 0;
    for (int y =0; y
    pitch_counter[y] = 0;}

for (int y = 0; y
    recent_pitch_array[y] = 0;
    recent_pitch_amplitude[y] = 0;
    }
    }//end else
}

    public void print()
    {int k = 0;
    while (k
    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
    post(k+ " Pitch :"+running_average_array[k]);
    k++;
    }//end while

}

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

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

for (int y = 0; y
    recent_pitch_array[y] = 0;
    recent_pitch_amplitude[y] = 0;
    }

}

}

Andrew Burgess's icon

what do you mean by mxj quickie object?

DerekJ's icon

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

Venetian's icon

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.

Peter Castine's icon

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

Stefan Tiedje's icon

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

Baroness Thorn's icon

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?

Venetian's icon

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:

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