In [1]:
%matplotlib inline
import librosa, librosa.display, numpy, matplotlib.pyplot as plt, IPython.display as ipd
In [2]:
plt.style.use('seaborn-muted')
plt.rcParams['figure.figsize'] = (14, 5)
plt.rcParams['axes.grid'] = True
plt.rcParams['axes.spines.left'] = False
plt.rcParams['axes.spines.right'] = False
plt.rcParams['axes.spines.bottom'] = False
plt.rcParams['axes.spines.top'] = False
plt.rcParams['axes.xmargin'] = 0
plt.rcParams['axes.ymargin'] = 0
plt.rcParams['image.cmap'] = 'gray'
plt.rcParams['image.interpolation'] = None
In [3]:
note_pt = dict()
# Sharps
note_pt['A4'] = 440.0
for octave in range(0, 10):
note_pt['A{}'.format(octave)] = 440.0*2**(octave-4)
note_pt['E1'] = 1.5*note_pt['A0']
for octave in range(0, 10):
note_pt['E{}'.format(octave)] = note_pt['E1']*2**(octave-1)
note_pt['B0'] = 1.5*note_pt['E0']
for octave in range(0, 10):
note_pt['B{}'.format(octave)] = note_pt['B0']*2**(octave-0)
note_pt['F#1'] = 1.5*note_pt['B0']
for octave in range(0, 10):
note_pt['F#{}'.format(octave)] = note_pt['F#1']*2**(octave-1)
note_pt['C#1'] = 1.5*note_pt['F#0']
for octave in range(0, 10):
note_pt['C#{}'.format(octave)] = note_pt['C#1']*2**(octave-1)
note_pt['G#0'] = 1.5*note_pt['C#0']
for octave in range(0, 10):
note_pt['G#{}'.format(octave)] = note_pt['G#0']*2**(octave-0)
note_pt['D#1'] = 1.5*note_pt['G#0']
for octave in range(0, 10):
note_pt['D#{}'.format(octave)] = note_pt['D#1']*2**(octave-1)
note_pt['A#0'] = 1.5*note_pt['D#0']
for octave in range(0, 10):
note_pt['A#{}'.format(octave)] = note_pt['A#0']*2**(octave-0)
note_pt['E#1'] = 1.5*note_pt['A#0']
for octave in range(0, 10):
note_pt['E#{}'.format(octave)] = note_pt['E#1']*2**(octave-1)
note_pt['B#0'] = 1.5*note_pt['E#0']
for octave in range(0, 10):
note_pt['B#{}'.format(octave)] = note_pt['B#0']*2**(octave-0)
# Flats
note_pt['D0'] = 2/3*note_pt['A0']
for octave in range(0, 10):
note_pt['D{}'.format(octave)] = note_pt['D0']*2**octave
note_pt['G0'] = 2/3*note_pt['D1']
for octave in range(0, 10):
note_pt['G{}'.format(octave)] = note_pt['G0']*2**octave
note_pt['C0'] = 2/3*note_pt['G0']
for octave in range(0, 10):
note_pt['C{}'.format(octave)] = note_pt['C0']*2**octave
note_pt['F0'] = 2/3*note_pt['C1']
for octave in range(0, 10):
note_pt['F{}'.format(octave)] = note_pt['F0']*2**octave
note_pt['Bb0'] = 2/3*note_pt['F1']
for octave in range(0, 10):
note_pt['Bb{}'.format(octave)] = note_pt['Bb0']*2**octave
note_pt['Eb0'] = 2/3*note_pt['Bb0']
for octave in range(0, 10):
note_pt['Eb{}'.format(octave)] = note_pt['Eb0']*2**octave
note_pt['Ab0'] = 2/3*note_pt['Eb1']
for octave in range(0, 10):
note_pt['Ab{}'.format(octave)] = note_pt['Ab0']*2**octave
note_pt['Db0'] = 2/3*note_pt['Ab0']
for octave in range(0, 10):
note_pt['Db{}'.format(octave)] = note_pt['Db0']*2**octave
note_pt['Gb0'] = 2/3*note_pt['Db1']
for octave in range(0, 10):
note_pt['Gb{}'.format(octave)] = note_pt['Gb0']*2**octave
note_pt['Cb0'] = 2/3*note_pt['Gb0']
for octave in range(0, 10):
note_pt['Cb{}'.format(octave)] = note_pt['Cb0']*2**octave
note_pt['Fb0'] = 2/3*note_pt['Cb1']
for octave in range(0, 10):
note_pt['Fb{}'.format(octave)] = note_pt['Fb0']*2**octave
In [4]:
sorted_notes = sorted(note_pt.items(), key=lambda x:x[1])
In [5]:
markdown = """|note|midi-ET|Hertz-ET|midi-PT|Hertz-PT|\n"""
markdown += """|----|----|-----|----|----|-----|\n"""
for note, f_pt in sorted_notes:
midi_et = librosa.note_to_midi(note)
f_et = librosa.midi_to_hz(midi_et)
midi_pt = librosa.hz_to_midi(f_pt)
if note.startswith('A') and midi_et % 12 == 9:
ipd.display_markdown(markdown, raw=True)
markdown = """|note|midi-ET|Hertz-ET|midi-PT|Hertz-PT|\n"""
markdown += """|----|----|-----|----|----|-----|\n"""
markdown += """|{}|{}|{:.5g}|{:.3f}|{:.5g}|\n""".format(
note, midi_et, f_et, midi_pt, f_pt
)
ipd.display_markdown(markdown, raw=True)