This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Define tones. Upper case are white keys in piano. Lower case are black keys | |
| scale_intervals = ['A','a','B','C','c','D','d','E','F','f','G','g'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Find index of desired key | |
| index = scale_intervals.index(whichKey) | |
| #Redefine scale interval so that scale intervals begins with whichKey | |
| new_scale = scale_intervals[index:12] + scale_intervals[:index] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Choose scale | |
| if whichScale == 'AEOLIAN': | |
| scale = [0, 2, 3, 5, 7, 8, 10] | |
| elif whichScale == 'BLUES': | |
| scale = [0, 2, 3, 4, 5, 7, 9, 10, 11] | |
| elif whichScale == 'PHYRIGIAN': | |
| scale = [0, 1, 3, 5, 7, 8, 10] | |
| elif whichScale == 'CHROMATIC': | |
| scale = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] | |
| elif whichScale == 'DORIAN': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Make harmony dictionary (i.e. fundamental, perfect fifth, major third, octave) | |
| #unison = U0 #semitone = ST | |
| #major second = M2 #minor third = m3 | |
| #major third = M3 #perfect fourth = P4 | |
| #diatonic tritone = DT #perfect fifth = P5 | |
| #minor sixth = m6 #major sixth = M6 | |
| #minor seventh = m7 #major seventh = M7 | |
| #octave = O8 | |
| harmony_select = {'U0' : 1, | |
| 'ST' : 16/15, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Get length of scale (i.e., how many notes in scale) | |
| nNotes = len(scale) | |
| #Initialize arrays | |
| freqs = [] | |
| #harmony = [] | |
| #harmony_val = harmony_select[makeHarmony] | |
| for i in range(nNotes): | |
| note = new_scale[scale[i]] + str(whichOctave) | |
| freqToAdd = note_freqs[note] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pixel_scale = makeScale(3, 'a', 'HARMONIC_MINOR') | |
| pixel_song, pixel_df,pixel_df_harmony = img2music(pixel_art, | |
| pixel_scale, | |
| T = 0.2, | |
| randomPixels = True) | |
| wavfile.write('pixel_song2.wav' , rate = 22050, data = pixel_song.astype(np.float32)) | |
| ipd.Audio(pixel_song, rate = sr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pedalboard import Pedalboard, Chorus, Reverb, Compressor, Gain, LadderFilter | |
| from pedalboard import Phaser, Delay, PitchShift, Distortion | |
| from pedalboard.io import AudioFile | |
| # Read in a whole audio file: | |
| with AudioFile('water_song.wav', 'r') as f: | |
| audio = f.read(f.frames) | |
| samplerate = f.samplerate | |
| # Make a Pedalboard object, containing multiple plugins: | |
| board = Pedalboard([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Read in a whole audio file: | |
| with AudioFile('catterina_song.wav', 'r') as f: | |
| audio = f.read(f.frames) | |
| samplerate = f.samplerate | |
| print(samplerate) | |
| # Make a Pedalboard object, containing multiple plugins: | |
| board = Pedalboard([ | |
| LadderFilter(mode=LadderFilter.Mode.HPF12, cutoff_hz=100), | |
| Delay(delay_seconds = 0.3), | |
| Reverb(room_size = 0.6, wet_level=0.2, width = 1.0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Read in a whole audio file: | |
| with AudioFile('nature_harmony_combined.wav', 'r') as f: | |
| audio = f.read(f.frames) | |
| samplerate = f.samplerate | |
| # Make a Pedalboard object, containing multiple plugins: | |
| board = Pedalboard([ | |
| LadderFilter(mode=LadderFilter.Mode.HPF12, cutoff_hz=100), | |
| Delay(delay_seconds = 0.1), | |
| Reverb(room_size = 1, wet_level=0.1, width = 0.5), | |
| PitchShift(semitones = 6), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Convert frequency to a note | |
| catterina_df['notes'] = catterina_df.apply(lambda row : librosa.hz_to_note(row['frequencies']), | |
| axis = 1) | |
| #Convert note to a midi number | |
| catterina_df['midi_number'] = catterina_df.apply(lambda row : librosa.note_to_midi(row['notes']), | |
| axis = 1) |