Playing with live_coding and samples

As described in the associated post here, these two programs create some samples using linked live_coding loops, which are then saved to wav files. The samples are then trimmed accurately to length and used as the source material in the second program which overlays them at a set interval, first played forwards and then in reverse. The sequence is repeated seven times in a thread, and at the same time the system volume is first faded up over 12 seconds, and at the end is faded out again over a further 12 seconds. The entire piece lasts just under a minute.

A zip file containing the programs, the saved and trimmed samples can be downloaded here.

The final piece can be listened to here.

NB This will not currently work on a Raspberry Pi as the resources required are too taxing.

The two programs are listed below: first the sample create program

#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 set 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

Then the sample play program:

#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 incrase 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!
Advertisements

2 thoughts on “Playing with live_coding and samples

  1. Pingback: Nice to be back…and writing for Sonic Pi again | rbnrpi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s