sound.echo
Class EchoFilter

java.lang.Object
  extended by sound.echo.EchoFilter

public class EchoFilter
extends java.lang.Object


Constructor Summary
EchoFilter(int numDelaySamples, float decay)
          Creates an EchoFilter with the specified number of delay samples and the specified decay rate.
 
Method Summary
 void filter(byte[] samples)
          Filters an array of samples.
 void filter(byte[] samples, int offset, int length)
          Filters the sound samples to add an echo.
 int getRemainingSize()
          Gets the remaining size, in bytes, of samples that this filter can echo after the sound is done playing.
static short getSample(byte[] buffer, int position)
          Convenience method for getting a 16-bit sample from a byte array.
 void reset()
          Clears this EchoFilter's internal delay buffer.
static void setSample(byte[] buffer, int position, short sample)
          Convenience method for setting a 16-bit sample in a byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EchoFilter

public EchoFilter(int numDelaySamples,
                  float decay)
Creates an EchoFilter with the specified number of delay samples and the specified decay rate.

The number of delay samples specifies how long before the echo is initially heard. For a 1 second echo with mono, 44100Hz sound, use 44100 delay samples.

The decay value is how much the echo has decayed from the source. A decay value of .5 means the echo heard is half as loud as the source.

Method Detail

getRemainingSize

public int getRemainingSize()
Gets the remaining size, in bytes, of samples that this filter can echo after the sound is done playing. Ensures that the sound will have decayed to below 1% of maximum volume (amplitude).


reset

public void reset()
Clears this EchoFilter's internal delay buffer.


filter

public void filter(byte[] samples,
                   int offset,
                   int length)
Filters the sound samples to add an echo. The samples played are added to the sound in the delay buffer multipied by the decay rate. The result is then stored in the delay buffer, so multiple echoes are heard.


filter

public void filter(byte[] samples)
Filters an array of samples. Samples should be in 16-bit, signed, little-endian format.


getSample

public static short getSample(byte[] buffer,
                              int position)
Convenience method for getting a 16-bit sample from a byte array. Samples should be in 16-bit, signed, little-endian format.


setSample

public static void setSample(byte[] buffer,
                             int position,
                             short sample)
Convenience method for setting a 16-bit sample in a byte array. Samples should be in 16-bit, signed, little-endian format.