Time shift when playing notes


#1

I’ve noticed that sometimes my host can play a specific note up to 30 milliseconds before/after the exact time that the note should be played.

What should be considered as a decent maximum delay in playing a note?

Thanks


#2

From http://www.adobe.com/support/techdocs/331631.html


#3

Thanks Vincent, I’ve done some modifications and now it’s much better.

I’ve also noticed that most hosts have some ‘glitches’ when calling the plug-in’s callback.
I did some testing, for example, Ableton with a buffer size of 23 milliseconds (monitoring calls to processBlock()):

started : 444354779 and lasted for 0.0326080322 diff from last = 29.1529253
started : 444354800 and lasted for 0.0344195962 diff from last = 20.854638
started : 444354812 and lasted for 0.0312493443 diff from last = 11.9580842
started : 444354840 and lasted for 0.0326080322 diff from last = 28.04697
started : 444354863 and lasted for 0.0303435326 diff from last = 22.9628369
started : 444354884 and lasted for 0.0317022204 diff from last = 20.9909576
started : 444354912 and lasted for 0.0326080322 diff from last = 27.9890002
started : 444354933 and lasted for 0.0303435326 diff from last = 20.9900519
started : 444354962 and lasted for 0.0326080322 diff from last = 29.0175114
started : 444354983 and lasted for 0.0326079726 diff from last = 21.0353408
started : 444355004 and lasted for 0.0307964087 diff from last = 20.9660487
started : 444355033 and lasted for 0.0339667201 diff from last = 29.0419674
started : 444355054 and lasted for 0.0298906565 diff from last = 20.9714834
started : 444355075 and lasted for 0.0307964683 diff from last = 20.9950336
started : 444355105 and lasted for 0.0326080322 diff from last = 29.9971105
started : 444355135 and lasted for 0.0317022204 diff from last = 30.0337946
started : 444355155 and lasted for 0.0307964087 diff from last = 19.9973189
started : 444355177 and lasted for 0.0326080322 diff from last = 21.9719154

You can see that many times it calls the callback after 29 millis - and the plugin is left helpless for 6 millis (dunno how bad it is though…)

Fl studio, on the other hand, is quite crazy - looks like all he does is to call the callback (45 millis buffer):

started : 445570374 and lasted for 0.00860490737 diff from last = 0.145830274
started : 445570374 and lasted for 0.00815202642 diff from last = 0.0375897884
started : 445570374 and lasted for 0.00769911389 diff from last = 0.0344195962
started : 445570374 and lasted for 0.00769911101 diff from last = 0.0330609083
started : 445570374 and lasted for 0.00815197671 diff from last = 0.0344195962
started : 445570374 and lasted for 0.0480062551 diff from last = 0.0344195366
started : 445570374 and lasted for 0.00815197511 diff from last = 0.0774440765
started : 445570374 and lasted for 0.00815202433 diff from last = 0.0348724127
started : 445570374 and lasted for 0.00860490659 diff from last = 0.0412129164
started : 445570374 and lasted for 0.00634043009 diff from last = 0.0362311602
started : 445570425 and lasted for 0.0163039847 diff from last = 50.6203222
started : 445570425 and lasted for 0.00860491561 diff from last = 0.0824257731
started : 445570425 and lasted for 0.00860489771 diff from last = 0.0366840363
started : 445570425 and lasted for 0.0086048668 diff from last = 0.0362311602
started : 445570425 and lasted for 0.00815202689 diff from last = 0.0348724127
started : 445570425 and lasted for 0.00815200899 diff from last = 0.0366840363
started : 445570425 and lasted for 0.0081519816 diff from last = 0.0425716043

And even though, he still manages to miss a call to the plug-in.

Is there anything a plug-in can do to prevent glitches, or that there’s no need to do anything in such small delays?

Thanks


#4

Well is this a problem with the plug-in, or a problem with the host?


#5

It’s a host problem, maybe if the protocol (vst/au) had the option for the plug-in to tell the host "are you awake or what? gimme a buffer to process already!"
then things would be better…


#6

Looking over your data, it seems to me that everything is working as desired. You said you were using Ableton with a 23ms buffer. And you’re getting 6ms latency on top of that (29ms). What’s wrong with that?

If you want your latency to go down you need to use the appropriate hardware. Are you using DirectSound or something? Because you should be using ASIO with a robust hardware device. Perhaps a Native Instruments Audio 2 or a FireFace 400? If you are using your on-board audio, you can’t expect low latency.

I suggest first switching to ASIO (use http://www.asio4all.com/ if necessary) to improve your base latency and if that’s not good enough then get a professional sound card.

I’m running 44kHz with a 64-sample buffer which is very low latency. You should be too!


#7

64 samples?! say no more, I’ll buy one in the next few days…


#8

Now you got me worried:

64 samples in 44.1K sampling leaves 0.00145 milliseconds for the processBlock() and thats not a lot!
The data I posted shows that I won’t be able to respond in time!

I need this sound card…


#9

You’re right, that’s not a lot! But I think you meant 1.45ms… ? Which is much more doable.


#10

Depending on your budget and hardware you might want to get a Firewire soundcard. They tend to do better than the USB 2.0. However, if you have the latest motherboard which supports USB 3.0 then a soundcard that supports USB 3.0 would be superior.

Before you go the USB 3.0 route, you will have to research your motherboard and the sound card to make sure that it will work, since USB 3.0 is a new standard and support for it is spotty at best.


#11

Also remember that if your buffer size is 64 then you will be performing a lot less operations in your callback so it will finish quicker anyway.


#12

You are right, 1.45 ms. now it looks much better… :slight_smile:

You’re right too, I thought about it too but I’ll have to see it working to make sure that it’s acting in a linear way, 10x.


#13

Well it won’t be completely linear because obviously some operations take more clock cycles than others. For example ‘if’ statements are relatively expensive compared to an add or a multiply, lets say 50x more so for this example.

Lets say you have one if statement in your process block and a multiply for every sample. Using buffer sizes 512, 256 and 64 will give you this number of clock cycles to process 512 samples: 562, 612, 912.

Now thats a very rudimentary example and the 50x was just a guess but all the function calls, pointer dereferencing stack variables etc. will add up to a very non-linear CPU consumption. But hey, thats the price you pay for a few ms of latency.


#14

Depending on your budget and hardware you might want to get a Firewire soundcard. They tend to do better than the USB 2.0. However, if you have the latest motherboard which supports USB 3.0 then a soundcard that supports USB 3.0 would be superior.

Before you go the USB 3.0 route, you will have to research your motherboard and the sound card to make sure that it will work, since USB 3.0 is a new standard and support for it is spotty at best.[/quote]

And keep in mind that some interfaces add extra buffers which they don’t report. Read here for more.


#15

Wow…great article, if a little disappointing.


#16

Wow…great article, if a little disappointing.[/quote]

It’s a bit out of date now, you need to follow the link to the forum to get the latest stuff (see pg 11 of the post linked from the article). There are a couple of USB based interfaces which aren’t too bad - the recommendation on sticking with PCI/PCIe based interfaces is really for those interested in very low latency audio.

BTW, the latency measurements are now done using my juce based RTL Utility.