marf.Storage
Class SampleLoader

java.lang.Object
  extended bymarf.Storage.SampleLoader
Direct Known Subclasses:
MP3Loader, ULAWLoader, WAVLoader

public abstract class SampleLoader
extends java.lang.Object

Absract Class SampleLoader

Provides samle loading interface. Must be overriden by a concrete sample loader.

$Header: /cvsroot/marf/marf/src/marf/Storage/SampleLoader.java,v 1.12 2003/02/16 18:59:23 mokhov Exp $


Field Summary
protected  javax.sound.sampled.AudioFormat oAudioFormat
          Properties of a wave.
protected  javax.sound.sampled.AudioInputStream oAudioInputStream
          Stream representing wave sample.
protected  java.io.ByteArrayOutputStream oByteArrayOutputStream
          Output stream used for writing audio data.
protected  Sample oSample
          Sample references of the sample to be loaded.
 
Constructor Summary
SampleLoader()
          Default constructor.
 
Method Summary
 Sample getSample()
           
 long getSampleSize()
          Retrieves the length of the sample (# of audio data in the audio stream).
abstract  Sample loadSample(java.io.File poFile)
          SampleLoader interface.
 Sample loadSample(java.lang.String pstrFilename)
          Same as loadSample(File) but takes filename as an argument.
abstract  int readAudioData(double[] paiAudioData)
          Reads audio data from the sample's audio stream into paiAudioData.
 void reset()
          Resets the marker for the audio stream.
abstract  void saveSample(java.io.File poFile)
          SampleLoader interface.
 void saveSample(java.lang.String pstrFilename)
          Same as saveSample(File) but takes filename as an argument.
 void setSample(Sample poSample)
          Sets internal sample reference from outside
 void updateSample()
          UpdateSample() is just used whenever the AudioInputStream is assigned to a new value (wave file).
abstract  int writeAudioData(double[] paiAudioData, int piWords)
          Writes audio data into the sample's audio stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oSample

protected Sample oSample
Sample references of the sample to be loaded.


oAudioFormat

protected javax.sound.sampled.AudioFormat oAudioFormat
Properties of a wave.


oAudioInputStream

protected javax.sound.sampled.AudioInputStream oAudioInputStream
Stream representing wave sample.


oByteArrayOutputStream

protected java.io.ByteArrayOutputStream oByteArrayOutputStream
Output stream used for writing audio data.

Constructor Detail

SampleLoader

public SampleLoader()
Default constructor. Instantiates ByteArrayOutputStream.

Method Detail

readAudioData

public abstract int readAudioData(double[] paiAudioData)
                           throws java.lang.Exception
Reads audio data from the sample's audio stream into paiAudioData.

Parameters:
paiAudioData - an array of doubles
Returns:
integer the number of data read
Throws:
java.lang.Exception

writeAudioData

public abstract int writeAudioData(double[] paiAudioData,
                                   int piWords)
                            throws java.lang.Exception
Writes audio data into the sample's audio stream.

Parameters:
paiAudioData - an array of doubles
piWords - the number of audio data to written from the paiAudiodata
Returns:
the number of data written
Throws:
java.lang.Exception

loadSample

public abstract Sample loadSample(java.io.File poFile)
                           throws java.lang.Exception
SampleLoader interface. Must be overriden by a concrete loader that knows how to load a specific sample.

Parameters:
poFile - file object a sample to be read from
Returns:
Sample object refernce
Throws:
java.lang.Exception

loadSample

public Sample loadSample(java.lang.String pstrFilename)
                  throws java.lang.Exception
Same as loadSample(File) but takes filename as an argument.

Parameters:
pstrFilename - filename of a sample to be read from
Returns:
Sample object refernce
Throws:
java.lang.Exception

saveSample

public abstract void saveSample(java.io.File poFile)
                         throws java.lang.Exception
SampleLoader interface. Must be overriden by a concrete loader that knows how to save a specific sample.

Parameters:
poFile - File object a sample to be saved to
Throws:
java.lang.Exception

saveSample

public void saveSample(java.lang.String pstrFilename)
                throws java.lang.Exception
Same as saveSample(File) but takes filename as an argument.

Parameters:
pstrFilename - filename of a sample to be saved to
Throws:
java.lang.Exception

updateSample

public final void updateSample()
                        throws java.lang.Exception

UpdateSample() is just used whenever the AudioInputStream is assigned to a new value (wave file). Then you would simply call this method to update the Sample member with the contents of the new AudioInputStream.

Throws:
java.lang.Exception

reset

public final void reset()
                 throws java.lang.Exception
Resets the marker for the audio stream. Used after writing audio data into the sample's audio stream.

Throws:
java.lang.Exception

getSampleSize

public final long getSampleSize()
                         throws java.lang.Exception
Retrieves the length of the sample (# of audio data in the audio stream).

Returns:
sample size, long
Throws:
java.lang.Exception

getSample

public final Sample getSample()
Returns:
Sample reference

setSample

public final void setSample(Sample poSample)
Sets internal sample reference from outside

Parameters:
poSample - Sample object