Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp precision #11

Open
OlivierSohn opened this issue Jul 12, 2018 · 4 comments
Open

Timestamp precision #11

OlivierSohn opened this issue Jul 12, 2018 · 4 comments

Comments

@OlivierSohn
Copy link
Member

OlivierSohn commented Jul 12, 2018

The Timestamp (type Timestamp = CULong) precision is currently milliseconds, which is enough to introduce midi-jitter of up-to one millisecond. I guess that in some applications, it could be audible, and some platforms (OSX for example) provide nanosecond precision for MIDI timestamps, so we could rewrite portmidi to take advantage of the full resolution, where it is available.

I'd like to propose a PR where the full precision is kept.
(After looking at it a bit more, it looks like it's a big task... and we would need some unit tests to make sure nothing is broken.)

Since it's a breaking change, to avoid undetected bugs when upgrading, I think the type should be changed, I propose newtype NanoTimestamp = CULLong.

What do you think?

@OlivierSohn
Copy link
Member Author

OlivierSohn commented Jul 12, 2018

In portmidi.h, this:

/*
    PmTimestamp is used to represent a millisecond clock with arbitrary
    start time. The type is used for all MIDI timestampes and clocks.
*/
typedef long PmTimestamp;

would then be replaced by:

/*
    PmTimestamp is used to represent a nanosecond clock with arbitrary
    start time. The type is used for all MIDI timestampes and clocks.
*/
typedef unsigned long long PmTimestamp;

@OlivierSohn
Copy link
Member Author

For alsa, snd_seq_ev_schedule_real (with absolute timestamp) would replace snd_seq_ev_schedule_tick which only has millisecond relative precision

@ninegua
Copy link
Member

ninegua commented Jul 12, 2018

Platform dependent behaviors are tricky to implement or test. But if you think the change is worth the effort, I've no problem with added precision.

@OlivierSohn
Copy link
Member Author

Initially I was ready to do the implementation, but now, I think I can live with a millisecond precision :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants