Converting MIDI ticks to actual playback seconds - midi

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

Related

Need to extract earliest and latest data reads from each day with multiple time stamps (seconds)

I have a very large csv file which contains multiple meter reads for 8 meters - the readings have been taken every few seconds. I want to create a summary showing the first and last meter read for each day and for each meter - how could I do that please?

Alsa tempo vs. PPQ

Recently I've been playing with the haskell ALSA interface, and I had to notice, that I do not really understand the concepts of tempo and PPQ.
Earlier I've written a Swig-Python interface to ALSA and in there I find the following piece of code (probably copied from somewhere else):
1 void AlsaMidiIfc::setTempo (int bpm) {
2 int queue = this->getOutQueue();
3 snd_seq_queue_tempo_t *tempo;
4 snd_seq_queue_tempo_alloca (&tempo);
5 snd_seq_queue_tempo_set_tempo(tempo, 60 * 1000000 / bpm);
6 snd_seq_queue_tempo_set_ppq(tempo, PPQ);
7 snd_seq_set_queue_tempo (mySeq, queue, tempo);
8 }
When I put an event into a queue, the time is always specified in ticks, right? So the only timing question to answer is "how long is a tick?".
What is the point of specifying two values, i.e. tempo and PPQ?
What would be the effect of changing the tempo, but leaving PPQ as it
is?
If I don't set PPQ at all, but only the tempo, what would be the
result?
Standard MIDI Files use these two values (tempo and PPQ) to specify the tempo.
The ALSA sequencer just uses the same mechanism.
The tempo value is the number of microseconds per quarter note.
Increasing it will increase the length of a tick, i.e., make playback slower.
A PPQ value of zero would be invalid.

Midi set tempo meta event

The Set Tempo Meta event itself contains a delta field as well. Is this delta defined in the previous tempo or in the new tempo (the tempo in this event)?
Thanks
Delta times are expressed in MIDI ticks, which are independent of tempo.
If you are calculating the real-time duration in microseconds of the delta time of the new tempo, you would use the MPQN of the previous tempo event to perform that calculation.

MIDI: Convert BPM to FPS delta time?

Given a BPM (beats per minute) MIDI delta time (leftmost bit off) with speed of 192:
0x00C0
I want to convert it to a FPS/TPM (frames per second / ticks per minute) delta time (leftmost bit on), but it should be the same (or the most accurate) speed value if you know what I mean.
For more info about MIDI Delta Time please take a look at Midi File Format under Header Chunk -> Time Division.
I am looking for a formula that will convert between these two deltatime types.
If you're talking about 0x00C0 being the time division field, what you're referring to is not 192 beats per minute, but rather 192 ticks per beat, quite a different beast. BPM is specified indirectly via "Set Tempo" events, given in microseconds per beat (with the lamentably ubiquitous 120 BPM being assumed to begin with). The trickiness of time division with this format is that the length of a tick will grow and shrink depending on the tempo changes in the song.
Let's say the time division you want to convert to has F as the frames per second (24, 25, 29.97, or 30) and G as the ticks per frame (note: it's not ticks per minute!). Further, let's assume that the current tempo in microseconds per beat is p. Then the formula to convert a given duration in ticksold to ticksnew (the unit analysis really helps!) is:
y = x ticksold * (1/192) beat/ticksold * p μsec/beat * (1/106) sec/μsec * F frames/sec * G ticksnew/frame
= ((x * p * F * G)/(192*106)) ticksnew

midi delta time

i need help..
i need to know exactly midi delta time format?is it millisecond,tick or what??
and i need formula to convert timestamp in millisecond into midi delta time...
thanks before..
Delta time is always specified in ticks, which are determined by the PPQ (pulses per quarter note).
So given an offset in milliseconds, you must first convert that to samples (using the sample rate), and then to pulses based on the current tempo and the PPQ.