-
Notifications
You must be signed in to change notification settings - Fork 757
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
scsynth: use CoreAudio host time to calculate time of day offset #5298
scsynth: use CoreAudio host time to calculate time of day offset #5298
Conversation
In macOS Big Sur, the clock provided by `high_resolution_clock` (using `mach_absolute_time`) drifts apart from the host time reported by CoreAudio. This is most apparent after a computer running Big Sur is in sleep mode for a bit, causing sounds from SuperCollider to be played after their scheduled time roughly by the amount of time the computer slept. This change makes it so that the time of day offset is calculated against the CoreAudio host time (instead of `high_resolution_clock` time) since that offset is later used against the CoreAudio host time to get OSC time. This commit effectively reverts the changes in 95a6604. See discussion in supercollider#5168.
3f60a8f
to
1a74fd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lilyinstarlight
Aside from fixing the issue on 11.1, I have tested this on macOS 10.13 and could not see any regressions (details below). I think this is the correct solution.
However, I'd prefer if someone else looked this over before merging (@muellmusik / @joshpar / @brianlheim ?)
As @lilyinstarlight mentioned, full discussion is in #5168, some relevant comments: #5168 (comment), #5168 (comment)
To test this, I checked whether bundle time offset is consistent after running the server for some time.
I started two servers, one from a regular develop build, one from this PR, and was scheduling them with short sounds simultaneously, playing to left and right channel, respectively. I've let them run for 2+hrs and they did behave exactly the same after these two hours. (the scheduling is not sample accurate, as the server started at different times and I suspect that their audio callbacks are not aligned; either way the sound result was the same whether I was running two copies of the regular server, or one regular server and one from this PR, and was also the same at the beginning of the test vs 2 hrs later)
~local = Server.default;
~local.boot;
~local.makeGui;
~local.meter;
~other = Server(\testing, NetAddr("localhost", 57112));
Server.program_("/path/to/server/from/this/pr/SuperCollider.app/Contents/Resources/scsynth"); //run this to use a different executable for the second server
~other.boot;
~other.makeGui;
~other.meter;
(
SynthDef(\impulse, {|out=0, amp=1|
Out.ar(out, WhiteNoise.ar(amp) * Env.perc(0, 0.01).ar(Done.freeSelf))
}).add;
)
//test
~local.sendBundle(0.1, [\s_new, \impulse, -1, 0, 1, \amp, 0.125, \out, 0]); // regular server: left channel
~other.sendBundle(0.1, [\s_new, \impulse, -1, 0, 1, \amp, 0.125, \out, 1]); // PR test server: right channel
(
~routine = Routine.run({
loop{
~local.sendBundle(0.1, [\s_new, \impulse, -1, 0, 1, \amp, 0.125, \out, 0]);
~other.sendBundle(0.1, [\s_new, \impulse, -1, 0, 1, \amp, 0.125, \out, 1]);
1.wait;
}
})
)
~local.dumpOSC(1);
~other.dumpOSC(1);
(
~routine.stop;
~local.quit;
~other.quit;
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Purpose and Motivation
See discussion in #5168
In macOS Big Sur, the clock provided by
high_resolution_clock
(usingmach_absolute_time
) drifts apart from the host time reported by CoreAudio. This is most apparent after a computer running Big Sur is in sleep mode for a bit, causing sounds from SuperCollider to be played after their scheduled time roughly by the amount of time the computer slept.This change makes it so that the time of day offset is calculated against the CoreAudio host time (instead of
high_resolution_clock
time) since that offset is later used against the CoreAudio host time to get OSC time.This commit effectively reverts the changes in 95a6604.
I read through the wiki page for making pull requests (and didn't know what I could make in terms of a regression test for this change) but let me know if there is anything else I should do!
I know there was still discussion in #5168 on clocks and timing in regards to this change and I will defer to the maintainers on whether this is a proper solution or not.
Types of changes
To-do list