Play_pattern_timed with wav samples

A = “path/to/A4.wav”
B = “path/to/B4.wav”
C = “path/to/B4.wav”

How to play the above samples with play_pattern_timed

A = "path/to/A4.wav"
B = "path/to/B4.wav"
C = "path/to/B4.wav"

n1 = [sample A,sample B,sample C,sample A]
d1 = [0.5,0.5,0.5,0.5]
in_thread do
  play_pattern_timed n1,d1
end

Giving error

Runtime Error: [buffer 6, line 905] - SyntaxError
Thread death!
 workspace_six:7: syntax error, unexpected constant, expecting `do' or '{' or '('
n1 = [sample A,sample B,sample C,sample C...
             ^~

C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:905:in `eval'
C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:905:in `block (2 levels) in __spider_eval'
C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:1169:in `block (2 levels) in __in_thread'
1 Like

Simple answer:

loop do
  tick
  sample n1.look
  sleep d1.look
end

or, to mimic play_pattern_timed:

n1.zip(d1).each do |n,d|
  print n,d
  
  sample n
  sleep d
  
end
1 Like

Yes, we cannot call play (or play_pattern, play_pattern_timed or play_chord) on sample, they are two distinct functions - play targets a synth, sample targets an audio file. It’s like trying to drop an audio file onto a MIDI track. But as David shows, it’s easy to mimic play_pattern_timed.

Love the pattern interleaving, with .zip() :wink:

PD-Pi