edu.cmu.sphinx.tools.audio
Class AudioData

java.lang.Object
  extended byedu.cmu.sphinx.tools.audio.AudioData
Direct Known Subclasses:
Sinusoid

public class AudioData
extends java.lang.Object

Represents a 16bit, SIGNED_PCM, big endian audio clip with a sample rate specified by AudioFormat.


Constructor Summary
AudioData()
          No-arg constructor.
AudioData(javax.sound.sampled.AudioInputStream ais)
          Creates a new AudioData from the given AudioInputStream, converting the data to 16bit, big endian, SIGNED_PCM if needed.
AudioData(short[] data, float sampleRate)
          Creates a new AudioData with the given data and sample rate.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Add a ChangeListener.
 short[] getAudioData()
          Gets the SIGNED_PCM 16 bit big endian audio data.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Gets the audio format.
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Remove a ChangeListener.
 void setAudioData(short[] data)
          Sets the audio data and notifies all ChangeListeners.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioData

public AudioData()
No-arg constructor. Creates an empty clip at 16kHz sample rate.


AudioData

public AudioData(short[] data,
                 float sampleRate)
Creates a new AudioData with the given data and sample rate. Expects the data to be 16bit, big endian, SIGNED_PCM.

Parameters:
data - the audio samples; one sample per element in the array
sampleRate - the sample rate in Hz

AudioData

public AudioData(javax.sound.sampled.AudioInputStream ais)
          throws java.io.IOException
Creates a new AudioData from the given AudioInputStream, converting the data to 16bit, big endian, SIGNED_PCM if needed.

Parameters:
ais - the AudioInputStream
Throws:
java.io.IOException - if problems happen when reading from ais
Method Detail

getAudioData

public short[] getAudioData()
Gets the SIGNED_PCM 16 bit big endian audio data. NOTE: this the actual array held by this object, so only use it as a reference (i.e., don't modify the contents).

Returns:
the SIGNED_PCM 16 bit big endian samples

setAudioData

public void setAudioData(short[] data)
Sets the audio data and notifies all ChangeListeners.

Parameters:
data - the new SIGNED_PCM 16 bit big endian samples

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Gets the audio format.

Returns:
the AudioFormat for the data managed by this object

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener listener)
Add a ChangeListener.

Parameters:
listener - the listener to add

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener listener)
Remove a ChangeListener.

Parameters:
listener - the listener to remove