Speed up playback so that a click becomes a note

I would like to try something funny. I want to take a percussive click and play it so fast that the single clicks melt into a “line” of sound. Then if I speed it up faster the sound becomes higher and if I slow it down, it becomes lower. Much like a car engine which sounds higher if the engine runs fast and lower if the engine runs slow. I tried to implement it by modifying the sleep time. However, this produced an error because the thread could not sync anymore. No big surprise tbh :wink: Here’s my code:

define :linearMelody do
  delta = -0.01
  minimum = 0.0001
  maximum = 0.5
  value = maximum
  
  loop do
    value = value + delta
    
    # invert direction if we hit minimum or maximum
    if (value <= minimum or value >= maximum)
      delta = delta * -1.0
    end
    
    sample :tabla_ke1
    sleep value
  end
end

linearMelody

Here’s the error:

SonicPi::Lang::Core::ZeroTimeLoopError
Thread death!
loop did not sleep or sync!

It happens as soon as the desired effect kicks in.

I hope you get the idea of what I’m trying to do. Is there another way to do this?

This is called granular synthesis. :slight_smile:

It’s usually implemented within an audio/synth engine rather than through abuse of a sequencer. There are lots of ways to do granular in supercollider but none are exposed through the current set of SonicPi instruments.