This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to measure the Frequency/Pitch/Note of a Midi File? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "How to measure the Frequency/Pitch/Note of a Midi File?" Watch "How to measure the Frequency/Pitch/Note of a Midi File?" New topic
Author

How to measure the Frequency/Pitch/Note of a Midi File?

Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
Hi guys,

I am new in this forum, actually this is my first post. I am also a relatively new java programmer, i just learned to use the language weeks ago. So forgive if i say something totally nonsense. ^^

Well, here is my problem:

i've created a midi player program. And i need to measure (any units of measurement will do) the notes being played in the midi file.. does anyone know how to do this?

thanks a lot, in advance!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617



It's a MIDI file: there's nothing to "measure."

http://tomscarff.110mb.com/midi_analyser/midi_note_frequency.htm
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
hi david,

im not really sure what you mean by there's nothing to measure in a midi.

well, can i have a sample code, where i can get the value of the midi notes from the file.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I mean the note value is contained in the note messages, it's not like you have to run a fourier analysis to figure out what notes are playing.

Have you looked through the Java MIDI tutorials, where you'd find things like javax.sound.midi.spi.MidiFileReader, javax.sound.midi.Sequence, javax.sound.midi.Track, and javax.sound.midi.MidiEvent?

I'd probably also search around to see if someone else has already written utilities to wrap all this up--I don't know what you're actually trying to do, but it seems pretty common.
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
Here is what i'm trying to do. I am a college student, and I need to finish this program in order for me to graduate.

My program should be able to:
a. have basic functionality of a midi player (play, pause, stop, file open, volume etc)
b. measure the pitch (frequency) of a singer using a mic in real time.
c. adjust the song(midi) pitch, and align it to the pitch of the singer.

I've already finished A, B. Im just having a hard time figuring out C. I need to know the pitch of the song in real time, and adjust accordingly. I getting confused on how to use note messages (maybe because of lack of sleep ).

thanks david, I appreciate that someone is actually talking to a newbie like me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You probably mean the key of a song, then, not the pitch--a song doesn't have a pitch, a note does. I question what this would actually mean, however, since changing the key of a song throughout the song would make it really, really suck. A lot. That's why there are autotuners, that correct the pitch of the *singer*, and try to align it to the expected notes of the song.

Doing it the other way around seems... like something used as a torture device on anyone that can hear tones.
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
i can't do it the other way around, because i already passed a proposal to my adviser(and i cant change it now, whether the results will be good or bad)

im planning to use pitchBend() on each channel of the Midi in changing the pitch..

can you teach me how to use midi notes, or just how to get the pitch of each notes of the midi song..?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3016
    
  10
Sj Balatan wrote:b. measure the pitch (frequency) of a singer using a mic in real time.

This part suggests that yes, you do really mean pitch rather than key. But it's important to note that this part would have nothing to do with a midi file, at this point. You're talking about looking at the raw wave output and determining the dominant frequency associated with it. This would probably involve a Fourier transform and finding a maximum. But I share David's skepticism here - this sounds like a bad idea. If a singer is out of tune, is it better to fix the orchestra, or fix the singer? Maybe if the singer is consitently out of tune, the latter might work, sort of. But I think most out-of-tune singers will probably be out-of-tune by an inconsistent amount. So if you "fix" the orchestra to match them, the end result will just... how should I say this?... suck. Badly.
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
Hi mike,

I already done with B. part. I can now actually measure the frequency of the singer using a mic. and yes, it has nothing to with midi.

i agree with you both guys, that It is indeed a bad idea, and it is better if i do it the other way around. But this is what my adviser suggested me to do, it doesn't matter much if it will turn out good or bad. I only need a conclusion with this study, i need to stick with it till the end..
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3016
    
  10
OK. So you've got a singer, and you know how to determine the frequency they are singing at, at any particular point in time. And you've got a MIDI file of music intended to accompany them. And you want to make these match up, by altering the accompanying music, rather than altering the singer. OK.

Important questions: does the MIDI file also contain the notes that the singer is trying to sing? And can these notes be identified and distinguished from the other notes?
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7
OK. So you've got a singer, and you know how to determine the frequency they are singing at, at any particular point in time. And you've got a MIDI file of music intended to accompany them. And you want to make these match up, by altering the accompanying music, rather than altering the singer. OK.


yes, exactly.

Important questions: does the MIDI file also contain the notes that the singer is trying to sing? And can these notes be identified and distinguished from the other notes?


that's one of my main problem, i can't get the notes of the midi file.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What code do you have so far? The classes I listed above are the classes you need, although you'll also need to track song position in real-time in order to insert the MIDI messages.
Sj Balatan
Greenhorn

Joined: Aug 16, 2010
Posts: 7


basically, this the backbone of my midi player.. hope this will get you a glimpse of my project.
 
GeeCON Prague 2014
 
subject: How to measure the Frequency/Pitch/Note of a Midi File?