-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtilities.py
executable file
·50 lines (37 loc) · 1.24 KB
/
Utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
#
# Utilities.py
#
# Copyright 2022 Harmonicdog. All rights reserved.
#
import math
ZEROdB = float(0x1000) # 12 bit
def LinearInterp(p0, p1, t):
"""Interpolates linearly between p0 and p1. `t` is a scalar [0,1]"""
return (1.0-t)*p0 + t*p1
def QuadraticInterp(p0, p1, p2, t):
"""Interpolates quadratically between p0, p1 and p2. `t` is a scalar [0,1]"""
return (1-t)*(1-t)*p0 + 2*t*(1-t)*p1 + t*t*p2
def ScalarToAmplitude(scalar):
"""Converts a linear scalar in the range [0,1] to decibels [-45,12] and then to an amplitude scalar"""
if scalar == 0.0:
return 0.0
theDB = LinearInterp(-45.0, 12.0, scalar)
theAmp = math.pow(10.0, 0.05 * theDB)
return theAmp
def MMtoDB(mm):
"""Converts millimeters [0,1] to dB value [-45,12]"""
return LinearInterp(-45.0, 12.0, mm)
def DBtoMM(db):
"""Converts a dB value [-45,12] to a scalar in millimeters in [0,1]. These are really tiny sliders :)"""
return (db - -45.0) / (12.0 - -45.0)
def FloatToIntVol(fvol):
return int(fvol * ZEROdB)
def IntVolToFloat(ivol):
return ivol / ZEROdB
def Log20k(x):
return math.log10(x) / 4.301029995663981
def EQIntQtoQ(intq):
return QuadraticInterp(10.0, 2.0, 1.0, IntVolToFloat(intq))
def EQIntDBtoDB(intdb):
return IntVolToFloat(intdb) * 18.0