-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonprototype.py
More file actions
104 lines (69 loc) · 1.68 KB
/
Copy pathpythonprototype.py
File metadata and controls
104 lines (69 loc) · 1.68 KB
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
import soundfile as sf
import matplotlib.pyplot as plt
import numpy as np
file = '440.wav'#'0002 7-Audio.aif'
INPUT, fs = sf.read(file)
OUTPUT=[]
WET = []
THRESHOLD = []
Threshold = -12.0
Ratio = 2.0
Attack = 50.0
Release = 200.0
Gain = 0.0
t_att = 0
t_rel = 0
numSamples = 0
attack = False
wet = 0.0
while numSamples < len(INPUT):
x_L = INPUT[numSamples][0]
x_R = INPUT[numSamples][1]
x_LdB = 20.0*np.log10(abs(x_L))
x_RdB = 20.0*np.log10(abs(x_R))
if x_LdB > Threshold or x_RdB > Threshold:
attack = True
if attack == True:
if t_att < (Attack/1000.0)*fs:
t_rel = 0
t_att += 1
wet = float(t_att)/((Attack/1000.0)*fs)
else:
wet = 1.0
attack = False
if attack == False:
if t_rel < (Release/1000.0)*fs:
t_att -= 1
t_rel += 1
wet = 1.0 - float(t_rel)/((Release/1000.0)*fs)
if abs(wet) > 1.0:
wet = 1.0
attack = False
t_att = 0
if abs(wet) < 0.0:
wet = 0.0
t_rel = 0
wet_LdB = Threshold + (x_LdB - Threshold)/Ratio
wet_RdB = Threshold + (x_RdB - Threshold)/Ratio
dry_LdB = x_LdB
dry_RdB = x_RdB
y_L = np.sign(x_L)*10.0**((wet_LdB*wet + dry_LdB*(1.0-wet))/20.0)
y_R = np.sign(x_R)*10.0**((wet_RdB*wet + dry_RdB*(1.0-wet))/20.0)
OUTPUT.append(y_L)
WET.append(wet/2.0)
THRESHOLD.append(10**(Threshold/20.0))
numSamples += 1
INPUT =[]
for i in xrange(len(INPUT)):
INPUT.append(INPUT[i][0])
THRESHOLD = np.asarray(THRESHOLD)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot(INPUT,'0.75', label = "Input")
plt.plot(OUTPUT, 'k', label = "Output")
plt.plot(WET,'c', label = "Amt of Comp/2")
plt.plot(THRESHOLD,'r', label = "Threshold")
plt.plot(-THRESHOLD,'r')
plt.legend()
gplt.show()
sf.write('440_12_2.wav', OUTPUT ,fs)