org.deken.game.sound.audio.streamAudioFilter
Class EchoStreamFilter

java.lang.Object
  extended by org.deken.game.sound.audio.streamAudioFilter.StreamAudioFilter
      extended by org.deken.game.sound.audio.streamAudioFilter.EchoStreamFilter

public class EchoStreamFilter
extends StreamAudioFilter

Title: EchoFilter

Description: This class is a SoundFilter that emulates an echo.

Version:
1.0
Author:
David Brackeen (Developing Games in Java)
See Also:
FilteredSoundStream

Constructor Summary
EchoStreamFilter(javax.sound.sampled.AudioInputStream inputStream)
           
EchoStreamFilter(int numDelaySamples, float decay)
          EchoFilter
 
Method Summary
 void filter(byte[] samples, int offset, int length)
          filter
 int getRemainingSize()
          getRemainingSize
 void reset()
          reset
 
Methods inherited from class org.deken.game.sound.audio.streamAudioFilter.StreamAudioFilter
filter, getSample, setAudioFormat, setSample
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EchoStreamFilter

public EchoStreamFilter(int numDelaySamples,
                        float decay)
EchoFilter

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.

Parameters:
numDelaySamples - int
decay - float

EchoStreamFilter

public EchoStreamFilter(javax.sound.sampled.AudioInputStream inputStream)
Method Detail

getRemainingSize

public int getRemainingSize()
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).

Overrides:
getRemainingSize in class StreamAudioFilter
Returns:
int

reset

public void reset()
reset

Clears this EchoFilter's internal delay buffer.

Overrides:
reset in class StreamAudioFilter

filter

public void filter(byte[] samples,
                   int offset,
                   int length)
filter

Filters the sound samples to add an echo. The samples played are added to the sound in the delay buffer multiplied by the decay rate. The result is then stored in the delay buffer, so multiple echoes are heard.

Specified by:
filter in class StreamAudioFilter
Parameters:
samples - byte[]
offset - int
length - int