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
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.
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
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?
@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 - 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.
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.
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