Debian Codegraph @

gen-freq-table

raw
1 #!/usr/bin/env python3
2 #
3 # gen-freq-table - calculate and print the frequency table for use in beep(1) man page
4 # Copyright (C) 2018-2019 Hans Ulrich Niedermann
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 import math
21
22 n_list = range(-9, 3+1)
23
24 octave_list = range(3, 6+1)
25
26 freqs = [ [ (440*(2**(i-4))*math.exp(math.log(2)*n/12)) for i in octave_list ] for n in n_list ]
27
28 notes = [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C" ]
29
30 print("""\
31 .TS
32 center box;
33 Cb | Cb s s s
34 Cb | Cb Cb Cb Cb
35 - | - - - -
36 C | N N N N.
37 note octave
38 """, end="")
39
40 print("name\t", end="")
41 for octave in octave_list:
42 print("%d\t" % octave, end="")
43 print()
44
45 for (note, freqline) in zip(notes,freqs):
46 print("%s\t" % note, end="")
47 for f in freqline:
48 print("%d\t" % int(round(f)), end="")
49 print()
50
51 print("""\
52 .TE
53 """, end="")