diff --git a/README.md b/README.md index 823c269..9d5ca3e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/blues_solo.py b/blues_solo.py index 45791ad..3daa76c 100644 --- a/blues_solo.py +++ b/blues_solo.py @@ -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 @@ -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" \ No newline at end of file +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" \ No newline at end of file