Crackling sounds in simple melody

Hi all,

I recently started out with Sonic Pi and am currently trying to create various melodies. Unfortunately, I am getting annoying crackling sounds for simple melodies combined with a beat. The following code produces those crackling sounds, but works fine, when removing the :beat loop.
I am working on a SurfaceBook 2 with an i7-8650U, having ruby.exe and scsynth.exe set to realtime priority. Can anyone point out a solution to this?

Thanks
Kevin

define :beat_a do |s|
  sample :bd_klub, cutoff: 60, amp: 4
  sleep s
end

define :chord_prog do |scl,chords|
  c_map = [:major, :minor, :minor, :major, :major, :minor]
  return chords.map { |it| chord scl[it], c_map[it] }
end

tact = 0.5

live_loop :beat do
  beat_a tact
end

live_loop :melody do
  use_synth :fm
  tick_reset
  prog = chord_prog((scale :eb2, :major), [5,4,2,3])
  prog.length.times do
    tick
    play_pattern_timed prog[look], tact/2
    sleep tact
  end
end

Hi @kevlatus,

What power management settings do you have enabled on your computer? Things might suffer a little bit more sometimes if your computer is prioritising reduced power consumption over high performance.

1 Like

Thanks for your quick reply, Ethan!
I am using the “best performance” settings as can be seen below.

Beyond that I’m not too sure to be honest, hopefully someone else might have some ideas :slight_smile:

I think you are generating lots of play command resources that will accumulate as they last longer than the time between them. Try changing the play_pattern line to

play_pattern_timed prog[look], tackt/2, release: tackt

This will ensure that the sounds die away during the sleep tack before the next iteration of the times loop starts.

I don’t really think that has anything substantially to do with the code (of course… in the end it is always the code ;). I can run this for a minute or so (did not try longer) having set tact = 0.25, thus double speed, without any warnings or cracks (xruns); the DSP load is pretty low. That’s on SP 3.2, Linux Mint 19.3, Intel Core i7, 16GB RAM and of course Jack Audio.

Just a shot in the dark (I noticed several posts concerning performance and Windows mentioning this): You are using the ASIO driver, right?

thanks for your tips, guys!

@robin.newman: changing the release sounds nice too, but there still are crackling sound.
Out of curiosity, I installed Sonic Pi on an Ubuntu machine and the code runs without any issues at all.

@Martin: I looked at the ASIO driver, which looks promising, but I was unable to set up Sonic Pi to use it. Is there any guidance on how to use ASIO with Sonic Pi (I couldn’t find one)?

Hi @kevlatus,

sorry, I can’t be of any help because I have no system Windows running. Did you check the postings here in this forum?

Hi @Martin,

yes, I already did and could not find a viable option, so I reached out to Sam for help. Thanks for your efforts!

1 Like

Hi @kevlatus - you currently have to hack the source to modify the default audio driver.

In the upcoming beta, you’ll be able to do this via a settings file which will be much easier - hopefully that will be out next week some time. I’m currently re-plumbing the entire MIDI system and am almost finished with that.

In the meantime, if you’re happy editing the source directly you could try this: https://github.com/samaaron/sonic-pi/issues/1881#issuecomment-386576806

This might be completely wrong, but is it just clipping? - It seems quite loud when I play it and by adding set_volume! 0.5 to the beginning seems to work for me.

set_volume! 0.5
rest of the code....
3 Likes

This is definitely possible - although by default there’s a compressor on the end of the signal chain which should stop clipping from happening at all.

so, I dug kinda deep into this issue by trying out ASIO drivers and compiling the latest version of SonicPi from source on Linux.
Interestingly, this issue also occurs on v3.2.2 on Ubuntu 20.04, but not on v2.10, which is available from APT.
Besides that, @binarysweets idea of reducing the volume was the only solution to remove the sounds.

Guess, I will try out another melody while waiting for the next release :sweat_smile:

So, does reducing the volume in Sonic Pi remove the issues you’re hearing?

yes! putting set_volume! 0.5 at the top of the code, removes the issues

1 Like

Wow, ok, that’s very useful to know. Certainly sounds like your sound card is clipping the audio somehow.

Thanks for letting me know that it fixes things for you!

sure, thanks for helping out and creating this awesome tool!

I’m already looking for an external audio interface.

1 Like

I’d be very interested to know if using an external interface solves this issue too :slight_smile:

sure, I will give an update once it is here :+1:

sooo, I just tried this on the new audio interface without any other precautions and it works like a charm!

1 Like