-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathJSynDelay.java
More file actions
60 lines (48 loc) · 1.66 KB
/
JSynDelay.java
File metadata and controls
60 lines (48 loc) · 1.66 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
package processing.sound;
import com.jsyn.engine.SynthesisEngine;
import com.jsyn.unitgen.Circuit;
import com.jsyn.unitgen.InterpolatingDelay;
import com.jsyn.unitgen.MultiplyAdd;
import com.jsyn.unitgen.UnitFilter;
/**
* A custom JSyn delay circuit with feedback.
*/
class JSynDelay extends UnitFilter {
private Circuit feedbackCircuit;
private InterpolatingDelay delay = new InterpolatingDelay();
private MultiplyAdd feedback = new MultiplyAdd();
public JSynDelay() {
super();
this.feedbackCircuit = new Circuit();
this.feedbackCircuit.add(this.delay);
this.feedbackCircuit.add(this.feedback);
// put the feedback multiplier unit before the delay -- this way
// the original signal is not played back immediately, but playback
// will be delayed for the length of the delay time
// TODO could add 'mix' parameter which allows direct passthrough of
// the original signal?
this.input = this.feedback.inputC;
this.feedback.inputA.set(0.0);
this.feedback.inputB.connect(this.delay.output);
this.feedback.output.connect(this.delay.input);
this.output = this.delay.output;
}
@Override
public void setSynthesisEngine(SynthesisEngine synthesisEngine) {
this.feedbackCircuit.setSynthesisEngine(synthesisEngine);
}
public void generate(int start, int limit) {
// not called
}
protected void setDelayTime(float delayTime) {
this.delay.delay.set(delayTime);
}
protected void setFeedback(float feedback) {
// TODO check range
this.feedback.inputA.set(feedback);
}
protected void setMaxDelayTime(float maxDelayTime) {
int maxSamples = (int) (Engine.getEngine().getSampleRate() * maxDelayTime);
this.delay.allocate(maxSamples);
}
}