开发者

Converting MIDI ticks to actual playback seconds

开发者 https://www.devze.com 2022-12-16 11:56 出处:网络
I want to know how to convert MIDI ticks to actual playback seconds. For example, if the MIDI PPQ (Pulses per quarter note) is 1120, how would I convert it into real worl开发者_C百科d playback second

I want to know how to convert MIDI ticks to actual playback seconds.

For example, if the MIDI PPQ (Pulses per quarter note) is 1120, how would I convert it into real worl开发者_C百科d playback seconds?


The formula is 60000 / (BPM * PPQ) (milliseconds).

Where BPM is the tempo of the track (Beats Per Minute).

(i.e. a 120 BPM track would have a MIDI time of (60000 / (120 * 192)) or 2.604 ms for 1 tick.

If you don't know the BPM then you'll have to determine that first. MIDI times are entirely dependent on the track tempo.


You need two pieces of information:

  • PPQ (pulses per quarter note), which is defined in the header of a midi file, once.
  • Tempo (in microseconds per quarter note), which is defined by "Set Tempo" meta events and can change during the musical piece.

Ticks can be converted to playback seconds as follows:

ticks_per_quarter = <PPQ from the header>
µs_per_quarter = <Tempo in latest Set Tempo event>
µs_per_tick = µs_per_quarter / ticks_per_quarter
seconds_per_tick = µs_per_tick / 1.000.000
seconds = ticks * seconds_per_tick

Note that PPQ is also called "division" or "ticks per quarter note" in the document linked above.

Note that Tempo is commonly represented in BPM (a frequency) but raw MIDI represents it in µs per quarter (a period).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号