-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfilterProQ3_reader.py
159 lines (122 loc) · 4.47 KB
/
fabfilterProQ3_reader.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import struct
from enum import IntEnum
from dataclasses import dataclass
import math
from pathlib import Path
class ProQ3Shape(IntEnum):
Bell = 0
LowShelf = 1
LowCut = 2
HighShelf = 3
HighCut = 4
Notch = 5
BandPass = 6
TiltShelf = 7
FlatTilt = 8
class ProQ3Slope(IntEnum):
Slope6dB_oct = 0
Slope12dB_oct = 1
Slope18dB_oct = 2
Slope24dB_oct = 3
Slope30dB_oct = 4
Slope36dB_oct = 5
Slope48dB_oct = 6
Slope72dB_oct = 7
Slope96dB_oct = 8
SlopeBrickwall = 9
class ProQ3StereoPlacement(IntEnum):
Left = 0
Right = 1
Stereo = 2
Mid = 3
Side = 4
@dataclass
class ProQ3Band:
enabled: bool = False
frequency: float = 1000.0 # 10.0 -> 30000.0 Hz
gain: float = 0.0 # dB
dynamic_range: float = 0.0 # dB
dynamic_threshold: float = 1.0 # 1 = auto, or value in dB
q: float = 1.0 # 0.025 -> 40.00
shape: ProQ3Shape = ProQ3Shape.Bell
slope: ProQ3Slope = ProQ3Slope.Slope24dB_oct
stereo_placement: ProQ3StereoPlacement = ProQ3StereoPlacement.Stereo
def __str__(self):
status = "On" if self.enabled else "Off"
return f"[{status:3}] {self.shape.name}: {self.frequency:.2f} Hz, {self.gain:.2f} dB, Q: {self.q:.2f}, {self.slope.name}, {self.stereo_placement.name}"
class FabfilterProQ3Reader:
def __init__(self):
self.version = 4
self.parameter_count = 334
self.bands = []
self.unknown_parameters = []
@staticmethod
def freq_convert_back(value: float) -> float:
"""Convert frequency value from FabFilter format to Hz"""
return math.pow(2, value)
@staticmethod
def q_convert_back(value: float) -> float:
"""Convert Q value from FabFilter format to actual Q"""
return math.pow(10, (value - 0.5) / 0.312098175)
def read_ffp(self, filepath: str) -> bool:
path = Path(filepath)
if not path.exists():
raise FileNotFoundError(f"File not found: {filepath}")
with open(filepath, 'rb') as f:
header = f.read(4).decode('ascii')
if header != "FQ3p":
return False
self.version = struct.unpack('<I', f.read(4))[0]
self.parameter_count = struct.unpack('<I', f.read(4))[0]
# Read 24 bands
self.bands = []
for _ in range(24):
band = ProQ3Band()
# Read band parameters
enabled = struct.unpack('<f', f.read(4))[0]
band.enabled = enabled == 1
_ = struct.unpack('<f', f.read(4))[0] # unknown1
freq = struct.unpack('<f', f.read(4))[0]
band.frequency = self.freq_convert_back(freq)
band.gain = struct.unpack('<f', f.read(4))[0]
band.dynamic_range = struct.unpack('<f', f.read(4))[0]
_ = struct.unpack('<f', f.read(4))[0] # unknown3
band.dynamic_threshold = struct.unpack('<f', f.read(4))[0]
q = struct.unpack('<f', f.read(4))[0]
band.q = self.q_convert_back(q)
shape = struct.unpack('<f', f.read(4))[0]
band.shape = ProQ3Shape(int(shape))
slope = struct.unpack('<f', f.read(4))[0]
band.slope = ProQ3Slope(int(slope))
placement = struct.unpack('<f', f.read(4))[0]
band.stereo_placement = ProQ3StereoPlacement(int(placement))
# Skip unknown parameters
_ = struct.unpack('<f', f.read(4))[0] # unknown5
_ = struct.unpack('<f', f.read(4))[0] # unknown6
self.bands.append(band)
# Read remaining parameters
remaining_count = self.parameter_count - 13 * len(self.bands)
self.unknown_parameters = []
for _ in range(remaining_count):
value = struct.unpack('<f', f.read(4))[0]
self.unknown_parameters.append(value)
return True
def __str__(self):
output = []
output.append("Bands:")
for band in self.bands:
if band.enabled:
output.append(str(band))
return "\n".join(output)
def main():
import sys
if len(sys.argv) != 2:
print("Usage: python fabfilter_reader.py <preset.ffp>")
return
reader = FabfilterProQ3Reader()
if reader.read_ffp(sys.argv[1]):
print(reader)
else:
print("Failed to read FFP file")
if __name__ == "__main__":
main()