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
52 changes: 49 additions & 3 deletions blues_solo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,64 @@ def add_note(out, instr, key_num, duration, bpm, volume):
stream *= volume
out << stream

def note_adjust(note, scale):
"""shifts a note till it is within an ordered scale of notes"""
if 0 <= note <= len(scale)-1:
return note
elif note < 0:
return note_adjust(note + 1, scale)
else: # note > len(scale) - 1
return note_adjust(note - 1, scale)

# this controls the sample rate for the sound file you will generate
sampling_rate = 44100.0
Wavefile.setDefaults(sampling_rate, 16)

bass = GuitarBass(sampling_rate) # use a guitar bass as the instrument
#bass = GuitarBass(sampling_rate)
flute = FluteSlide(sampling_rate)
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 """
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

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

licks = [
[ [-1,0.5*1.1], [-1,0.5*0.9], [-1, 0.5*1.1], [-1, 0.5*0.9] ],

[ [1,0.25*1.1],[1,0.25*0.9],[1, 0.25*1.1],[1, 0.25*0.9],
[-1,0.25*1.1],[-1,0.25*0.9],[-1, 0.25*1.1], [-1, 0.25*0.9],
[1,0.25*1.1],[1,0.25*0.9], [1, 0.25*1.1], [1, 0.25*0.9],
[1,0.25*1.1], [1,0.25*0.9], [1, 0.25*1.1], [1, 0.25*0.9] ],

[ [1,0.5*1], [1,0.5*0.9], [1, 0.5*1], [1, 0.5*0.9] ],

[ [2,1], [-1, 0.5*1], [-1, 0.5*0.9] ],

[ [1,0.25*1.1],[1,0.25*0.9],[-1, 0.25*1.1],[-1, 0.25*0.9],
[1,0.333],[1,0.333],[1, 0.333],
[1,0.25*1.1],[1,0.25*0.9], [1, 0.25*1.1], [1, 0.25*0.9],
[-1,0.333],[-1,0.333],[-1, 0.333] ]

]
for i in range(8):
lick = choice(licks)
for note in lick:
curr_note += note[0]
curr_note = note_adjust(curr_note, blues_scale)
add_note(solo, flute, blues_scale[curr_note], note[1], beats_per_minute, 1.0)

backing_track = AudioStream(sampling_rate, 1)
Wavefile.read('backing.wav', backing_track)

m = Mixer()

solo *= 0.8 # adjust relative volumes to taste
backing_track *= 1.6

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

solo >> "blues_solo.wav"
m.getStream(500.0) >> "slow_blues.wav"
Binary file added blues_solo.wav
Binary file not shown.
Binary file added slow_blues.wav
Binary file not shown.