Sample cutoff / choke groups

Hello everyone! I’m working on a sample slicing program that allows me to use my midi keyboard to add slices to a sample at points I choose using my keyboard’s control dials, and play back the slices using my keyboard’s pads. Everything works so far, but I need some kind of way to have a sample that starts playing cut off previously playing samples. Is there something similar to choke groups in Sonic Pi? If not, is there a way to stop all currently playing sounds/samples?

1 Like

Could you explain a little more about choke groups? What kind of code would you like to be able to write and what should it do?

For choking hi-hats, I use this method:

use_bpm 130

define :sample_choke_group do |group,samp,args={}|
  player = get group
  
  if player != nil
    control player, amp_slide: 0.01, amp: 0
  end
  
  use_sample_defaults args
  player = sample samp
  set group, player
end

live_loop :drums do
  
  at [0, 1.5, 2] do
    sample :bd_haus
  end
  
  at [ 1, 3 ] do
    sample :sn_dolf, pan: 0.5
  end
  
  7.times do
    sample_choke_group( :hat_group,
                        :drum_cymbal_closed,
                        pan: -0.5 )
    sleep 0.5
  end
  
  sample_choke_group( :hat_group,
                      :drum_cymbal_hard,
                      pan: -0.5, amp: 0.5 )
  sleep 0.5
end

It doesn’t actually stop the sample playing, just sets its volume to zero. This isn’t a problem for me running code on a Mac where the sample will finish quite soon, but may be a problem for longer samples if a large number of silent sample players end up working at once on a less powerful computer such as a Raspberry Pi.

EDIT: I tried the following. It still works, and might be stopping the choked synth player. Not sure if it’s saving computer power:

use_bpm 130

define :sample_choke_group do |group,samp,args={}|
  player = get group
  print player
  
  if player != nil
    control player, amp_slide: 0.01, amp: 0
    
    at 0.01 do
      control player, on: false
    end 
  end
  
  
  
  use_sample_defaults args
  player = sample samp
  set group, player
end

live_loop :drums do
  
  at [0, 1.5, 2] do
    sample :bd_haus
  end
  
  at [ 1, 3 ] do
    sample :sn_dolf, pan: 0.5
  end
  
  7.times do
    sample_choke_group( :hat_group,
                        :drum_cymbal_closed,
                        pan: -0.5 )
    sleep 0.5
  end
  
  sample_choke_group( :hat_group,
                      :drum_cymbal_hard,
                      pan: -0.5, amp: 0.5 )
  sleep 0.5
end



can you use kill to do this?
eg

k=sample :ambi_glass_hum
sleep 1
kill k #cuts it short after 1 beat
1 Like

Oh, I hadn’t used kill. I suppose I shouldn’t answer questions just yet :slight_smile:

New version:

use_bpm 127

define :sample_choke_group do |group,samp,args={}|
  player = get group
  
  if player != nil  
    kill player
  end
  
  use_sample_defaults args
  player = sample samp
  set group, player
  return player
end

vars = (ring false, false, false, true)

live_loop :drums do
  tick
  
  at [0, 1.5, 2] do
    sample :bd_haus
  end
  
  at [ 1, 3 ] do
    sample :sn_dolf, pan: 0.5
  end
  
  if vars.look
    at 3.5 do
      
      sample :sn_dolf, pan: 0.5
    end
  end
  
  7.times do
    sample_choke_group( :hat_group,
                        :drum_cymbal_closed,
                        pan: -0.5 )
    sleep 0.5
  end
  
  sample_choke_group( :hat_group,
                      :drum_cymbal_hard,
                      pan: -0.5, amp: 0.5 )
  sleep 0.5
end

Simply killing the player seems to work fine. No clicks. I don’t know if it will click on other sounds.

provided you have a reference to the sound it should work with play as well eg

k = play :c4, sustain: 50, release: 1
sleep 1
kill k

However I think this will give a bit of a click, so you could try:

k=play :c4,sustain: 50,release: 1
sleep 1
control k,amp: 0,amp_slide: 0.1
sleep 0.1
kill k

Choke groups are groups of samples that cut each other off if one is played while another is already playing. I would like to write code that allows the sample slices in my program to cut each other off in this way, so that I don’t get multiple slices playing on top of each other if I want to switch to another slice before the one I’m currently playing finishes.

Thank you! This is exactly what I was looking for.