About the with_fx time

I created the following program to sound an effect every 2 seconds to make a sample with_fx.
In spite of sleep 2, the time interval became about 2.178.
Why is this?
If I make the with_fx line a comment line, the time interval becomes 2 seconds.

The beat values were the same for both.
It was different when recorded and measured with Audacity.

fx_names.length.times do |i|
  if i!=29 then
    with_fx fx_names[i] do
    play :C4, attack:0,decay:0,sustain:1,release:1
    sleep 2
    end
  end
end

Hi there,

that’s odd and not something I’ve ever observed. Whilst it’s true that the with_fx takes some time to setup the FX, everything is running with 500ms of ‘space’ so unless it takes longer than 500ms to setup (which I’m highly doubting) you shouldn’t see any timing issues at all.

Do you have ‘enforce timing guarantees’ enabled? That should stop the call to play if it’s actually late, so if the interval is 2.178 on your system, you shouldn’t actually hear any plays at all.

What happens if you call sleep before play - so just swapping those two lines around. Does that change the behaviour?

Also:

  • What system are you running on?
  • What does the GUI log say?
  • What if you just chose the same FX every time - say :krush - do you still observe the same timing issue?
  • Is the time interval consistently 2.178 or is that an mean average?

Thank you Sam,
Environment,
iMac 28inch 2020, Sonoma 14.2.1
Sonic Pi 4.5.0

‘enforce timing guarantees’ was disabled.
I think the time interval is not consistently.
However, when only :krush was used, it was the same length as noFx.
The figure shows, from top to bottom, the above program, fx commented, enforce timing guarantees, and :krush only.
One effect appears to be missing, but did not appear in the log file.

Log with_fx
=> Starting run 153

{run: 153, time: 0.0}
├─ 0 :autotuner
└─ synth :beep, {note: 60.0, attack: 0.0, decay: 0.0, sustain: 1.0, release: 1.0}

===
{run: 153, time: 79.9984}
├─ 41 :wobble
└─ synth :beep, {note: 60.0, attack: 0.0, decay: 0.0, sustain: 1.0, release: 1.0}

{run: 153, time: 81.9984}
└─ Stopped internal thread

Log without fx
no Fx
=> Starting run 154

{run: 154, time: 0.0}
├─ 0 :autotuner
└─ synth :beep, {note: 60.0, attack: 0.0, decay: 0.0, sustain: 1.0, release: 1.0}

===
{run: 154, time: 80.0073}
├─ 41 :wobble
└─ synth :beep, {note: 60.0, attack: 0.0, decay: 0.0, sustain: 1.0, release: 1.0}

{run: 154, time: 82.0073}
└─ Stopped internal thread

Hi, can you help me understand what’s wrong with the image - it appears as expected on an initial look to me.

Also, are you observing drift - in that the “badly timed” events also make all the subsequent events late - or are you just seeing specific events appear later than expected but all the rest on time?

Sorry, this was all my mistake.
with_fx fx_names[0] do
puts i,fx_names[0]
play :C4,attack:0,decay:0,sustain:1,release:1
sleep 2
end
The volume of this was zero, so I had to delete it on Audacity, resulting in a shorter overall time.

Oh no worries at all. Great to get the bottom of it.

Sonic Pi having rock solid timing is very important to me which is why I took this issue very seriously. It’s always good to double check things anyway.

Have fun with Sonic Pi!