Can someone explain "Onset"


#1

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?


How to access data from onset function (using lambda)?
#2

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!


#3

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


#4

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.