Synching samples

Hello,

I downloaded a sample pack and wanted to use a 124BPM beat which has a duration of
7.741950113378685 seconds.

My code:

use_bpm 62

live_loop :metronome do
  sleep 1
end

beats = "path to samplepack"
sample_beat = beats, 7

live_loop :beat, sync: :metronome do
  sample sample_beat, beat_stretch: 8
  sleep 8
end

live_loop :cowbell, sync: :beat do
   sample :drum_cowbell
   sleep 1
  end
end
  1. question: What does the timer start at 0.9677 and not 1?
    {run: 31, time: 0.0}
    └─ 8.000015117157975

{run: 31, time: 0.9677, thread: :live_loop_beat}

  1. question:
    For example I want to add a cowbell sound with sleep 1. Obviously they are going quickly out of sync due to the samples duration. How do I work with this? My current solution is to beat_stretch it to 8, sleep for 8 and change the bpm to 62 to keep the same pitch. However the sample duration is still not exactly 8 unless I change the bpm to 60 * (8 / 7.741950113378685) which doesn’t seem to be the way to go.

Additionally, how would I got about syncing a 120bpm sample with a 124bpm sample?

I just found this thread here: http://in-thread.sonic-pi.net/t/playing-external-samples-in-time-with-each-other/1407/2

I tried working with use_sample_bpm and got to this:
The beat sample has an original duration of 15 seconds and the HiHat sample has a duration of 16 seconds. How do I get them together with a cowbell in sync?

beats = "Bass/"
sample_beat = beats, 1

use_sample_bpm sample_beat, num_beats: 4

live_loop :beat do
  sample sample_beat
  sleep 4
end

j = 0
live_loop :hihat do
  samps = "Hi Hats/"
  sample samps, j
  sleep sample_duration(samps,j)
end


live_loop :cowbell do
  sample :drum_cowbell
  sleep 0.125
end

Thanks!

This is because the loop :beat is synced to :metronome. As these both start at the same time it actually misses the first cue and starts on the second 1 beat later. Since your bpm is 62 this is at realtime 60/62 = 0.9667
To get them to start together on the first cue you could delay the metronome by say 0.05 using
live_loop :metronome, delay: 0.05 do

Then your timings would start from 0.05 * 60/62 = 0.048
Essentially a cue is only received if there is a sync preceding it in time set up. The delay to metronome starting achieves this.

You could sync cowbell to the start of one of the other samples by using a sync within the the loop :cowbell
eg

live_loop :beat do
  sample sample_beat
  sleep 4
end

live_loop :cowbell do
sync :beat
  sample :drum_cowbell
end

would give one cowbell at the start of each sample_beat

Alternatively

live_loop :cowbell do
  sync :beat
  3.times do
    sample :drum_cowbell
    sleep 1
  end
  sample :drum_cowbell
end

would give a cow_bell each beat (assuming 60 bpm). Missing the last sleep allows it to sync at the start of the next sample_beat