marf.Storage.Loaders
Class WAVLoader

java.lang.Object
  extended by marf.Storage.SampleLoader
      extended by marf.Storage.Loaders.AudioSampleLoader
          extended by marf.Storage.Loaders.WAVLoader
All Implemented Interfaces:
ISampleLoader

public class WAVLoader
extends AudioSampleLoader

Loads/stores samples if WAVE format.

$Id: WAVLoader.java,v 1.33 2008/02/23 01:42:59 mokhov Exp $

Since:
0.0.1
Version:
$Revision: 1.33 $
Author:
Jimmy Nicolacopoulos, Serguei Mokhov

Field Summary
 
Fields inherited from class marf.Storage.Loaders.AudioSampleLoader
oAudioFormat, oAudioInputStream, oEncoding
 
Fields inherited from class marf.Storage.SampleLoader
fRequiredFrequency, iRequiredBitSize, iRequiredChannels, oByteArrayOutputStream, oSample
 
Fields inherited from interface marf.Storage.ISampleLoader
DEFAULT_CHANNELS, DEFAULT_FREQUENCY, DEFAULT_SAMPLE_BIT_SIZE, MARF_INTERFACE_CODE_REVISION
 
Constructor Summary
WAVLoader()
          Default WAVLoader Constructor.
WAVLoader(float pfRequiredFrequency, int piRequiredBitSize, int piRequiredChannels, javax.sound.sampled.AudioFormat.Encoding poEncoding)
          Allows construction of the WAVE loader with non-default parameters.
 
Method Summary
static java.lang.String getMARFSourceCodeRevision()
          Returns source code revision information.
 Sample loadSample(java.io.InputStream poAudioDataInputStream)
          Loads and decodes the WAV sample from the provided stream.
 int readSampleData(double[] padAudioData)
          Buffers out the contents of an audio buffer into the parameter.
 void reset()
          Resets the marker for the audio and byte-array streams.
 void saveSample(java.io.File poOutFile)
          Saves the wave into a file for playback.
 void validateAudioFormat(javax.sound.sampled.AudioFormat poFormat)
          Validates audio file stream format for WAVE files.
 int writeSampleData(double[] padAudioData, int piNbrWords)
          Buffers the contents of audio data parameter into the equivalent AudioInputStream object given the audio format specification.
 
Methods inherited from class marf.Storage.Loaders.AudioSampleLoader
getAudioFormat, getAudioInputStream, getEncoding, getSampleSize, loadSample, readAudioData, setAudioFormat, setAudioInputStream, setEncoding, writeAudioData
 
Methods inherited from class marf.Storage.SampleLoader
getRequiredBitSize, getRequiredChannels, getRequiredFrequency, getSample, loadSample, loadSample, saveSample, saveSample, saveSample, setRequiredBitSize, setRequiredChannels, setRequiredFrequency, setSample, updateSample
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WAVLoader

public WAVLoader()
          throws InvalidSampleFormatException
Default WAVLoader Constructor.

Throws:
InvalidSampleFormatException - if the WAV file isn't really in WAV format or any other error took place.

WAVLoader

public WAVLoader(float pfRequiredFrequency,
                 int piRequiredBitSize,
                 int piRequiredChannels,
                 javax.sound.sampled.AudioFormat.Encoding poEncoding)
          throws InvalidSampleFormatException
Allows construction of the WAVE loader with non-default parameters.

Parameters:
piRequiredFrequency - other than default of 8000
piRequiredBitSize - other than the default of 16
piRequiredChannels - other than the default of 1
poEncoding - other than the default of AudioFormat.Encoding.PCM_SIGNED
Throws:
InvalidSampleFormatException - if the WAV file isn't really in WAV format or any other error took place.
Since:
0.3.0.6
See Also:
AudioFormat.Encoding
Method Detail

loadSample

public Sample loadSample(java.io.InputStream poAudioDataInputStream)
                  throws StorageException
Loads and decodes the WAV sample from the provided stream.

Specified by:
loadSample in interface ISampleLoader
Overrides:
loadSample in class SampleLoader
Parameters:
poAudioDataInputStream - the stream of a sample to be read from
Returns:
Sample object reference
Throws:
StorageException - if there was an error loading the sample
Since:
0.3.0.6
See Also:
SampleLoader.loadSample(java.io.InputStream)

readSampleData

public final int readSampleData(double[] padAudioData)
                         throws StorageException
Buffers out the contents of an audio buffer into the parameter.

Parameters:
padAudioData - data array to fill in
Returns:
the number of sample points of data read (default is a word of two bytes)
Throws:
StorageException - if there was a problem reading the audio data
See Also:
AudioSampleLoader.readAudioData(double[])

writeSampleData

public final int writeSampleData(double[] padAudioData,
                                 int piNbrWords)
                          throws StorageException
Buffers the contents of audio data parameter into the equivalent AudioInputStream object given the audio format specification. Essentially, this method converts a double-array data to a byte array and makes it available again for reading using the standard means. The double data is assumed not to exceed a two-byte range prior conversion to bytes. If it does exceed two bytes in useful precision, then this precision will be LOST.

Parameters:
padAudioData - array of data to be written
piNbrWords - number of words to be written
Returns:
the number of data written
Throws:
StorageException - if there was an error writing audio data
See Also:
AudioSampleLoader.writeAudioData(double[], int)

saveSample

public final void saveSample(java.io.File poOutFile)
                      throws StorageException
Saves the wave into a file for playback.

Specified by:
saveSample in interface ISampleLoader
Overrides:
saveSample in class SampleLoader
Parameters:
poOutFile - File object for output
Throws:
StorageException - if there was an error saving sample
See Also:
ISampleLoader.saveSample(java.io.File)

reset

public void reset()
           throws StorageException
Resets the marker for the audio and byte-array streams. Used after writing audio data into the sample's audio stream.

Specified by:
reset in interface ISampleLoader
Overrides:
reset in class AudioSampleLoader
Throws:
StorageException - if there was an error resetting the streams
Since:
0.3.0

validateAudioFormat

public void validateAudioFormat(javax.sound.sampled.AudioFormat poFormat)
                         throws javax.sound.sampled.UnsupportedAudioFileException
Validates audio file stream format for WAVE files. Checks the format has the required bit size, number of channels, and required sampling frequency.

Parameters:
poFormat - the audio format to validate
Throws:
javax.sound.sampled.UnsupportedAudioFileException - if any of the three criteria are not met
Since:
0.3.0.5

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Returns source code revision information.

Returns:
revision string
Since:
0.3.0.2


SourceForge Logo