jfrace.device
Class WaveTablePlayer

java.lang.Object
  |
  +--jfrace.device.WaveTablePlayer
Direct Known Subclasses:
GI_AY_3_8910ToneGenerator

public class WaveTablePlayer
extends java.lang.Object

Audio player based on a wave table. The player uses the undocumented audio player sun.audio.AudioPlayer. The sun.audio package is part of every JDK and of Java implementation of (presumably) all web browsers supporting Java. Note that sun.audio.AudioPlayer plays only 8000 Hz sampled u-law encoded audio data. The method setWaveTable automatically encodes the data.

Author:
Franz-Josef Elmer

Field Summary
protected  byte[] waveTable
          Byte array of the wave table.
 
Constructor Summary
WaveTablePlayer(int size)
          Create an instance with a given size of the wave table.
 
Method Summary
 int getLength()
          Return the length of the current wave form.
 int getSize()
          Return the size of the wave table.
 boolean isPlaying()
          Return the playing flag.
protected static byte linear2ulaw(int pcm_val)
          Linear 2 byte to 1 byte u-law.
 void play()
          Start playing and set the playing flag.
protected  void setLength(int value)
          Set the length of the actual wave form
 void setWaveTable(int[] waveForm)
          Set the wave form of the wave table.
 void stop()
          Stop playing and reset the playing flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

waveTable

protected byte[] waveTable
Byte array of the wave table.
Constructor Detail

WaveTablePlayer

public WaveTablePlayer(int size)
Create an instance with a given size of the wave table.
Parameters:
size - Wave table size, i.e. the maximum number of bytes a wave form can have.
Method Detail

linear2ulaw

protected static byte linear2ulaw(int pcm_val)
Linear 2 byte to 1 byte u-law.
Parameters:
pcm_val - 16 bit linear value
Returns:
u-law encoded input

getSize

public int getSize()
Return the size of the wave table. This is the maximum number of bytes a wave form can have.

getLength

public int getLength()
Return the length of the current wave form.

setLength

protected void setLength(int value)
Set the length of the actual wave form

setWaveTable

public void setWaveTable(int[] waveForm)
Set the wave form of the wave table. In the playing modus this wave form will be continuously repeated. The wave form will be stored in the wave table as u-law encoded bytes.
Parameters:
waveForm - Array of the wave form.

play

public void play()
Start playing and set the playing flag. Does nothing if the playing flag is already set.

isPlaying

public boolean isPlaying()
Return the playing flag.

stop

public void stop()
Stop playing and reset the playing flag. Does nothing if the playing flag is already reset.