0

My goal currently is to change the tempo(speed) of the song that I parse in as a MIDI file.

Lets say I need to speed up the song by a factor of 2. This implies that the song now takes half the time to play.

Where exactly is the information related to this tempo stored? I know that there is a meta event FF 51 which is used to designate tempo changes. But from what I have read, it is for tempo-changes in real time while the music is playing. If I want to change the tempo of the entire song from start to finish, would changing all the meta events of FF 51 suffice? Also, it seems like for some MIDI files, there may not be such an event to indicate tempo changes, in which case the tempo is assumed to be 120. How do I change that by the desired amount if the event does not exist?

Furthermore, it seems like there is a relation between ticks per quarter from the header chunk, delta times, and the tempo. However, I am not able to understand this relation because of the jargon heavy music language (I don't understand a lot of the terms of music) which is available online in all the explanations. Could anyone please break it down for me?

Edit: I discovered that changing the ticks per quarter field affects the tempo. So now I am able to speed the song up and down. However, how do I make sure that the song takes in less storage as well? How would I need to change the delta times?

1

You have several options to change speed of MIDI file playing:

  1. Change ticks per quarter note stored in MIDI file geader, as you did.
  2. Change all delta-times. For example, to speed up by two times, divide delta-time values by 2, so space between two adjacent events will be compressed by two times.
  3. Change microseconds per quarter note values in Set Tempo events. You are right, it's possible that MIDI file doesn't have thiese events. In this case you need to insert new Set Tempo event at the start of a MIDI file.

Also you should definitely read Standard MIDI File specification to know what you're doing.

However, how do I make sure that the song takes in less storage as well?

What do you mean? If you mean size of file in bytes, it will be around the same value, since no information is thrown away from the file, you just changed some values.

If you mean calculate duration in hours:minutes:seconds, you need to iterate over all MIDI events in file and calculate metric time using Set Tempo events within the file.

Please note that in vast majority of cases it will be better to use existing programming libraries that do this job for you. If you're happy with C#, you can use my DryWetMIDI library.

| improve this answer | |
  • Thanks a lot for your detailed answer. Just a tiny followup. So speeding up would mean dividing delta times by 2. For ticks per quarter, do I multiply the ticks per quarter note by 2 or again divide? – gazillionTickets Apr 13 at 15:45
  • Let's think. You need to compress quarter note to decrease its duration. So it must occupy less ticks. So you need to divide ticks per quarter note. Main resource is the SMF spec: midi.org/specifications-old/category/smf-specifications. – Maxim Apr 13 at 15:54
  • I tried doing what you said and your explanation makes perfect sense. But for some reason, when I am multiplying the ticks per quarter with 2 (only ticks per quarter, not doing anything with anything else) then the song tends to get faster and takes half the time as before. – gazillionTickets Apr 13 at 16:36
  • You're right, that's my fault. When we decrease length of quarter note, then old delta-times will mean that larger part of quarter note will be used. So yes, we need multiply :) – Maxim Apr 13 at 16:48
  • No problem! Thanks for your responses. So basically if we multiply the ticks per quarter by 2 or divide the delta times by 2, the effect is the same? – gazillionTickets Apr 13 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.