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

Thread sync/drift #2

Closed
whaleygeek opened this issue Sep 8, 2013 · 1 comment
Closed

Thread sync/drift #2

whaleygeek opened this issue Sep 8, 2013 · 1 comment

Comments

@whaleygeek
Copy link

Hi, been doing some work with CA, I noticed that if I start 3 threads running at default BPM, after a few bars they get a bit out of sync. I wasn't sure whether you had built in thread synchronisation into your core code, or whether it was up to the user to do their own sync between threads. Either are ok of course, but I wasn't sure if you were expecting users to realise that they need thread synchronisation and then read about how to do it as part of the learning experience, or whether you had provision for it to happen automatically in your code so readers could just code multiple tracks out of the box.

Code below as an example, excuse my crap ruby code I'm not really a ruby programmer: I have a separate thread showing the bar and beat number so I can keep track of everything on the screen, the thread that starts playing after 3 bars on my Raspberry Pi is already out of sync. If I remove this bar counting, it does still get out of sync eventually so I think even if there was a startup latency in the threads, there still appears to be some drift over time.

C=60
D=62
E=64
F=65
G=67
A=69
B=71
octave=12
major = [0,2,4,5,7,9,11,12]
pentatonic = [1,3,6,8,10]
d=1.0

bar=0
beat=0
in_thread do
loop do
sleep d
beat=(beat+1)%4
if beat==0
bar = bar + 1
print "**** "
print bar
print "\n"
end
end
end

by the time this thread reaches it's target bar

time has drifted enough to be noticeable

in_thread do
note=C+12
loop do
if bar>3
play note
end
sleep d/2
end
end

in_thread do
with_synth "beep"
note=C
loop do
play note+pentatonic[rand(5)]
sleep d/2
end
end

in_thread do
note=C-octave*2
with_synth "beep"
loop do
play note
sleep d
play note
sleep d
play note
sleep d/2
play note
sleep d/2
play note
sleep d
end
end

in_thread do
with_synth "saw_beep"
loop do
note = C+pentatonic[rand(5)]
play note-(octave)
sleep d
end
end

@samaaron
Copy link
Collaborator

Hi there,

I haven't added any thread synchronisation to Sonic Pi. This is going to be a feature for a future version :-)

samaaron pushed a commit that referenced this issue Oct 6, 2014
This was referenced Sep 25, 2015
hzulla added a commit to hzulla/sonic-pi that referenced this issue May 2, 2016
samaaron added a commit that referenced this issue May 12, 2016
Moving towards weblate #2: Activate translation sync of Qt GUI through weblate
lostapathy added a commit to lostapathy/sonic-pi that referenced this issue Nov 28, 2017
# This is the 1st commit message:

remove USE_RVM

All builds had USE_RVM set, so removing conditional that didn't use it
as well as the env variable itself.

# This is the commit message sonic-pi-net#2:

Update to latest ruby versions

Updating to latest ruby versions and simplifying travis syntax
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