Skip to content

Instantly share code, notes, and snippets.

View victormurcia's full-sized avatar
😀
Playing with data :]

Victor Murcia victormurcia

😀
Playing with data :]
View GitHub Profile
@victormurcia
victormurcia / tones.py
Created September 3, 2022 03:11
keys in piano
#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']
@victormurcia
victormurcia / note_index.py
Last active September 3, 2022 03:14
get note index in piano keys
#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]
@victormurcia
victormurcia / scale_list.py
Last active October 1, 2022 15:29
Interval definitions for various musical scales
#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':
@victormurcia
victormurcia / harmony_def.py
Created September 3, 2022 03:31
Define intervals for various harmonies
#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,
@victormurcia
victormurcia / make_song.py
Created September 3, 2022 04:18
make song using desired scale
#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]
@victormurcia
victormurcia / pixel_song.py
Created September 3, 2022 04:29
pixel art song
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)
@victormurcia
victormurcia / water_song_pedalboard.py
Created September 3, 2022 05:24
water_song_pedalboard
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([
@victormurcia
victormurcia / catterina_song_pedalboard.py
Created September 3, 2022 05:28
catterina_song_pedalboard
# 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),
@victormurcia
victormurcia / nature_song_pedalboard.py
Created September 3, 2022 05:30
nature_song_pedalboard.
# 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),
@victormurcia
victormurcia / librosa_conversions.py
Created September 3, 2022 05:36
librosa_conversions
#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)