Jump to content

midi latency at recording, not the average problem


Recommended Posts

Hi, my first post here. I've worked with logic since 2012 on and off and know my way around pretty good, but this one problem has bugged me and I've never found a way to solve it. The problem is simply that when I record midi the notes are recorded too late. When using 1024 recording buffer it is recorded about 50 ms too late, when using 32 sample recording buffer the delay is about 4-8 ms. See this youtube clip for a demonstration where I record audio and midi at the same time:

 

Most people who record midi seems to want to quantize it before using it further, in that case you're fine and don't need to worry I guess. The same goes if you are willing to change the audio buffer to 32 ms when recording, that shrinks the problem to be manageble. I prefer to use 512 though since I don't want pops and clicks and also I don't have a very fast computer.

 

And also the most confusing to me is that I don't get why this is a problem. Logic automatically delay compensates audio, you can record at 1024 buffer and still the audio sync up perfectly, believe me I've tried this. But why doesn't it work with midi? Do you know how I can get it to work? Or is this such a weird use case that Logic isn't built for it? And just to clarify, this isn't only a problem when I record both audio and midi at the same time, I recorded both in the youtube-clip to demonstrate the delay, off course the midi delay is there even if I wouldn't choose to record audio at the same time.

 

Edit 1

20210521: I use direct monitoring, not software monitoring. And the problem is where the midi lands on the grid after they hqve been recorded, nothing else.

 

Edit 2

20210522 We've discussed this back and forth for a long time and haven't come up with any other solution than lowering the buffer size setting. I think all of us agree that there could exist a solution to this, is not impossible we just haven't found it. There is some disagreement among the writers in the thread weather the audio is placed too early or the midi too late. I'm totally sure that it is the midi that gets placed too late but I've been wrong before...

The question was originally about sending audio and midi to logic at the same time to Logic. But the discussion has also touched on sending midi from Logic to a hardware synth and recording the sound. With high buffer settings the recorded sound ends up too early. There are two solutions to this, tweak the value of the midi delay in the settings or turn on auto delay on the external midi track that triggers the midi. The first solution is the one totally preferred by me because when you record audio from an external synth that gets triggered by midi clock, that clock needs to be delayed as well so you might as well delay all midi information from Logic, not just the midi notes.

Edited by mrcarlzone
Link to comment
Share on other sites

  • 2 weeks later...

With a high buffer you will get latency, doesn't matter what you do.

The problem is, there will always be latency. It's basic physics.

Sound also has latency, we just can't hear it.

A computer has to make calculations in real time to compensate things, but there will always be latency.

 

And with audio and midi being recorded at the same time, it's more calculations.

And if you're using heavy 3rd party plugins, even worse.

So the best you can do is keep the buffer low and don't use latency-inducing plugins, or engage low-latency mode when you record.

Link to comment
Share on other sites

Thank you for answering, lowering the buffer and removing plugins seems to be the only way to handle this problem. But the claim that you make that you always should use a low buffer when recording is not all true. There could be a way for Logic to solve this, I thought there was, but now I think it is not implemented.

 

The thing about audio latency is that it actually is possible to choose the highest buffer settings and even slam on a limiter with 50 ms look ahead on the master and still have no trouble recording audio which syncs perfectly. That's because there are latency compensation on audio tracks! Here's a demo that I made. In the video i have connected cables from output 1-2 on my sound interface and connected them back to input 1-2 (of course with no monitoring, that would yield a nasty feedback):

 

My point is, why isn't it the same when using midi??

Link to comment
Share on other sites

The thing about audio latency is that it actually is possible to choose the highest buffer settings and even slam on a limiter with 50 ms look ahead on the master and still have no trouble recording audio which syncs perfectly.

 

Sorry, I can't agree with this. The moment I put an Adaptive Limiter or any latency inducing plugin anywhere, I get audible latency when recording audio. And if I increase the buffer, it's worse.

So I don't know how you hear latency, but I can't play with it.

Link to comment
Share on other sites

I should clarify, I dont use software monitoring, I use direct monitoring through my interface. If i would have used software monitoring, it would have been unavoidable I agree. But my question is about where the recorded sound ends up on the the grid. Like I tried to show in my example.
Link to comment
Share on other sites

I should clarify, I dont use software monitoring, I use direct monitoring through my interface. If i would have used software monitoring, it would have been unavoidable I agree. But my question is about where the recorded sound ends up on the the grid. Like I tried to show in my example.

 

Ahh, now I get it.

Yeah, with direct monitoring and software monitoring turned off, you can see that Logic records ahead when you have a latency inducing plugin.

 

You can always mess with the Recording Delay slider and go down that rabbit hole.

I personally don't use direct monitoring.

Link to comment
Share on other sites

Yes, and taking the example of audio recording logic kind of sorts it out using automatic recording latency compensation. The difference in clip number two is just 1 or 2 ms which is quit small to me, even when using a buffer of 1024 ms and a limiter plugin it works well. BUT considering midi in the first example there is no automatic adjustment of the midi track. If we assume that the audio is correctly placed timing wise, the midi is placed too late. That's my question, is there an automatic timing adjustment for midi or not? I'm guessing now that there aren't.
Link to comment
Share on other sites

I wonder if this is possibly interface (driver) latency compensation going wrong. In other words: MIDI isn't recorded too late but the audio material is placed too early in relation to it.

AFAIK this could be fixed with the "Recording Delay" setting. Unfortunately Logic doesn't seem to provide a detailed explanation for this (anymore?).

I'd probably check first if MIDI data actually comes in late; this could be done with a single MIDI cable. Enter manually a couple of notes onto a MIDI track and record those then onto another MIDI track.

Link to comment
Share on other sites

The problem has always been there for me, I've just changed sound interface. I've thought about it quite a lot and I think there are delay compensation for audio that works very well, that is illustrated in the second youtube-link I included in this thread. In that example I send audio from logic, through the DA then routed back trough the AD and into logic again. When I've selected a buffer of 1024 ms there are of course quite a lot of latency but logic is aware of that and when the recording is done it moves the audio to the right position, it's just a mere 2 ms off in my example. So your idea of audio coming in too early is not correct. It's the midi that is the problem.

 

This is actually a bit complex but I've understand it like this. Logic sends a sound at time t, when it is send through DA it is delayed by d1 arriving at t + d1. If I sing through a microphone at t + d1 that sound must travel through the AD and will arrive at time t + d1 + d2. But logic is not stupid and places it at time t + d1 +d2 on the grid, it knows the value of d1 and d2 based on the setting of the record buffer and what extra latency the plugins adds. So Logic subtracts d1 + d2 from the time and places the audio coming from the microphone at time t +d1 +d2 - (d1 + d2) = t. So everything is good!

 

But the problem I'm talking about in this thread arises when I play on my midi controller, I try to match the time t, but I'll have to wait until I hear it being played and that happens at time t + d1. The midi doesn't travel through the AD, it goes much faster, but still arrives at t + d1. Logic could have subtracted d1 from the midi timing to place the note at time t but somehow it doesn't take d1 into account, it places the midi note at t + d1 on the grid.

 

This is how I think it works, I don't know if my explanation made any sense. I'm wondering if there are midi delay compensation on recorded midi notes, and it seems like there are not.

Link to comment
Share on other sites

Thanks but I didn't find a solution in the link. The author of that article seemed to compare the latency between different DAW:s. I accept that there is latency, I'm not affected by it while playing my midi controller because I don't use software synths that much. What I do care about is that the notes a play on the controller ends up on the right place on the grid. But the conclusion here is that I have to switch to the lowest possible buffer size while recording midi. It wouldn't have bother me so much if Logic didn't have a well implemented latency adjustment of the audio tracks. But now when Logic do have that I don't understand why they chose to not implement the same thing for MIDI.
Link to comment
Share on other sites

So your idea of audio coming in too early is not correct. It's the midi that is the problem.

We don't know that; and it would be useful to make the check I described. Your second youtube video showed the re-recorded audio material slightly early as well so clearly there are some discrepancies in the way the interface reports its latency.

Link to comment
Share on other sites

I've made the test that gacki mentioned and connecting the midi out to the midi in and it showed a very small timing difference:

 

I don't know if you guys could see that in my first video, if you pause at 0:31 you can actually see that the timing difference is 54 ms, measured with the "locators". I'm not really concerned with a timing difference which is just 2 ms, but 54 ms is not great.

Link to comment
Share on other sites

OK, let's try to unpack all of this.

There definitely IS some sort of problem but it's unclear to me where it comes from. There also seems to be some sort of misunderstanding of measurements which might lead to different expectations. And finally there is some stuff that doesn't make sense to me (yet).

 

Let's start with your first video. The 54 ms you thought you had measured are actually 28 ms (which I find still not acceptable!). But nonetheless it is about half of what we thought it was.

The number "54" is actually the "ticks" of the PPQ resolution of Logic. Logic has a 960 PPQ (Pulse Per Quarter) resolution (it actually is more complicated when it comes to audio data - but let's stick with this for now). This means that each quarter note can be divided into 960 parts (which equals 240 subdivisions within a 16th note).

So how long is such a subdivision? Well, that naturally depends on the tempo.

Your example has a tempo of 120 BPM. This means 1/4 notes are each 500 ms long. This gives for each "tick" or "pulse" a length of 500/960 = 0.52 ms. This number is different for different tempos!

0.52 ms per tick x 54 ticks = 28.08 ms. Still not acceptable in my book.

 

Second video: Audio is placed consistently about 2 ticks early (when latency compensation is on); this equals around 1 ms at 120 BPM. This difference is probably independent from the tempo (you'd get a different number of ticks for different tempos but it probably will stay around 1 ms). This could be a driver issue but I agree that this is very minor. This COULD also mean that the driver is working satisfactory for audio alone.

 

Third video: My takeaway is that there is no delay in the reception of MIDI data, at least not in a loopback situation. The difference for the first example was 2 ticks early (around 1 ms), for the second one 1 tick late (around 0.52 ms). And actually the audio buffer size should NOT affect the timing at all. So I'm rather inclined to mark this down as "jitter" in MIDI reception. This COULD also mean that the driver is working satisfactory for MIDI alone.

 

So what can we make out of all of this?

Time for another test: simultaneous loopback of both audio and MIDI (without any plugins and so on).

 

Out of interest I did this with my cheapo M-Audio interface and the results are ... interesting.

Link to comment
Share on other sites

In your first video you record with the Adaptive Limiter on. That's a latency-inducing plugin that creates havoc. I always take it out of the channel when I record so I don't have to deal with the mess.

 

In my first video I actually wasn't using adlimit. I just redid the example to confirm.

 

While I was doing that I found something else. When I changed sound from piano to organ on my nord stage the distance between the midi and the sound transient increased from 50 to 70 ticks. It seems like the nord has a built in latency when playing piano samples. The organ sound is not samples but modelled, that could be the reason for the difference.

 

I will continue when I have more time later today.

Link to comment
Share on other sites

While I was doing that I found something else. When I changed sound from piano to organ on my nord stage the distance between the midi and the sound transient increased from 50 to 70 ticks. It seems like the nord has a built in latency when playing piano samples. The organ sound is not samples but modelled, that could be the reason for the difference.

 

I had a similar thought. However this wouldn't (fully) explain why the latency is different for different buffer sizes.

There are other possible (unknown) factors. As far as I see it the Nord is connected via 5-pin-MIDI to the USB interface. It would be interesting to see if the situation is different when the Nord is connected directly via USB-MIDI to the computer (if it is a model that allows this).

Link to comment
Share on other sites

Forget the whole "change sound from piano to organ" i wrote in my previous post.

 

Nord stage has a special organ trigger function which is made to be able to play organ on a weighted piano. For the piano samples to sound you have to press the keys all the way down, but for the organ to play you just have to press it slightly. If you press it gentle enough, the organ will sound but no midi is sent. If you play it normally, the organ will sound and midi information is sent 10-50 ticks later depending on time it takes for the key to travel from the top to the bottom.

 

All in all, we can totally ignore the "piano sound vs organ sound" thing, it's just a special feature on the nord stage and I don't want to derail the main discussion.

 

EDIT: I've come to this conclusion thru triggering the nord and another synth (prophet 8) from another midi controller (octatrack). When the nord stage is played from midi notes sent from the octatrack to the prophet 8 and to the nord stage via midi thru both their sounds arrive at the same time to logic.

Link to comment
Share on other sites

To sum up. I think we can say that this is how it works in logic if you try to record audio and midi at the same time:

 

1. The metronome click is played from logic at time t

2. The click is converted to audio and heard at time t+d1

3. An outboard synth is played at t + d1 which sounds right on the beat, and also sends midi at the same time

4. The audio arrives back to logic at t + d1 + d2, the midi on the other hand travels back to logic in practically no time and arrives at time t + d1

5. Logic knows the values of d1 and d2, and adjusts the audio back to t, Logic doesn't do anything to correct the midi and leaves it sitting at t+d1

 

HjUtfbb.jpg

Link to comment
Share on other sites

No, that's not correctly describing what happens.

Logic actually gives a negative delay to all of its audio data (also the click) when playing it back so that it appears at the same time as a MIDI click. The click (and other audio material that is already present) is heard at t. That's what the latency compensation does.

 

As I wrote that my own "loopback" testing was "interesting": I was playing back both MIDI and audio data and re-recording it into Logic.

Result: audio was slightly late, MIDI was slightly early (!).

Link to comment
Share on other sites

Here we go:

 

1546802435_Bildschirmfoto2021-05-19um15_24_17.thumb.png.ad887c606c1bc73a25a34141bb00406d.png

 

Upper Ruler is in milliseconds. We can see that all loopback audio is about 1 ms late; this is true for the metronome, the Ultrabeat click (coming directly from MIDI data) and the Ultrabeat click coming from the BiP file (the transients of this one don't line up with the other two because the transient in the BiP file is a bit late).

 

The two Ultrabeat tracks at the top were used for the MIDI loopback.

First track was used for pure MIDI loopback without Audio; recorded MIDI data is about 3 ms early.

Second track was used for combined audio/MIDI loopback (together with the Audio track below it); MIDI is here about 5 ms early. (this decreases later)

 

All tests done with an M-Audio M-Track 2x2M and a buffer size of 1024.

 

Preliminary conclusions: There's somewhere an audio driver error of roughly 1 ms lurking; otherwise audio loopback seems to be consistent. MIDI loopback is early and somewhat "jittery": the first notes are even "earlier" than the following. Pure MIDI loopback: the first two notes were 6 ticks early, the rest 4 ticks. Combined Audio/MIDI loopback: the first notes were 10 ticks early, the rest again 4 ticks.

Link to comment
Share on other sites

Ok, so you've confirmed that recording midi directly from the output of the interface at the same time as recording audio from the output of the interface yields recordings that sits just about perfect or like 3-4 ms off. The same that I did but you did it on your hardware and conducted the test simultaneously, correct?

 

I post another video that confirm that my model above about audio/midi-sync seems to be correct.

 

Here an external instrument region has 4/4 notes with midi repeating. During recording it is sent to the nord stage and record the audio. According to my understandning, the midi travels without any noticeable delay to the nord stage, arrives at time t, the nord plays the sound, that sound arrive in logic at time t+d2. Logic then continues to latency-compensate the audio track by removing d1+d2 from t+d2 which yields

t+d2 - (d1+d2)=t-d1

The audio sits before the beat by d1 ms, in this case about 25-30 ms.

 

EDIT: to fix this I go in the midi settings menu and add 27 ms of delay. I thought you said that Logic does this automatically, or maybe I misunderstood? After that change the recording of the audio is almost exactly on the beat.

Link to comment
Share on other sites

I'll try to do a test on different hardware tomorrow, but in general I'd suspect a driver "problem" here.

There are different layers to latency compensation and at each step something can go wrong. Logic has to compensate for different types of latency: latency introduced by plugins and instruments and latency originating with the buffer size and audio driver.

Especially the latter can be tricky because the driver's behavior can be unpredictable (it shouldn't, though!).

 

One thing should have become more clear: The problem seems NOT to be that Logic places the recorded MIDI data too late; it seems more as if Logic "overcompensates" the latency for incoming audio. The solution for this problem should consequently NOT come from delaying MIDI data (which could open a completely different can of worms) but from fixing the "overcompensation".

 

As I wrote: I'll look into this tomorrow.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...