What's new

Is wait_ticks as accurate as wait?

Ben Osterhouse

Active Member
Hi!

I am working on a script which plays back the notes in a midi file. If you play a note, it will start playing back the midi file, at whatever pitch you played.
If notes overlap, it will continue in the midi file, not starting from the beginning again.
I'm doing this in the note callback by the way.

This example midi file has a note on every quarter note:
midi file to play.png


Here are some overlapping quarter notes going in, to trigger that midi file:
1635123155917.png

Here is the result:

1635123185739.png

Inconsistent! Huh...

What's happening is, sometimes the second note in the midi file is happening before the second played note.
It's happening 23 microseconds too early, so the pattern gets broken.
I know that wait and wait_ticks aren't super accurate. Certainly not this accurate, so it makes sense that you'd get this problem.

However, I was just realizing that the factory polystep script does a very similar thing to what I'm trying to do.
Does it have the same problem? No! Very interesting... So after a bunch of comparison, I realized, the only difference was that the polystep script uses the normal wait, instead of wait_ticks.

If I make the polystep script do wait_ticks, I get the exact same result as in my script!
And, I can fix my script by just using the normal wait 🙂

This is weird though... doing some tests to compare wait and wait_ticks, it looks like they basically have the same amount of precision. Looking at other threads on the forum, I'm seeing posts about wait_ticks, and it sounds like wait_ticks should be fine.

It broke the factory script though, so I don't know.
Are there issues with wait_ticks after all?

-Ben
 

Attachments

  • 1635123134077.png
    1635123134077.png
    1.8 KB · Views: 1
The ksp manual says kontakt sometimes kind of "miss" some ticks, maybe that's what you're experiencing here ? By the way, doesn't changing wait_ticks to ticks make you loose the benefit of some kind of input quantize (according that's what you're after) ?
 
Ok interesting. I think the advantage of wait_ticks is that if a tempo change happens while it's waiting, it will take into account the changing tick length while it's waiting.
 
I did some tests a while ago, and I think neither was completely accurate, but wait_ticks was worse ... I think. Check out this thread:
 
Last edited:
In the end I found that actually the main problem was that I was using DISTANCE_BAR_START to figure out where I was in the bar. It starts to jitter when you go past 181BPM

I should have been using NI_SONG_POSITION, which is in ticks, and seems to be more accurate. I suppose if someone does a time signature change, you wouldn't be able to know where the downbeats are anymore, but in my case I don't need to know.
 
Top Bottom