-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathAmplitude.java
More file actions
81 lines (68 loc) · 2.11 KB
/
Copy pathAmplitude.java
File metadata and controls
81 lines (68 loc) · 2.11 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
package processing.sound;
import com.jsyn.ports.UnitOutputPort;
import com.jsyn.unitgen.PeakFollower;
import processing.core.PApplet;
/**
* 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 implements Modulator {
private PeakFollower follower;
/**
* @param parent typically use "this"
* @webref Analysis:Amplitude
*/
public Amplitude(PApplet parent) {
super(parent);
this.follower = new PeakFollower();
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() {
this.follower.input.disconnectAll();
this.input = null;
}
protected void setInput(UnitOutputPort input) {
Engine.getEngine().add(this.follower);
this.follower.start();
this.follower.input.connect(input);
}
/**
* Queries a value from the analyzer and returns a float between 0. and 1.
*
* @webref Analysis:Amplitude
* @webBrief Queries a value from the analyzer and returns a float between 0. and 1.
* @return amp An amplitude value between 0-1.
**/
public float analyze() {
// TODO check if input exists, print warning if not
return (float) this.follower.current.getValue();
}
// Below are just duplicated methods from superclasses which are required
// for the online reference to build the corresponding pages.
/**
* Define the audio input for the analyzer.
*
* @param input
* the input sound source. Can be an oscillator, noise generator,
* SoundFile or AudioIn.
* @webref Analysis:Amplitude
* @webBrief Define the audio input for the analyzer.
**/
public void input(SoundObject input) {
super.input(input);
}
public UnitOutputPort getModulator() {
return this.follower.output;
}
}