Skip to content

Instantly share code, notes, and snippets.

@rbnpi
Created November 19, 2014 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbnpi/2d3e83722201850f0fd8 to your computer and use it in GitHub Desktop.
Save rbnpi/2d3e83722201850f0fd8 to your computer and use it in GitHub Desktop.
Creating 3 samples with Sonic-Pi and then reusing them in second program: Prophwazsaw
#Sample generation program. used with Sample play. Written by Robin Newman Nov 2015
#the progarm is run three times with Synths saw, prophet and zawa
#the individula outputs are recored as wave files for about three cycloes of the sound cycle
#Each cycle lasts exactly 4 seconds 9set by metro
#the recorded wav files are then trimmed exacty to 4 seconds length starting from the first sound,
#and resaved as wave files called rbnzawa1, rbnsaw1 and rbnprophet1.
#I used the open source Audacity program on a Mac to do this
#the samples are then used in the sample play program
use_debug false
with_fx :reverb,room: 0.8 do
use_synth :prophet
live_loop :metro do
cue :tick
wait 2
cue :tick2
wait 2
end
live_loop :go1 do
sync :tick
play :c3
sleep 0.1
play :g3
cue :tick2
play :c3
sleep 0.1
play :g3
end
live_loop :go2 do
sync :tick
sleep 0.5
play_pattern_timed scale(:c4,:minor),[0.1],release: 0.1
sync :tick2
sleep 0.5
play_pattern_timed scale(:c4,:minor),[0.1],release: 0.1
end
live_loop :go3 do
sync :tick
sleep 0.7
play_pattern_timed scale(:c4,:minor).reverse,[0.1],release: 0.1
sync :tick2
sleep 0.7
play_pattern_timed scale(:c4,:minor).reverse,[0.1],release: 0.1
end
live_loop :go4 do
sync :tick
sleep 1
play_pattern_timed scale(:c5,:minor).reverse,[0.1],release: 0.1
sync :tick2
sleep 1
play_pattern_timed scale(:c5,:minor).reverse,[0.1],release: 0.1
end
live_loop :go5 do
sync :tick
sleep 0.3
play_pattern_timed scale(:c4,:minor,num_octaves: 2),[0.2],release: 0.2
end
live_loop :go6 do
sync :tick
sample :ambi_lunar_land,finish: 0.5,release: 0.1,amp: 2
sleep 3.9
end
end
The programs were created using a near release beta of Sonic-Pi 2.1
Because of the processing required these programs will not work effectively on a
Raspberry Pi, but require the more powerful resources available on the Mac version of
Sonic Pi, although they should also work on a more powerful Linux box under say Ubuntu.
and probably on the Windows version of Sonic Pi too, although I haven't tested this.
The first program createsamples uses 6 live_coding loops to generate a pattern of notes
related to a c minor scale, together with a background ambi_lunar_land sound. The timing
is controlled by cue and sync commands using the metronome thread metro.
The program was run three times, changing the synth between :prophet, :saw and :zawa
In each case a sample wav file was recorded using Sonic Pi's inbuilt facility.
The three samples were then edited using the program Audacity (open source available for
Mac, Pi, Linux etc) and once cycle of the sounds (which lasts exactly 4 seconds) was
extracted in each case, and saved to give the samples in the supplied folder rbn.
The second program playsamples is used to play these recorded samples. They are overlapped
each one starting 4.0/3 seconds after the previous one, and then the three saamples are
played backwwards again at 4.0/3 second intervals. This cycle is repeated seven times, in
a thread
At the same time the overall volume is controlled using the set_system_volume! command.
The volume is started at 0 and a loop is used to increase it linearly to 2 over a period
of 12 seconds. It then remains fixed for 32 seconds plus 2/3 4 seconds, and then the
volume decreases again to 0 over 12 seconds when the piece stops.
Timings. Overall loop 7 times 8 plus 2/3 4 seconds = 58.67 seconds.
Volume: 12 seconds vol up, 32 + 2.67 seconds constant, 12 seconds fade = 58.67 seconds
To use the programs on a Mac, open then in a text editor and copy and paste into an empty
workspace in Sonic-Pi. The samples should be placed in a convenient folder on the Mac
and the line use_sample_pack 'Users/rbn/Desktop/samples/rbn' adjusted to suit.
#Play samples. This program uses three samples recorded from the associated sample generation program
#written by Robin Newman Nov 2014
#The three samples called rbnsaw1, rbnprophet1 and rbnzawa1 are each exactly 4 seconds long and play the same
#piece but using different synths
#The samples are played 4.0/3 seconds apart, first forwards and then in reverse.
#The process is repeated 7 times in a thread
#at the same time the overall volume level is increased over 12 seconds from 0 to 1
#it then remains at this level for 32 seconds before fading out again over a further 12 seconds
use_sample_pack '/Users/rbn/Desktop/samples/rbn' #samples stored here on my mac adjust to suit your system
load_samples [:rbnsaw1,:rbnprophet1,:rbnzawa1] #preload the samples
use_debug false
in_thread do
sleep 0.1 #make sure volume 0 before starting
7.times do
sample :rbnprophet1
sleep 4.0/3
sample :rbnzawa1
sleep 4.0/3
sample :rbnsaw1
sleep 4.0/3
sample :rbnprophet1,rate: -1
sleep 4.0/3
sample :rbnzawa1,rate: -1
sleep 4.0/3
sample :rbnsaw1,rate: -1
sleep 4.0/3
end
end
set_volume! 0
v = 0
1200.times do #loop to increase volume! to 2 over 12 seconds
v=v+2.0/1200
set_volume! v
sleep 0.01
end
sleep 32+(4.0*2/3)
1200.times do #loop to decrease the volume to 0 over 12 seconds
v=v-2.0/1200
set_volume! v
sleep 0.01
end
sleep 1 #ensure is finished before volume reset
set_volume! 1 #so that other programs still work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment