Sample slices pattern_timed

Hi,
I’ve sliced a sample and am using the same slice at 3 different pitches.
I’d like to be able to store each of those pitched slices eg as a variable and then play them using something like play_pattern_timed.
How can I achieve this?

I’ve had a play with this this afternoon, and have got a solution. I’ve actually taken it quite a long way and had a lot of fun playing various pieces of music using sliced samples to get the note(s). Just needs a little more tidying up. I’ll post something tomorrow!
EDIT Better late than never…still just the next day, and here is the function that I came up with plus some examples below it.

#slicedSampleFunction.rb by Robin Newman, Feb 2023

#This function implements two things.
#first it uses a sample name, followed by parameters for a list of rpitch offsets,
#and a list durations, and thus is akin to the play_patterned-timed function for synths
#These three paramteres are required as listed below
#secondly it allows you to select a sample slice, and/or use start: and finish: paramters
#to adjust the characteristics of the sample source being used. In particular the :release
#parameter is useful if the slicing or start finish values give rise to clicks. YOu can reduce
#the value of release: until they disappear. Similarly atack can be used to reduce initial clicks.

#call splaytimed with args:
#REQUIRED
#sample name
#pitchlist: list of rpitch values
#durlist: list of durations for each sound
#OPTIONAL
#offset: (added to pitchlist values)
#num_slices: (if not using default 16)
#slice: (slice to be played)
#start: and finish: (defaults are 0 and 1)
#sustain: (default is 0)
#release: (default will be current duration for durlist) can be reduced to eliminate clicks
#any other parameters such as pan:, amp:, cutoff: etc
#splaytimed is wrapped in a in_thread do...end which can be removed if you prefer
define :splaytimed do|sn,*args| #this plays patterns of notes with supplied associated durations
  av =args[0] #extract supplied args for pitchlist,durlist and offset
  pl=av[:pitchlist];offset = av[:offset];dur=av[:durlist]
  offset=0 if offset==nil #deal with missing offset
  if pl==nil or dur==nil
    raise "you must supply both pitchlist: and durlist: arguments"
    stop
  end
  #puts "av",av
  #now delete pitchlist and durlist from remaining args
  av.delete(:pitchlist)
  av.delete(:durlist)
  #puts "av stripped",av
  #use a loop to play the sequence of relative pitches and durations
  pl.length.times do
    tick
    #put next rpitch and dur (and offset if there is one)  values into p1,p2
    p1=pl.look+offset;p2=dur.look
    #puts p1,p2
    #now create opts list for calling the sample by merging in rpitch sustain and release values
    opts=( { :rpitch=> p1,:sustain => 0,:release => p2 } ).merge(av)
    #note these values can be overriden in call to splaytimed eg add sustain: 0.1
    #puts opts
    #play thesample
    sample sn,opts if ![:r,:rest,nil].include? pl.look #don't play if a rest
    sleep dur.look #sleep current duration value
  end
end

#example pitch list and duration list
p=[0,2,4,7,-5,-1,0,:r,0,2,4,7,-5,-1,0];d=[0.4,0.2,0.4,0.2,0.4,0.2,0.4,0.4,0.4,0.2,0.4,0.2,0.4,0.2,0.4]
#sample misc_crow starting at 0.2 (no slice)
splaytimed :misc_crow,pitchlist: p,durlist: d,start: 0.2
#sample misc_crow slice 0 of 2 slices  with pitch pffset -12
splaytimed :misc_crow,pitchlist: p,durlist: d ,offset: -12 ,num_slices: 2,slice: 0
#sample ambi-glass_rub slice 0 of 12 offset -24 starting at 0.8 through slice also added attack release and amp
splaytimed :ambi_glass_rub,pitchlist: p,durlist: d ,offset: -24 ,num_slices: 12,slice: 0,
  start: 0.8,attack: 0.01,release: 0.2,amp: 3
#sample ambi_glass_rub offset 12, slice 0 of 2 starting 0.4 through slice with attack and amp setting
splaytimed :ambi_glass_rub,pitchlist: p,durlist: d ,offset: 12 ,num_slices: 2,slice: 0,start: 0.4,attack: 0.01,amp: 2
#same as above but using sample ambi_glass_hum
splaytimed :ambi_glass_hum,pitchlist: p,durlist: d ,offset: 7 ,num_slices: 2,slice: 0,start: 0.4,attack: 0.01,amp: 2

#it works very well with external samples. If using a defined path to a folder and a numeric sample offset use sn = path,3
#and splaytimed sn,pitchlist:...... to enter the sample name

Also in a separate post I will publish some mixed up Bach that I have produced using the function above.
I hope the comments help you to follow what is going on. Please ask for further explanation if you want more.

1 Like

Thank you, this is really very helpful, and I’ve been able to use external samples to gain the effect I was hoping for.

That’s great. I too have found it very versatile with a range of external samples.