danger.audio
Class SimpleTonePlayer

java.lang.Object
  extended by danger.audio.SimpleTonePlayer


public class SimpleTonePlayer
extends Object

A simple mechanism for generating audio tones. A single SimpleTonePlayer can play up to 15 tones simultaneously. For more tones, use a second SimpleTonePlayer.


Constructor Summary
SimpleTonePlayer()
          Creates a new SimpleTonePlayer.
SimpleTonePlayer(boolean preallocate)
          Creates a new SimpleTonePlayer.
 
Method Summary
 void destroy()
          Frees as many resources as possible that are currently held by this object.
 void playTone(int note, int duration, int volume)
          Plays a single tone at a particular volume and for a specified duration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTonePlayer

public SimpleTonePlayer()
Creates a new SimpleTonePlayer. Each SimpleTonePlayer corresponds to a single, 15-channel Sequence. However, the Sequence will be transparently allocated and freed as needed.

See Also:
Sequence

SimpleTonePlayer

public SimpleTonePlayer(boolean preallocate)
                 throws AudioException
Creates a new SimpleTonePlayer. Each SimpleTonePlayer corresponds to a single, 15-channel Sequence. If pre-allocation is enabled, the sequence will be pre-allocated and reused for the life of the SimpleTonePlayer. Otherwise, the Sequence will be transparently allocated and freed as needed.

Parameters:
preallocate - whether to pre-allocate a Sequence
Throws:
AudioException - if the Sequence cannot be allocated
See Also:
Sequence
Method Detail

destroy

public void destroy()
Frees as many resources as possible that are currently held by this object. The object cannot be used again after being destroyed.


playTone

public void playTone(int note,
                     int duration,
                     int volume)
              throws AudioException
Plays a single tone at a particular volume and for a specified duration.

Parameters:
note - the MIDI note to play
duration - the length of the note, in milliseconds
volume - the volume of the note on a linear scale, where 0 is silence, and 100 is maximum volume
Throws:
AudioException - if all channels are currently in use
IllegalArgumentException - if note is less than 0 or greater than 127, or if duration is less than or equal to 0
IllegalStateException - if this object has been destroyed