COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 09-12-2018, 10:04 AM   #1
teatime
Human being with feelings
 
teatime's Avatar
 
Join Date: Aug 2016
Location: South Africa
Posts: 44
Default Midi Sync Hair Splitting

Good day
I am generating midi events that are supposed to coincide with beat divisions, and, for the most part it's going well.

There is a little niggle that I'm having a lot of trouble getting rid of though. It seems my midi, while sounding perfectly in time, dangles very slightly to the left of the beat divisions.


Behold, it dangles.

The Plan was to look at the sample position in processDoublesReplacing for each window, and if a note is supposed to take place in that window, send it.



This is with the grid @ 1/1024ths, so it really is near vanishingly minor, and stays consistent for all note lengths... but it's not perfect, which is worrisome.

Am I missing something fundamental here?

Code:
double samplesPerNoteDiv = samplesPerBeat * pow(2,(noteLength + 2));
double beatPosition = samplePos / IPMAX(samplesPerNoteDiv, 1);
int nextBeat = ceil(beatPosition);
int samplesBeat = nextBeat * samplesPerNoteDiv;

if (samplesBeat >= samplePos && samplesBeat < samplePos + nFrames) {
	if (pattern[nextBeat % length % steps] == 1) {
		int offset = samplesBeat - samplePos;
		msg->MakeNoteOnMsg(60, 64, offset); 
		return true;
	}
	else {
			return false;
	}
} 
else {
	return false;
}
(While I'm trying to get things to sync a notelength is just half the beat div, but the dangly bit on the right is hopefully related to the dangly bit on the left)

Last edited by teatime; 09-13-2018 at 01:27 AM. Reason: Removed some noise.
teatime is offline   Reply With Quote
Old 09-13-2018, 01:37 AM   #2
teatime
Human being with feelings
 
teatime's Avatar
 
Join Date: Aug 2016
Location: South Africa
Posts: 44
Default

Perhaps phrased differently, is there somewhere in Reaper I can find really accurate note position information to determine if it's just a visual glitch, or it it's really dangling?

Note properties shows the beat position as being correct, but visual inspection shows a dangle - switching to samples view on the timeline means I can't see where it's supposed to be, although I could use a calculator and determine the correct sample position and find out </rubberduck>.
teatime is offline   Reply With Quote
Old 09-13-2018, 12:12 PM   #3
pressplay
Human being with feelings
 
pressplay's Avatar
 
Join Date: Sep 2017
Location: Berlin
Posts: 47
Default

Without having inspected your code in detail, there is one thing that comes to my mind immediately. It may not be your fault, but an unprecise latency compensation in your DAW. Is this error time constant? What happens if you change your audio buffer size?
pressplay is offline   Reply With Quote
Old 09-15-2018, 08:06 AM   #4
teatime
Human being with feelings
 
teatime's Avatar
 
Join Date: Aug 2016
Location: South Africa
Posts: 44
Default

I did a little experiment and it seems it's not even deterministic. For a given note size and bpm, while recording, it is consistent (every note offset by about x samples), but when I change the bpm and come back, it is a new, different value:

eg. for 1/64th notes I got the following..
Code:
bpm     sampleoffset
85      11 
86      6
140     0
160     4
15      2
300     0
but when I came back to 86 again, it was now 5 samples too late, instead of 11 too early; checking out the others yielded similar results.

We're talking about +- 360us, so it's not that significant, and for a given BPM, when I am recording, regardless of whether I change the note size, all offsets are the same.

Changing the BPM without playing, and changing it back has no effect.
Changing to another BPM, hitting play, and changing back does change it though.
Changing the BPM while playing I can't really tell, because of how the notes are positioned.

¯\_(ツ)_/¯

As far as I can tell the code that I wrote is supposed to be 100% deterministic, so this is pretty wild.

[using wdl-ol / reaper (latest)]
teatime is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.