1 # This file is part of jack_mixer
3 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 '''Encapsulates scale linear function edge and coefficients for scale = a * dB + b formula'''
23 def __init__(self
, db
, scale
):
26 self
.text
= "%.0f" % math
.fabs(db
)
29 '''Scale abstraction, various scale implementation derive from this class'''
30 def __init__(self
, scale_id
, description
):
32 self
.scale_id
= scale_id
33 self
.description
= description
34 self
.scale
= jack_mixer_c
.Scale()
36 def add_threshold(self
, db
, scale
, is_mark
):
37 self
.scale
.add_threshold(db
, scale
)
39 self
.marks
.append(Mark(db
, scale
))
41 def calculate_coefficients(self
):
42 self
.scale
.calculate_coefficients()
44 def db_to_scale(self
, db
):
45 '''Convert dBFS value to number in range 0.0-1.0 used in GUI'''
46 #print "db_to_scale(%f)" % db
47 return self
.scale
.db_to_scale(db
)
49 def scale_to_db(self
, scale
):
50 '''Convert number in range 0.0-1.0 used in GUI to dBFS value'''
51 return self
.scale
.scale_to_db(scale
)
53 def add_mark(self
, db
):
54 self
.marks
.append(Mark(db
, -1.0))
59 def scale_marks(self
):
62 i
.scale
= self
.db_to_scale(i
.db
)
64 # IEC 60268-18 Peak programme level meters - Digital audio peak level meter
65 # Adapted from meterpridge, may be wrong, I'm not buying standards, event if they cost $45
66 # If someone has the standart, please eighter share it with me or fix the code.
68 '''IEC 60268-18 Peak programme level meters - Digital audio peak level meter'''
70 Base
.__init
__(self
, "iec_268",
71 "IEC 60268-18 Peak programme level meters - Digital audio peak level meter")
72 self
.add_threshold(-70.0, 0.0, False)
73 self
.add_threshold(-60.0, 0.05, True)
74 self
.add_threshold(-50.0, 0.075, True)
75 self
.add_threshold(-40.0, 0.15, True)
77 self
.add_threshold(-30.0, 0.3, True)
79 self
.add_threshold(-20.0, 0.5, True)
83 self
.add_threshold(0.0, 1.0, True)
84 self
.calculate_coefficients()
87 class IEC268Minimalistic(Base
):
88 '''IEC 60268-18 Peak programme level meters - Digital audio peak level meter,
91 Base
.__init
__(self
, 'iec_268_minimalistic',
92 'IEC 60268-18 Peak programme level meters - Digital audio peak level meter, fewer marks')
93 self
.add_threshold(-70.0, 0.0, False)
94 self
.add_threshold(-60.0, 0.05, True)
95 self
.add_threshold(-50.0, 0.075, False)
96 self
.add_threshold(-40.0, 0.15, True)
97 self
.add_threshold(-30.0, 0.3, True)
98 self
.add_threshold(-20.0, 0.5, True)
100 self
.add_threshold(0.0, 1.0, True)
101 self
.calculate_coefficients()
104 class Linear70dB(Base
):
105 '''Linear scale with range from -70 to 0 dBFS'''
107 Base
.__init
__(self
, "linear_70dB", "Linear scale with range from -70 to 0 dBFS")
108 self
.add_threshold(-70.0, 0.0, False)
119 self
.add_threshold(0.0, 1.0, True)
120 self
.calculate_coefficients()
123 class Linear30dB(Base
):
124 '''Linear scale with range from -30 to +30 dBFS'''
126 Base
.__init
__(self
, "linear_30dB", "Linear scale with range from -30 to +30 dBFS")
127 self
.add_threshold(-30.0, 0.0, False)
128 self
.add_threshold(+30.0, 1.0, True)
129 self
.calculate_coefficients()
132 def scale_test1(scale
):
133 for i
in range(-97 * 2, 1, 1):
135 print("%5.1f dB maps to %f" % (db
, scale
.db_to_scale(db
)))
137 def scale_test2(scale
):
140 print("%.2f maps to %.1f dB" % (s
, scale
.scale_to_db(s
)))
142 def print_db_to_scale(db
):
143 print("%-.1f dB maps to %f" % (db
, scale
.db_to_scale(db
)))
145 def scale_test3(scale
):
146 print_db_to_scale(+77.0)
147 print_db_to_scale(+7.0)
148 print_db_to_scale(0.0)
149 print_db_to_scale(-107.0)
151 #scale = linear_30dB()