-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common filter superclass with resonance option (implements #46)
- Loading branch information
1 parent
49a5f84
commit 622df3d
Showing
3 changed files
with
71 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 'Q' unitport | ||
abstract class Filter<E extends FilterBiquadCommon> extends Effect<E> { | ||
|
||
public Filter(PApplet parent) { | ||
super(parent); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters