Seconds to delta offset in midi file

Seconds to delta offset in midi file

Post by Peter Zegeli » Sun, 29 Jun 2003 13:21:25



Hi,
   I need to figure out how to convert an offset expressed in seconds to
a delta time within a list of midi events.
   I thought it would be quite straight forward but it looks like tempo
changes would complicate things a bit. Is it really just a case of
accumulating a total time in seconds based on a particular conversion
rate until a tempo change event is found, calculating a new conversion
rate, and continuing until the desired time is reached? Or am I missing
something here?
   Can anyone help me with the calculations required?

Many thanks!

Peter

 
 
 

Seconds to delta offset in midi file

Post by Philip Delaques » Sun, 29 Jun 2003 14:58:18


I think you've got the idea. The MIDI file header tells you how many
quanta per quarter-note pertain in that particular file. The tempo
change events tell you how many microseconds duration is each quarter
note. By accumulating deltas, you keep track of how many quarter notes
have elapsed. By doing simple arithmetic, you convert those quarters to
seconds. You establish a new "baseline" for calculations whenever you
encounter a tempo change event.

So, your given time, minus the time at which the most recent tempo
change occurred, converted to quanta, plus the quantum at which the
most recent tempo change occurred, is the quantum where your given time
occurs. OK?

Philip.



> Hi,
>    I need to figure out how to convert an offset expressed in seconds to
> a delta time within a list of midi events.
>    I thought it would be quite straight forward but it looks like tempo
> changes would complicate things a bit. Is it really just a case of
> accumulating a total time in seconds based on a particular conversion
> rate until a tempo change event is found, calculating a new conversion
> rate, and continuing until the desired time is reached? Or am I missing
> something here?
>    Can anyone help me with the calculations required?

> Many thanks!

> Peter


 
 
 

Seconds to delta offset in midi file

Post by Peter Zegeli » Sun, 29 Jun 2003 18:43:58


Thanks Philip!
   Yes it makes sense. I wanted to confirm the general idea and make
sure I wasnt missing anything. Now to try it in the real world!

Thanks again for your explanation,

Peter



> I think you've got the idea. The MIDI file header tells you how many
> quanta per quarter-note pertain in that particular file. The tempo
> change events tell you how many microseconds duration is each quarter
> note. By accumulating deltas, you keep track of how many quarter notes
> have elapsed. By doing simple arithmetic, you convert those quarters to
> seconds. You establish a new "baseline" for calculations whenever you
> encounter a tempo change event.

> So, your given time, minus the time at which the most recent tempo
> change occurred, converted to quanta, plus the quantum at which the
> most recent tempo change occurred, is the quantum where your given time
> occurs. OK?

> Philip.



> > Hi,
> >    I need to figure out how to convert an offset expressed in seconds to
> > a delta time within a list of midi events.
> >    I thought it would be quite straight forward but it looks like tempo
> > changes would complicate things a bit. Is it really just a case of
> > accumulating a total time in seconds based on a particular conversion
> > rate until a tempo change event is found, calculating a new conversion
> > rate, and continuing until the desired time is reached? Or am I missing
> > something here?
> >    Can anyone help me with the calculations required?

> > Many thanks!

> > Peter