Closed stani closed 7 years ago
I will check if time is big enough lose for accuracy or affects the sync of the midi file.
I played a file of 230 sec. and measured time between onStart
and onStop
. It plays about 240 seconds -> 10 sec longer. About 2 sec lost per minute. For something like a rhythm game it's pretty huge.
I figured out that my way of calculating elapsed ticks is wrong if Tempo changes more that once. So, instead I introduced 2 variables: lastTempoTime
and lastTempoTick
, which are initially set to zero then updated every time the Tempo is changed (set to time and tick of the Tempo event). With that elapsed ticks are calculated this way:
mTicksElapsed = lastTempoTick+ msToTicks(elapsedTime - lastTempoTime, mMPQN, mPPQ);
It seems to work well.
I have found a workaround that doesn't require much change. I had to apply a 4% increase in PPQ to get a more accurate playback. I tested this on a 16 minute song and the result was 1 second off the original time [using Media player to check the midi time]. Other songs I tried get like a total of 1 second off the original total time.
double MidiUtil::msToTicks(long ms, int mpqn, int ppq) { return ((ms * 1000.0) * (ppq * 1.04)) / mpqn; }
so I don't think its the tempo change but rather slower tick playback
Is is possible to send me the changes on git or through email so I can check vs my temp solution
Ok, I added my changes. There is also couple of other things, like GetMidiNotes
(access to notes for BP) and ProcessTo
(like Process but time is controlled externally).
found issues with your workaround...found 1 midi that jumps forward while playing, another does not end properly.
I introduced a variable that lets the user decide the speed playback
I have fixed up the timing issue. I have removed the long to double conversion
I believe it's because how
mMsElapsed
is calculated. I replaced it bymMsElapsed = FPlatformTime::ToMilliseconds(now - mStartMs);
and it works ok. (mStartMs is set instart()
asmStartMs = FPlatformTime::Cycles();
)Also, I think it's better to use actor time or game time, instead of platform time. This way the time can stop when game is paused or time dilation can be applied.