Ableton / link

Ableton Link
Other
1.09k stars 149 forks source link

Add missing methods to Linux Clock implementation. #97

Open marcel303 opened 3 years ago

fgo-ableton commented 3 years ago

What is the reason you want to add this? The reason those exist in the darwin is to allow convenient conversion from/to core audio timestamps. There is no such "native" linux timestamp format. As far as I can tell any necessary conversions should be doable using std::chrono.

marcel303 commented 3 years ago

What is the reason you want to add this? The reason those exist in the darwin is to allow convenient conversion from/to core audio timestamps. There is no such "native" linux timestamp format. As far as I can tell any necessary conversions should be doable using std::chrono.

Hm, I was under the impression somehow I should use ticks for time stamps. Not sure where I got that idea (maybe I copy-pasted some example code). I've used ticks through out the code base before I began porting to Linux. But if I understand you correctly, I should be using micros for the cross-platform code, and use ticksToMicros to convert mHostTime on macOS to micros?

fgo-ableton commented 3 years ago

ticks() just calls mach_absolute_time(). mach_absolute_time() should be used with caution. I.e. it behaves differently on arm and x86. So I would not recommend to use this as the general time unit for an app that is supposed to support multiple platforms. I.e. if you want to do some calculations using a sample rate value and time value, you will have to know the unit. You can use mach_timebase_info to convert the result of mach_absolute_time() to nanoseconds. In Link we use microseconds as a unit for time as this makes sense regarding accuracy and data being transmitted over the network. If microseconds makes sense for your application you could use that. If you have other requirements something else might make more sense.