Can someone explain "Onset"

I have been using “onset” in my code with fun results after discovering it from another users code. I’d like to know in detail what it does but I can’t find it in the tutorial document. Is it chopping the sample based on transients or into equal chunks? How does it know how finely to chop up the samples?

1 Like

The reference material for onset is part of the “sample” documentation in the Lang part of the Help.

It is chopping up samples by transients. As far as I understand it, the sample will be chopped up with each part being given an index. The argument given to the onset function itself is picking which chopped part of the sample will be played (0 = 1st chop, 1 = 2nd chop etc). You can also include release to adjust how long the chop will last for, but it will stop before the next transient regardless.

Here’s an example of using it with the Amen break. Right now it is just playing the kick drum but if you change the argument for the onset function, it will give you a different sound.

live_loop :amenOnset do
  sample :loop_amen, onset: 0, release: 0.25
  sleep 0.25
end

Once you have figured out what each index is playing, you could easily isolate different drum sounds and make your own beats.

Here’s a very crude example

live_loop :amenKick do
  sample :loop_amen, onset: 0, release: 0.25
  sleep 2
end

live_loop :amenSnare do
  sleep 1
  sample :loop_amen, onset: 2, release: 0.25
  sleep 1
end

live_loop :amenHat do
  sample :loop_amen, onset: 4, release: 0.25
  sleep 0.25
end

I have had a lot of fun with using **onset: pick**to get random patterns of the different chopped samples. I’ll include a repetition block to have a repeated pattern in my loop along with use_random_seed and just keep picking random seeds until I get something I like. The example below came out pretty cool and it was just from entering a random number for the seed!

live_loop :amenRandom do
  use_random_seed 80708
  16.times do
    sample :loop_amen, onset: pick, release: 0.25
    sleep 0.125
  end
end

Finally, to add some rhythmic variation, I like to use a knit to get different groupings of sleep times. The number of times it repeats is just adding up all the number of times each value happens in the knit. For this example, 8 + 4 + 4 + 2 + 4 + 2 = 24.times

live_loop :amenKnit do
  use_random_seed 42341
  24.times do
    sample :loop_amen, onset: pick, release: 0.3
    sleep (knit, 0.125, 8, 0.25, 4, 0.125, 4, 0.25, 2, 0.125, 4, 0.25, 2).tick
  end
end

Just for reference, slice: along with num_slices: is the function to be used to get chopped samples that are equal chunks. This is also documented under sample.
Here’s a link to video a made a while back exploring the slice: function to chop up a break beat.

Hope this is helpful. @samaaron recommended onset to me a while back, promising that it would blow my mind and he wasn’t wrong!

5 Likes

Ahh perfect that clarifies things. And the knit tip will come in handy.

This inspired me to try and make a visual representation of how onset works. I think it came out pretty good. I posted it here.

3 Likes

This is very interesting. I hadn’t used onset, nor pick before. It’s quite easy to get something interesting and distant from the original looped sample. I’m definitely going to be using this more in the future.

use_bpm 127

roots = (ring :e1, :e1, :g1, :g1, :a1, :a1, :b1, :b1 )

beat_stretches = (ring 4, 4, 4, 2, 8, 8, 4, 1 )

set_mixer_control! limiter_bypass: 1

live_loop :amenchop do
  tick
  bs = beat_stretches.look
  
  in_thread do
    use_random_seed 234
    
    16.times do
      sample :loop_amen, amp: 0.3, pan: -1, onset: pick, beat_stretch: bs if one_in(1.25)
      sleep 0.25
    end
  end
  
  in_thread do
    use_random_seed 896
    
    16.times do
      sample :loop_amen, amp: 0.3, pan: 1, onset: pick, beat_stretch: bs if one_in(1.25)
      sleep 0.25
    end
    
  end
  
  2.times do
    sample :bd_haus, amp: 1
    sleep 1
    sample :bd_haus, amp: 0.7
    sample :sn_dolf
    sleep 0.75
    sample :sn_dolf, amp: 0.2 if one_in(2)
    sleep 0.25
  end
end

live_loop :bass do
  tick
  use_random_seed 2835
  
  use_synth :tb303
  use_synth_defaults amp: 0.1, sustain: 0.2, release: 0.05, cutoff: 130, cutoff_slide: 0.2, res: 0.9
  
  with_fx :eq, low_shelf: 0.7 do
    
    16.times do |i|
      if i == 0 || one_in(2)
        if i > 0 && one_in(2)
          
          sn = play roots.look
          
        else
          sn = play roots.look + 12
        end
        
        control sn, cutoff: 0
      end
      
      sleep 0.25
    end
  end
  
end




4 Likes