-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathFilter.java
More file actions
100 lines (89 loc) · 3.14 KB
/
Filter.java
File metadata and controls
100 lines (89 loc) · 3.14 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
package processing.sound;
import com.jsyn.unitgen.FilterBandPass;
import com.jsyn.unitgen.FilterBiquadCommon;
import processing.core.PApplet;
/**
* Common superclass for JSyn filters that have a 'frequency' and a 'Q' unitport
* @webref Effects:Filter
*/
public abstract class Filter<E extends FilterBiquadCommon> extends Effect<E> {
public Filter(PApplet parent) {
super(parent);
this.left.frequency.setValueAdded(true);
this.right.frequency.setValueAdded(true);
this.left.Q.setValueAdded(true);
this.right.Q.setValueAdded(true);
}
/**
* Sets the resonance (or 'Q factor') of this filter. Increasing Q increases
* the resonance of the filter at its cutoff frequency. Defaults to 1.
* @webref Effects:Filter
* @webBrief Sets the resonance (or 'Q factor') of this filter.
* @param q the desired Q factor, a value between 0.1 and 10
*/
public void res(float q) {
// TODO check for [0.1, 10] range
this.left.Q.set(q);
this.right.Q.set(q);
}
/**
* Modulates the resonance of this filter using another generator, typically a
* (low frequency) oscillator. The effective resonance of the filter will be
* the sum of the static value passed to <code>.res(float)</code>, and the
* dynamic value produced by the modulator (which fluctuates around 0).
* @param modulator an oscillator or noise object
*/
public void res(Modulator modulator) {
Engine.setModulation(this.left.Q, modulator);
Engine.setModulation(this.right.Q, modulator);
}
/**
* Sets the cutoff frequency for the filter.
* @webref Effects:Filter
* @webBrief Sets the cutoff frequency for the filter.
* @param freq the cutoff frequency in Hertz
**/
public void freq(float freq) {
this.left.frequency.set(freq);
this.right.frequency.set(freq);
}
/**
* Modulates the frequency of this filter using another generator, typically a
* (low frequency) oscillator. The effective cutoff frequency of the filter
* will be the sum of the static value passed to <code>.freq(float)</code>, and
* the dynamic value produced by the modulator (which fluctuates around 0).
* @param modulator an oscillator or noise object
*/
public void freq(Modulator modulator) {
Engine.setModulation(this.left.frequency, modulator);
Engine.setModulation(this.right.frequency, modulator);
}
public void process(SoundObject input, float freq) {
this.freq(freq);
this.process(input);
}
/**
* Starts applying this filter to an input signal.
* @webref Effects:Filter
* @webBrief Starts applying this filter to an input signal.
* @param input the sound source to filter
* @param freq the cutoff frequency in Hertz
* @param q the resonance (or 'Q factor'), a value between 0.1 and 10
**/
public void process(SoundObject input, float freq, float q) {
this.freq(freq);
this.res(q);
this.process(input);
}
/**
* Sets frequency and bandwidth of the filter with one method.
* @webref Effects:Filter
* @webBrief Sets frequency and bandwidth of the filter with one method.
* @param freq the cutoff frequency in Hertz
* @param q the resonance (or 'Q factor'), a value between 0.1 and 10
**/
public void set(float freq, float q) {
this.freq(freq);
this.res(q);
}
}