This commit is contained in:
Connor Olding 2014-10-02 01:21:52 -07:00
parent 3aae7d6c1d
commit 83f1fbe6fc
4 changed files with 152 additions and 133 deletions

0
data.py Normal file → Executable file
View file

52
notes.py Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/python
A = 440
notes = {
'C' : 0,
'D' : 2,
'E' : 4,
'F' : 5,
'G' : 7,
'A' : 9,
'B' : 11,
}
rel = (2**(1/12.))
def note2freq(name):
sharp = name[1] == '#'
flat = name[1] == 'b'
if sharp or flat:
note = name[0:1]
octave = int(name[2])
else:
note = name[0]
octave = int(name[1])
num = notes[note]
if sharp:
num += 1
if flat:
num -= 1
fullnum = num + 12*(octave - 5)
return A*rel**(fullnum + 3)
if __name__ == '__main__':
def test(name, expected):
print('{:3} gave {: 9.2f} Hz\nexpected {: 9.2f} Hz'.format(name, note2freq(name), expected))
test('C2' , 65.41)
test('Ab4', 415.30)
test('A4' , 440.00)
test('B4' , 493.88)
test('B#4', 523.25)
test('Cb5', 493.88)
test('C5' , 523.25)
print()
test('E4' , 329.63)
test('B3' , 246.94)
test('G3' , 196.00)
test('D3' , 146.83)
test('A2' , 110.00)
test('E2' , 82.41)
import sys
sys.exit(0)

58
run.py Executable file
View file

@ -0,0 +1,58 @@
#!/usr/bin/python
from strings import print_ideal_stock
in_mm = 25.4
scale_length = 648/in_mm
string_sets = {
'regular light': (
# (desired note, tension, and type)
('E4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('A2' , 16, 'W'),
('E2' , 16, 'W'),
),
'jazz light': (
('E4' , 24, 'P'),
('B3' , 24, 'P'),
('G3' , 24, 'W'),
('D3' , 24, 'W'),
('A2' , 24, 'W'),
('E2' , 24, 'W'),
),
'regular light (DADGAD)': (
('D4' , 16, 'P'),
('A3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('A2' , 16, 'W'),
('D2' , 16, 'W'),
),
'regular light (open G, 6)': (
('D4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('B2' , 16, 'W'),
('D2' , 16, 'W'),
),
'regular light (open G, 7)': (
('D4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('B2' , 16, 'W'),
('G2' , 16, 'W'),
('D2' , 16, 'W'),
),
}
print('for a scale length of {:>5.2f} inches'.format(scale_length))
for name, strings in string_sets.items():
print()
print('"{}"'.format(name))
print_ideal_stock(strings, scale_length)

View file

@ -1,6 +1,7 @@
#!/usr/bin/python
from data import *
from notes import note2freq
stock = []
stock += daddario_plain_steel
@ -8,143 +9,22 @@ stock += daddario_nickle_wound
#stock += circle_k_plain
#stock += circle_k_hybrid_wound
mm_to_in = 0.03937
scale_length = 648*mm_to_in
string_sets = {
'regular light': (
# (desired note, tension, and type)
('E4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('A2' , 16, 'W'),
('E2' , 16, 'W'),
),
'jazz light': (
('E4' , 24, 'P'),
('B3' , 24, 'P'),
('G3' , 24, 'W'),
('D3' , 24, 'W'),
('A2' , 24, 'W'),
('E2' , 24, 'W'),
),
'regular light (DADGAD)': (
('D4' , 16, 'P'),
('A3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('A2' , 16, 'W'),
('D2' , 16, 'W'),
),
'regular light (open G, 6)': (
('D4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('B2' , 16, 'W'),
('D2' , 16, 'W'),
),
'regular light (open G, 7)': (
('D4' , 16, 'P'),
('B3' , 16, 'P'),
('G3' , 16, 'P'),
('D3' , 16, 'W'),
('B2' , 16, 'W'),
('G2' , 16, 'W'),
('D2' , 16, 'W'),
),
}
A = 440
notes = {
'C' : 0,
'D' : 2,
'E' : 4,
'F' : 5,
'G' : 7,
'A' : 9,
'B' : 11,
}
rel = (2**(1/12.))
def note2freq(name):
sharp = name[1] == '#'
flat = name[1] == 'b'
if sharp or flat:
note = name[0:1]
octave = int(name[2])
else:
note = name[0]
octave = int(name[1])
num = notes[note]
if sharp:
num += 1
if flat:
num -= 1
fullnum = num + 12*(octave - 5)
return A*rel**(fullnum + 3)
def test(name, expected):
print('{:3} gave {: 9.2f} Hz\nexpected {: 9.2f} Hz'.format(name, note2freq(name), expected))
if False:
test('C2' , 65.41)
test('Ab4', 415.30)
test('A4' , 440.00)
test('B4' , 493.88)
test('B#4', 523.25)
test('Cb5', 493.88)
test('C5' , 523.25)
print()
test('E4' , 329.63)
test('B3' , 246.94)
test('G3' , 196.00)
test('D3' , 146.83)
test('A2' , 110.00)
test('E2' , 82.41)
import sys
sys.exit(0)
uw_const = 386.4
def uw2tension(uw, freq):
return (uw*(2*scale_length*freq)**2)/uw_const
def uw2tension(uw, freq, SL):
return (uw*(2*SL*freq)**2)/uw_const
def tension2uw(t, freq):
return (t*uw_const)/(2*scale_length*freq)**2
if False:
# DAd's data is all screwy so we use change scale lengths for a best-fit
scale_length = 25.4825
D3 = note2freq('D3')
A2 = note2freq('A2')
E2 = note2freq('E2')
print('NW024 {:10.8f} == 0.00010857'.format(tension2uw(15.73, D3)))
print('NW025* {:10.8f} == ? '.format(tension2uw(17.21, D3)))
print('NW026 {:10.8f} == 0.00012671'.format(tension2uw(18.38, D3)))
print()
print('NW036 {:10.8f} == 0.00023964'.format(tension2uw(19.04, A2)))
print('NW037* {:10.8f} == ? '.format(tension2uw(20.23, A2)))
print('NW038 {:10.8f} == 0.00026471'.format(tension2uw(20.96, A2)))
print()
scale_length = 25.18
print('NW039 {:10.8f} == 0.00027932'.format(tension2uw(12.46, E2)))
print('NW040* {:10.8f} == ? '.format(tension2uw(13.18, E2)))
print('NW042 {:10.8f} == 0.00032279'.format(tension2uw(14.37, E2)))
print()
scale_length = 25.02
print('NW049 {:10.8f} == 0.00043014'.format(tension2uw(18.97, E2)))
print('NW050* {:10.8f} == ? '.format(tension2uw(19.68, E2)))
print('NW052 {:10.8f} == 0.00048109'.format(tension2uw(21.15, E2)))
import sys
sys.exit(0)
def tension2uw(t, freq, SL):
return (t*uw_const)/(2*SL*freq)**2
outfmt = '{:<8} at {:> 5.2f} lbs ({:>+4.2f})'
finalfmt = 'total: {:>7.2f} lbs ({:>+5.2f})'
def print_ideal_stock(strings):
def print_ideal_stock(strings, scale_length=25.512):
SL = scale_length
total_tension = 0
total_desired_tension = 0
for note, tension, kind in strings:
freq = note2freq(note)
uw = tension2uw(tension, freq)
uw = tension2uw(tension, freq, SL)
closest = ('n/a', 0)
for name, stock_uw in stock:
@ -155,7 +35,7 @@ def print_ideal_stock(strings):
if abs(stock_uw - uw) < abs(closest[1] - uw):
closest = (name, stock_uw)
closest_tension = uw2tension(closest[1], freq)
closest_tension = uw2tension(closest[1], freq, SL)
diff = closest_tension - tension
print(outfmt.format(closest[0], closest_tension, diff))
@ -165,8 +45,37 @@ def print_ideal_stock(strings):
error = total_tension - total_desired_tension
print(finalfmt.format(total_tension, error))
print('for a scale length of {:>5.2f} inches'.format(scale_length))
for name, strings in string_sets.items():
if __name__ == '__main__':
# DAd's data is all screwy so we use change scale lengths for a best-fit
SL = 25.4825
D3 = note2freq('D3')
A2 = note2freq('A2')
E2 = note2freq('E2')
test_fmt = '{:8} {:10.8f} == {:10}'
def test(name, unit, tension, note):
print(test_fmt.format(name, tension2uw(tension, note, SL), unit))
test('NW024' , '0.00010857', 15.73, D3)
test('NW025*', '?' , 17.21, D3)
test('NW026' , '0.00012671', 18.38, D3)
print()
print('"{}"'.format(name))
print_ideal_stock(strings)
test('NW036' , '0.00023964', 19.04, A2)
test('NW037*', '? ', 20.23, A2)
test('NW038' , '0.00026471', 20.96, A2)
print()
SL = 25.18
test('NW039' , '0.00027932', 12.46, E2)
test('NW040*', '? ', 13.18, E2)
test('NW042' , '0.00032279', 14.37, E2)
print()
SL = 25.02
test('NW049' , '0.00043014', 18.97, E2)
test('NW050*', '? ', 19.68, E2)
test('NW052' , '0.00048109', 21.15, E2)
import sys
sys.exit(0)