public class EnvelopeFollower extends java.lang.Object implements AudioProcessor
An envelope detector is an electronic circuit that takes a high-frequency signal as input and provides an output which is the envelope of the original signal. The capacitor in the circuit stores up charge on the rising edge, and releases it slowly through the resistor when the signal falls. The diode in series rectifies the incoming signal, allowing current flow only when the positive input terminal is at a higher potential than the negative input terminal.The resulting envelope is stored in the buffer in the processed AudioEvent. The class can be used thusly:
EnvelopeFollower follower = new EnvelopeFollower(44100); AudioDispatcher dispatcher = AudioDispatcher.fromFloatArray(sine, 44100, 1024, 0); dispatcher.addAudioProcessor(follower); dispatcher.addAudioProcessor(new AudioProcessor() { public boolean process(AudioEvent audioEvent) { //envelope float buffer[] = audioEvent.getFloatBuffer(); for(int i = 0 ; i < buffer.length ; i++){ System.out.println(buffer[i]); } return true; } public void processingFinished() { } }); dispatcher.run();
Constructor and Description |
---|
EnvelopeFollower(double sampleRate)
Create a new envelope follower, with a certain sample rate.
|
EnvelopeFollower(double sampleRate,
double attackTime,
double releaseTime)
Create a new envelope follower, with a certain sample rate.
|
Modifier and Type | Method and Description |
---|---|
void |
calculateEnvelope(float[] buffer) |
boolean |
process(AudioEvent audioEvent)
Process the audio event.
|
void |
processingFinished()
Notify the AudioProcessor that no more data is available and processing
has finished.
|
public EnvelopeFollower(double sampleRate)
sampleRate
- The sample rate of the audio signal.public EnvelopeFollower(double sampleRate, double attackTime, double releaseTime)
sampleRate
- The sample rate of the audio signal.attackTime
- Defines how fast the envelope raises, defined in seconds.releaseTime
- Defines how fast the envelope goes down, defined in seconds.public boolean process(AudioEvent audioEvent)
AudioProcessor
process
in interface AudioProcessor
audioEvent
- The audio event that contains audio data.public void calculateEnvelope(float[] buffer)
public void processingFinished()
AudioProcessor
processingFinished
in interface AudioProcessor