Sign in to follow this  
bleomonkey

Midi Timing

Recommended Posts

Someone already posted a thread on here about Midi timing, but I still don't understand how to convert it to milliseconds/seconds. Here is part of what I have: MFile 1 2 480 MTrk 0 Tempo 600000 15000 On ch=1 n=84 v=127 15092 Off ch=1 n=84 v=64 15250 On ch=1 n=87 v=127 15342 Off ch=1 n=87 v=64 15450 On ch=1 n=86 v=127 How can I convert this to seconds/milliseconds? Thanks

Share this post


Link to post
Share on other sites
Quote:
Source : http://www.sonicspot.com/guide/midifiles.html
Set Tempo
This meta event sets the sequence tempo in terms of microseconds per quarter-note which is encoded in three bytes. It usually is found in the first track chunk, time-aligned to occur at the same time as a MIDI clock message to promote more accurate synchronization. If no set tempo event is present, 120 beats per minute is assumed. The following formula's can be used to translate the tempo from microseconds per quarter-note to beats per minute and back.

MICROSECONDS_PER_MINUTE = 60000000

BPM = MICROSECONDS_PER_MINUTE / MPQN
MPQN = MICROSECONDS_PER_MINUTE / BPM


Your tempo events sets the tempo to 600000 microseconds per quarter note. You can convert this to beats per minute as follows :
60000000 microseconds per minute / 600000 milliseconds per quarter note = 100 bpm

Then, your time division (or ticks per beat) is set to 480 (in the header). Let's take an exemple :

15000 On ch=1 n=84 v=127

15000 is the time elapsed since the last midi event, in ticks, (you might want to check your code for this, this number looks a bit too huge). Aniways, divide this number by your time division to know the time elapsed since the last invent in quarter notes :

15000 ticks / 480 ticks per quarter note = 31.25 quarter notes

That number is really huge, let's just convert it to seconds to see what it gives :

31.25 quarter notes / 100 beats per minute = 0.3125 minutes = 18.75 seconds.

This means that you have a pause of about 20 seconds between two of your events... very unlikely. If I were you, I'd check back your code which reads the event time delta. Unless you're converting relative time stamps to absolute time stamps...

Share this post


Link to post
Share on other sites
Thank you so much. This is perfect and it is reasonable that the first note doesn't start until about 20 seconds into the song because the song is "One" by Metallica. Do you know what the two numbers mean that are to the left of 480 at the top (1 and 2) and also what v (which I assume is velocity) affects?

Share this post


Link to post
Share on other sites
Here it comes :

MFile 1 2 480

The "1" is the type of midi file, you've got 3 types :

0- Single-Track Midi, you should only find one MTrk chunk
1- Multi-Track Midi, the most common, can include multiple tracks (MTrk chunks). The first track is usually used for events such as tempo changes and copyright information
2- If I'm not mistaking (I've never seen one), it defines a Midi containing multipe tracks which are not necessarly supposed to be played simultaneously. Let's call them "Independant Tracks Midis"

The "2" is simply the number of tracks in your file.

The "v" of your NoteOn and NoteOff events is effectively the velocity. A value of zero on a NoteOn is the same as a NoteOff message. For all the other values, it defines how "strong" the key was hit (if you were on a keyboard) :

Values around 32 mean "piano"
Values around 64 mean "mezzo-forte"
Values around 96 mean "forte"
Values around 127 mean "fortissimo"

If you have any other questions, don't hesitate

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this