-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModularReverb.java
More file actions
77 lines (64 loc) · 2.01 KB
/
ModularReverb.java
File metadata and controls
77 lines (64 loc) · 2.01 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
import beads.*;
import java.lang.Math.*;
import java.util.ArrayList;
class ModularReverb extends Function {
VelvetDelay delay;
BiquadComponent materialAttenuation;
BiquadComponent airAttenuation;
float prevOut;
float reverberance;
float goalReverberance;
float velocity;
public ModularReverb(UGen input, float[] window, int density, float reverberance, BiquadComponent materialAttenuation) {
super(input);
float sampleRate = context.getSampleRate();
delay = new VelvetDelay((int)context.getSampleRate(), 23, window, Math.round(sampleRate / density), context.getSampleRate());
this.reverberance = reverberance;
this.goalReverberance = reverberance;
this.velocity = 1.0f;
this.materialAttenuation = materialAttenuation.register(this);
}
public ModularReverb(UGen input, VelvetDelay delay, BiquadComponent attenuation) {
super(input);
this.delay = delay;
this.materialAttenuation = attenuation;
this.prevOut = 0;
}
public float calculate() {
// Register input
float in = processInput();
float sample = in + prevOut;
// Delay
sample = delay.calculate(sample);
// Spectral decay
sample = materialAttenuation.calculate(sample, this);
// Artificial decay
sample *= reverberance;
if(goalReverberance != reverberance){
reverberance += MathUtils.constrain(goalReverberance - reverberance, -velocity, velocity);
}
// Output
prevOut = sample;
return sample;
}
// Artificially change the reverberance of the room
public void setOpenness(float openness){
goalReverberance = 1 - openness;
}
// Compile all inputs into a single channel
private float processInput() {
if (x.length == 1) {
return x[0];
} else {
float sum = 0;
for (float f : x) {
sum += f;
}
return sum;
}
}
// Set the guranteed delays, which manifest as resonances
public void setResonance(ArrayList<Integer> resonances){
delay.setResonances(resonances);
}
}