Skip to content

Commit

Permalink
Allow to use Amplitude analyzer as a modulator
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Oct 12, 2023
1 parent aec473d commit 27ecb91
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/processing/sound/Amplitude.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import processing.core.PApplet;

/**
* This is a volume analyzer. It calculates the root mean square of the
* amplitude of each audio block and returns that value.
* This is a volume analyzer. It tracks the peaks of an input signal, which is a
* simple measure of the overall amplitude of that signal.
*
* @webref Analysis:Amplitude
* @webBrief This is a volume analyzer.
*/
public class Amplitude extends Analyzer {
public class Amplitude extends Analyzer implements Modulator {

private PeakFollower follower;

Expand All @@ -23,7 +23,16 @@ public class Amplitude extends Analyzer {
public Amplitude(PApplet parent) {
super(parent);
this.follower = new PeakFollower();
this.follower.halfLife.set(0.1);
this.halfLife(0.1f);
}

/**
* Sets the half-life of this amplitude analyzer. The output approaches zero
* based on the value on halfLife. The default value is <code>0.1</code>.
* @webBrief Sets the half-life of this amplitude analyzer.
*/
public void halfLife(float value) {
this.follower.halfLife.set(value);
}

protected void removeInput() {
Expand Down Expand Up @@ -65,4 +74,8 @@ public float analyze() {
public void input(SoundObject input) {
super.input(input);
}

public UnitOutputPort getModulator() {
return this.follower.output;
}
}

0 comments on commit 27ecb91

Please sign in to comment.