# Creating a sync track with a sample playing

**URL:** <https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570>\
**Category:** Support, Help & Resources\
**Created:** [February 21, 2023, 2:06pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570 "2023-02-21T14:06:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 2:06pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/1 "2023-02-21T14:06:25Z")

</div>

Hello,

I’m very new here and try using Sonic Pi for one purpose, for now.

I want to create a sync track to send to some hardware, which plays a sample 24 times per beat.

I got to the point where I have Sonic Pi syncing with Ableton Link, I can play my sample in a loop but am unsure about the 24 times per beat bit.

What would be a reliable way to do what I want? As simple as possible?

Thank you!

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [February 21, 2023, 2:43pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/2 "2023-02-21T14:43:47Z")

</div>

I’m not sure if I understand exactly, but if you sleep for a 24th of a beat in your loop, then the loop will run 24 times per beat. Does this do what you want:

```ruby
live_loop :beat do
  sample :the_sample
  sleep 1.0 / 24
end

```

---

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 2:45pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/3 "2023-02-21T14:45:29Z")

</div>

Thanks! That’s close to what I thought, didn’t know I could to 1.0 / 24. Will try!

---

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 2:49pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/4 "2023-02-21T14:49:04Z")

</div>

> [@emlyn](#):
>
> `1.0 / 24`

Just listening to the output in a headphone (couldn’t try using the signal for sync yet), it is not constant. Could there be timing issues/streaming issues? Is there something to do for steady output and streaming?

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [February 21, 2023, 2:56pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/5 "2023-02-21T14:56:47Z")

</div>

I tried it myself and the timing seemed pretty steady - I couldn’t hear any variation. Are you using wired headphones? If they are bluetooth it’s possible they could be introducing some timing fluctuations.

---

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 2:59pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/6 "2023-02-21T14:59:09Z")

</div>

No I use an RME soundcard, wired headphones into it. Should be solid. I’ll try on my music machine later.

---

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 3:29pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/7 "2023-02-21T15:29:28Z")

</div>

> [@emlyn](#):
>
> ```ruby
> live_loop :beat do
> sample :the_sample
> sleep 1.0 / 24
> end
> 
> ```

I now tried in the real world case I was intending. The receiving device in an ERM Multiclock, which generates MIDI clock based on that sample playback.

Using Sonic Pi this way, I can see the tempo varying around the target tempo. When I do the same in say Ableton Live, it is steady.

That may be also caused by the fact that I use an ASIO driver for my RME UCX soundcard in Ableton Live, while I haven’t found that option in Sonic Pi (did I miss it?), so it’s using and WDM driver, for the same soundcard.

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [February 21, 2023, 3:38pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/8 "2023-02-21T15:38:45Z")

</div>

It could be the driver. I don’t use Sonic Pi on Windows, but this thread might be helpful: [[SOLVED] Select ASIO Driver?](https://in-thread.sonic-pi.net/t/solved-select-asio-driver/847)

---

<div class="post-metadata">

**Author:** ![amaury](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@amaury](https://in-thread.sonic-pi.net/u/amaury)\
**Post date:** [February 21, 2023, 3:48pm UTC](https://in-thread.sonic-pi.net/t/creating-a-sync-track-with-a-sample-playing/7570/9 "2023-02-21T15:48:35Z")

</div>

Thanks a lot for your help @emlyn , I appreciate!
