Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
Algorithmic Music Composition Project Toolbox starter code

Full instructions at https://sites.google.com/site/sd16spring/home/project-toolbox/algorithmic-music-composition

This program creates a 16 bar blues solo that is played to a longer backing track. Each time the code is ran, a new solo is created and saved over the old .wav file.

To make the solo a different length, change the range in line 58. Since each lick is only half a bar, the solo will be range/2 bars long.

Before running the code, be sure that you have Nsound and matplotlib.pylab installed.

To run the code and create a solo, type
$ python blues_solo.py
in the terminal. To listen to the solo, type
$ cvlc slow_blues.wav
To quit cvlc, type
$ ctrl c
54 changes: 48 additions & 6 deletions blues_solo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def add_note(out, instr, key_num, duration, bpm, volume):
duration: the duration of the note in beats
bpm: the tempo of the music
volume: the volume of the note
"""
"""
freq = (2.0**(1/12.0))**(key_num-49)*440.0
stream = instr.play(duration*(60.0/bpm),freq)
stream *= volume
Expand All @@ -23,14 +23,56 @@ def add_note(out, instr, key_num, duration, bpm, volume):
sampling_rate = 44100.0
Wavefile.setDefaults(sampling_rate, 16)

bass = GuitarBass(sampling_rate) # use a guitar bass as the instrument
bass = GuitarBass(sampling_rate) # use a guitar bass as the instrument
solo = AudioStream(sampling_rate, 1)

""" these are the piano key numbers for a 3 octave blues scale in A
See: http://en.wikipedia.org/wiki/Blues_scale """
See: http://en.wikipedia.org/wiki/Blues_scale """
blues_scale = [25, 28, 30, 31, 32, 35, 37, 40, 42, 43, 44, 47, 49, 52, 54, 55, 56, 59, 61]
beats_per_minute = 45 # Let's make a slow blues solo
beats_per_minute = 45 # Let's make a slow blues solo

add_note(solo, bass, blues_scale[0], 1.0, beats_per_minute, 1.0)
# add_note(solo, bass, blues_scale[0], 1.0, beats_per_minute, 1.0)
curr_note = 0
add_note(solo, bass, blues_scale[curr_note], 1.0, beats_per_minute, 1.0)

solo >> "blues_solo.wav"
licks= [[[1, 0.5*1.1],[1, 0.5*0.9],[1, 0.5*1.1],[1, 0.5*0.9]],
[[2, 0.5*1.1], [2, 0.5*0.9], [-4, 0.5*1.1], [3, 0.5*0.9]],
[[6, 0.5*1.1], [-1, 0.5*0.9], [-1, 0.5*1.1], [-1, 0.5*0.9]],
[[4, 0.5*1.1], [-2, 0.5*0.9], [-1, 0.5*1.1], [1, 0.5*0.9]],
[[3, 0.5*1.1], [-1, 0.5*0.9], [-1, 0.5*1.1], [2, 0.5*0.9]],
[[2, 0.5*1.1], [1, 0.5*0.9], [1, 1.0]],
[[2, 0.5*1.1], [3, 0.5*0.9], [-1, 1.0]],
[[4, 0.5*1.1], [1, 0.5*0.9], [-3, 1]],
[[5, 1.0], [0, 0.5*1.1], [-1, 0.5*0.9]],
[[2, 1.0], [2, 0.5*1.1], [-2, 0.5*0.9]],
[[4, 1.0], [-3, 0.5*1.1], [1, 0.5*0.9]],
[[2, 1.0*1.1], [3, 1.0*0.9]],
[[-3, 1.0*1.1], [1, 1.0*0.9]],
[[-1, 1.0*1.1], [2, 1.0*0.9]],
[[3, 2.0]],
[[-1, 2.0]],
[[1, 2.0]] ]

for i in range(32):
lick = choice(licks)
for note in lick:
curr_note += note[0]
if curr_note<= 0:
curr_note=2
elif curr_note>= len(blues_scale)-1:
curr_note= len(blues_scale)-2
add_note(solo, bass, blues_scale[curr_note], note[1], beats_per_minute, 1.0)

# solo >> "blues_solo.wav"
backing_track = AudioStream(sampling_rate, 1)
Wavefile.read('backing.wav', backing_track)

m = Mixer()

solo *= 0.6 # adjust relative volumes to taste
backing_track *= 2.0

m.add(2.25, 0, solo) # delay the solo to match up with backing track
m.add(0, 0, backing_track)

m.getStream(500.0) >> "slow_blues.wav"