X Tutup
Skip to content

Commit 9565505

Browse files
committed
Add cutoff frequency and resonance modulation to Filter
1 parent c7cff61 commit 9565505

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

src/processing/sound/Engine.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.jsyn.devices.AudioDeviceOutputStream;
2424
import com.jsyn.devices.javasound.JavaSoundAudioDevice;
2525
import com.jsyn.devices.jportaudio.JPortAudioDevice;
26+
import com.jsyn.ports.UnitInputPort;
2627
import com.jsyn.unitgen.ChannelOut;
2728
import com.jsyn.unitgen.Multiply;
2829
import com.jsyn.unitgen.UnitGenerator;
@@ -583,6 +584,15 @@ private void registerWithParent(PApplet theParent) {
583584
theParent.registerMethod("resume", this.registeredCallback);
584585
}
585586

587+
protected static void setModulation(UnitInputPort port, Modulator modulator) {
588+
if (modulator == null) {
589+
port.disconnectAll();
590+
} else {
591+
port.setValueAdded(true);
592+
port.connect(modulator.getModulator());
593+
}
594+
}
595+
586596
// static helper methods that do stuff like checking argument values or
587597
// printing library messages
588598

src/processing/sound/Filter.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
import processing.core.PApplet;
77

88
/**
9-
* Common superclass for JSyn filters that have a 'Q' unitport
9+
* Common superclass for JSyn filters that have a 'frequency' and a 'Q' unitport
1010
* @webref Effects:Filter
1111
*/
1212
public abstract class Filter<E extends FilterBiquadCommon> extends Effect<E> {
1313

1414
public Filter(PApplet parent) {
1515
super(parent);
16+
this.left.frequency.setValueAdded(true);
17+
this.right.frequency.setValueAdded(true);
18+
this.left.Q.setValueAdded(true);
19+
this.right.Q.setValueAdded(true);
1620
}
1721

1822
/**
@@ -28,6 +32,18 @@ public void res(float q) {
2832
this.right.Q.set(q);
2933
}
3034

35+
/**
36+
* Modulates the resonance of this filter using another generator, typically a
37+
* (low frequency) oscillator. The effective resonance of the filter will be
38+
* the sum of the static value passed to <code>.res(float)</code>, and the
39+
* dynamic value produced by the modulator (which fluctuates around 0).
40+
* @param modulator an oscillator or noise object
41+
*/
42+
public void res(Modulator modulator) {
43+
Engine.setModulation(this.left.Q, modulator);
44+
Engine.setModulation(this.right.Q, modulator);
45+
}
46+
3147
/**
3248
* Sets the cutoff frequency for the filter.
3349
* @webref Effects:Filter
@@ -39,6 +55,18 @@ public void freq(float freq) {
3955
this.right.frequency.set(freq);
4056
}
4157

58+
/**
59+
* Modulates the frequency of this filter using another generator, typically a
60+
* (low frequency) oscillator. The effective cutoff frequency of the filter
61+
* will be the sum of the static value passed to <code>.freq(float)</code>, and
62+
* the dynamic value produced by the modulator (which fluctuates around 0).
63+
* @param modulator an oscillator or noise object
64+
*/
65+
public void freq(Modulator modulator) {
66+
Engine.setModulation(this.left.frequency, modulator);
67+
Engine.setModulation(this.right.frequency, modulator);
68+
}
69+
4270
public void process(SoundObject input, float freq) {
4371
this.freq(freq);
4472
this.process(input);

src/processing/sound/Oscillator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ public void freq(float freq) {
3838
this.oscillator.frequency.set(freq);
3939
}
4040

41-
/*
41+
/**
4242
* Modulates the frequency of this oscillator using another generator,
43-
* typically a (low frequency) oscillator.
43+
* typically a (low frequency) oscillator. The effective frequency of the
44+
* oscillator will be the sum of the static <code>float</code> value passed to
45+
* <code>freq()</code>, and the dynamic value produced by the modulator (which
46+
* fluctuates around 0).
4447
* @param modulator an oscillator or noise object
45-
* @webBrief Modulates the frequency of this oscillator.
4648
*/
4749
public void freq(Modulator modulator) {
48-
this.oscillator.frequency.disconnectAll();
49-
this.oscillator.frequency.connect(modulator.getModulator());
50+
Engine.setModulation(this.oscillator.frequency, modulator);
5051
}
5152

5253
public void amp(Modulator modulator) {
53-
this.oscillator.amplitude.disconnectAll();
54-
this.oscillator.amplitude.connect(modulator.getModulator());
54+
Engine.setModulation(this.oscillator.amplitude, modulator);
5555
}
5656

5757
public void play() {

src/processing/sound/SoundObject.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,13 @@ protected void removeEffect(Effect<? extends UnitFilter> effect) {
150150
this.circuit.removeEffect();
151151
}
152152
}
153+
154+
/**
155+
* Gets the <code>JSynCircuit</code> object which encapsulates all the JSyn
156+
* units (basic sound generator, pan and amplitude) which control the sound
157+
* synthesis of this SoundObject.
158+
*/
159+
public JSynCircuit getUnitGenerator() {
160+
return this.circuit;
161+
}
153162
}

0 commit comments

Comments
 (0)
X Tutup