Adding an Orchestra to Sonic Pi Using Samples
Where to get some orchestra samples
Download, unzip and move selected samples to a sample directory.
I used sampath = “c:/home/pi/samples/”
Here is the code that makes it work:
#Example1.rb
# Sonic Pi Wav Orchestra
# you will need to download the wav files from
# http://virtualplaying.com
# unzip and copy selected files to a folder defined by
# the samps variable below
# use sampath to point ot the folder where the wav files
# are located
sampath = "c:/home/pi/samples/"
# setup several wav files using the path
samps=[]
samps.push(sampath+"trumpets-sus-e4.wav")
samps.push(sampath+"tuba-sus-e2.wav")
#samps.push(sampath+"tuba-sus-e2-PB-loop.wav")
samps.push(sampath+"cello-c4.wav")
samps.push(sampath+"violin-e4.wav")
samps.push(sampath+"oboe-e4-pb-loop.wav")
#samps.push(sampath+"flute4_b.wav")
#samps.push(sampath+"piccolo-c4-pb-loop.wav")
# define the sample pitch of each instrument
sp=[]
sp.push(:E4) # the sample pitch trumpet
sp.push(:E4) # the sample pitch tuba
sp.push(:C4) # the sample pitch cello
sp.push(:E4) # the sample pitch violin
sp.push(:E4) # the sample pitch oboe
#sp.push(:C4) # the sample pitch flute
#sp.push(:C4) # the sample pitch piccolo
# one way to play wave files
halftone=Math.log(2.0)/12.0
octtone=Math.log(2.0)
centtone=halftone/100.0
tempo=1.0
define :playwavnote do |sampsn,spitch,pitch,time,cents=0.0,amp=1.0,pan=0.0|
# Determine the number of half tones to shift the pitch
a=note spitch
if a !=nil
b=note pitch
if b !=nil
puts a,b, b-a
rate1=Math.exp((b-a)*halftone+cents*centtone)
puts "rate1=",rate1
sample sampsn,
rate:rate1,
attack: 0.1,
sustain: tempo*time*0.5,
release: tempo*time*2.0/3.0,amp: amp ,pan: pan
end # if b!=nil
end # if a!- nil
sleep tempo*time
end #define :playwavenote
#test cases
playwavnote samps[0],:r,:C4,0.25
playwavnote samps[0],sp[0],:r,0.25
playwavnote samps[0],sp[0],:C4,0.25
#try a scale with different instuments
keyscale=scale(:c4,:major)
j=0
while j<samps.length
puts samps[j],sp[j]
i=0
#try a scale
while i<keyscale.length
playwavnote samps[j],sp[j],keyscale[i],0.25
i+=1
end #next i
j+=1
end #next j
One sample per live-loop.
If you have two loops with violins playing in unison you will hear only one.
Use the cents to detune one of the violins slightly.