com.realtime.crossfire.jxclient.sound
Class Processor

java.lang.Object
  extended by com.realtime.crossfire.jxclient.sound.Processor
All Implemented Interfaces:
java.lang.Runnable

public class Processor
extends java.lang.Object
implements java.lang.Runnable

A thread that plays a music file over and over until terminated.


Field Summary
private  AudioFileLoader audioFileLoader
          The AudioFileLoader for loading audio files.
private static float MIN_VALUE
          The minimum factor for fading in/out effects.
private  java.lang.String name
          The name of the music to play.
private  int state
          The current state: 0=fade in, 1=playing, 2=fade out, 3=terminate, 4=terminate immediately.
private  float volume
          The current volume.
private static float VOLUME_STEP_PER_SAMPLE
          The step for the fading in/out factor.
 
Constructor Summary
Processor(java.lang.String name, AudioFileLoader audioFileLoader)
          Creates a new instance.
 
Method Summary
private  void convertSample(byte[] buf, int i)
          Converts one audio sample according to the current volume.
private  javax.sound.sampled.AudioInputStream openAudioInputStream()
          Opens and returns an audio stream for name.
 void run()
          
 void terminate(boolean fadeOut)
          Stops playing music.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

audioFileLoader

@NotNull
private final AudioFileLoader audioFileLoader
The AudioFileLoader for loading audio files.


MIN_VALUE

private static final float MIN_VALUE
The minimum factor for fading in/out effects.

See Also:
Constant Field Values

name

@NotNull
private final java.lang.String name
The name of the music to play.


state

private int state
The current state: 0=fade in, 1=playing, 2=fade out, 3=terminate, 4=terminate immediately.


volume

private float volume
The current volume. It is a factor that is multiplied to all sample values while fading in/out.


VOLUME_STEP_PER_SAMPLE

private static final float VOLUME_STEP_PER_SAMPLE
The step for the fading in/out factor. It is multiplied to the current value for each sample.

See Also:
Constant Field Values
Constructor Detail

Processor

public Processor(@NotNull
                 java.lang.String name,
                 @NotNull
                 AudioFileLoader audioFileLoader)
Creates a new instance.

Parameters:
name - the music name to play
audioFileLoader - the audio file loader for loading audio files
Method Detail

convertSample

private void convertSample(@NotNull
                           byte[] buf,
                           int i)
Converts one audio sample according to the current volume.

Parameters:
buf - the buffer holding the sample
i - the sample offset

openAudioInputStream

@NotNull
private javax.sound.sampled.AudioInputStream openAudioInputStream()
                                                           throws java.io.IOException,
                                                                  javax.sound.sampled.UnsupportedAudioFileException
Opens and returns an audio stream for name.

Returns:
the audio stream
Throws:
java.io.IOException - if the file cannot be opened
javax.sound.sampled.UnsupportedAudioFileException - if the file cannot be decoded

run

public void run()

Specified by:
run in interface java.lang.Runnable

terminate

public void terminate(boolean fadeOut)
Stops playing music. The music is faded out rather than cut off.

Parameters:
fadeOut - Whether tp fade out the music (true) or to cut it off (false).