be.hogent.tarsos.dsp
Class EnvelopeFollower

java.lang.Object
  extended by be.hogent.tarsos.dsp.EnvelopeFollower
All Implemented Interfaces:
AudioProcessor

public class EnvelopeFollower
extends java.lang.Object
implements AudioProcessor

An envelope follower follows the envelope of a signal. Sometimes the name envelope detector is used. From wikipedia:

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();
  

Author:
Joren Six

Constructor Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvelopeFollower

public EnvelopeFollower(double sampleRate)
Create a new envelope follower, with a certain sample rate.

Parameters:
sampleRate - The sample rate of the audio signal.

EnvelopeFollower

public EnvelopeFollower(double sampleRate,
                        double attackTime,
                        double releaseTime)
Create a new envelope follower, with a certain sample rate.

Parameters:
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.
Method Detail

process

public boolean process(AudioEvent audioEvent)
Description copied from interface: AudioProcessor
Process the audio event. Do the actual signal processing on an (optionally) overlapping buffer.

Specified by:
process in interface AudioProcessor
Parameters:
audioEvent - The audio event that contains audio data.
Returns:
False if the chain needs to stop here, true otherwise. This can be used to implement e.g. a silence detector.

calculateEnvelope

public void calculateEnvelope(float[] buffer)

processingFinished

public void processingFinished()
Description copied from interface: AudioProcessor
Notify the AudioProcessor that no more data is available and processing has finished. Can be used to deallocate resources or cleanup.

Specified by:
processingFinished in interface AudioProcessor