Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turning in project toolbox #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
46 changes: 44 additions & 2 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,6 +23,47 @@ 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
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
time = [0.5, 0.8, 0.9, 1.2, 1.5] # add random swing
volume = [0.5, 0.8, 1.0, 2.0, 2.5, 3.0, 5.0] # add random dynamics

""" initial conditions """
curr_note = 12
roots = [0,6,12,18]
add_note(solo, bass, blues_scale[curr_note], 1.0, beats_per_minute, 1.0)

licks = [ [ [3,choice(time)], [-2,choice(time)], [-4,choice(time)], [2,choice(time)], [3,choice(time)] ],
[ [1,choice(time)], [4,choice(time)], [-2,choice(time)], [1,choice(time)], [1,choice(time)] ],
[ [-1,choice(time)], [2,choice(time)], [-1,choice(time)], [2,choice(time)], [-1,choice(time)] ],
[ [2,choice(time)], [-1,choice(time)], [-1,choice(time)],[-1,choice(time)], [2,choice(time)] ] ]

for i in range(20):
lick = choice(licks)
for note in lick:
curr_note += note[0]
if curr_note < 0 or curr_note > len(blues_scale) - 1: # keep in index of blues_scale
curr_note = choice(roots)
add_note(solo, bass, blues_scale[curr_note], note[1], beats_per_minute, choice(volume))

""" Make it cooler-- adding a backing track and mixing various audio streams """
backing_track = AudioStream(sampling_rate, 1)
Wavefile.read('backing.wav', backing_track)

m = Mixer()

solo *= 0.4 # adjust volumes

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

m.getStream(500.0) >> "slow_blues.wav" # change from blues_solo.wav to slow_blues.wav

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

Expand All @@ -33,4 +74,5 @@ def add_note(out, instr, key_num, duration, bpm, volume):

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

solo >> "blues_solo.wav"
solo >> "blues_solo.wav"