marf.Storage
Class SampleLoader

java.lang.Object
  extended by marf.Storage.SampleLoader
All Implemented Interfaces:
ISampleLoader
Direct Known Subclasses:
AudioSampleLoader, SineLoader, TextLoader

public abstract class SampleLoader
extends java.lang.Object
implements ISampleLoader

Abstract class that provides a generic implementation of the sample loading interface. Must be overridden by a concrete sample loader.

$Id: SampleLoader.java,v 1.29 2008/02/21 06:05:08 mokhov Exp $

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

Field Summary
protected  float fRequiredFrequency
          Current frequency.
protected  int iRequiredBitSize
          Current bit size of a sample.
protected  int iRequiredChannels
          Current number of channels.
protected  java.io.ByteArrayOutputStream oByteArrayOutputStream
          Output stream used for writing audio data.
protected  Sample oSample
          Sample references of the sample to be loaded.
 
Fields inherited from interface marf.Storage.ISampleLoader
DEFAULT_CHANNELS, DEFAULT_FREQUENCY, DEFAULT_SAMPLE_BIT_SIZE, MARF_INTERFACE_CODE_REVISION
 
Constructor Summary
SampleLoader()
          Default constructor.
 
Method Summary
static java.lang.String getMARFSourceCodeRevision()
          Returns source code revision information.
 int getRequiredBitSize()
           
 int getRequiredChannels()
           
 float getRequiredFrequency()
           
 Sample getSample()
          Returns internal reference to a Sample object.
 long getSampleSize()
          Retrieves the length of the sample (# of audio data in the audio stream).
 Sample loadSample(byte[] patFileData)
          Converts the byte array into a buffered byte array input stream and passes it on.
 Sample loadSample(java.io.File poInFile)
          Loads sample data from a file.
 Sample loadSample(java.io.InputStream poDataInputStream)
          Not implemented.
 Sample loadSample(java.lang.String pstrFilename)
          Same as loadSample(File) but takes filename as an argument.
 void reset()
          Resets the marker for the audio stream.
 void saveSample(byte[] patFileData)
          Assumes the file data is in the array of bytes for loading.
 void saveSample(java.io.File poOutFile)
          Prime SampleLoader interface.
 void saveSample(java.io.OutputStream poDataOutputStream)
          Assumes the output stream is the sample file data.
 void saveSample(java.lang.String pstrFilename)
          Same as saveSample(File) but takes filename as an argument.
 void setRequiredBitSize(int piRequiredBitSize)
           
 void setRequiredChannels(int piRequiredChannels)
           
 void setRequiredFrequency(float piRequiredFrequency)
           
 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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface marf.Storage.ISampleLoader
readSampleData, writeSampleData
 

Field Detail

iRequiredBitSize

protected int iRequiredBitSize
Current bit size of a sample.


iRequiredChannels

protected int iRequiredChannels
Current number of channels.


fRequiredFrequency

protected float fRequiredFrequency
Current frequency.

Since:
0.3.0

oSample

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


oByteArrayOutputStream

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

Constructor Detail

SampleLoader

public SampleLoader()
Default constructor. Instantiates ByteArrayOutputStream.

Method Detail

loadSample

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

Specified by:
loadSample in interface ISampleLoader
Parameters:
pstrFilename - filename of a sample to be read from
Returns:
Sample object reference
Throws:
StorageException - if there was an error loading the sample
See Also:
loadSample(File)

loadSample

public Sample loadSample(java.io.File poInFile)
                  throws StorageException
Loads sample data from a file. In a nutshell, converts the File into a buffered file input streams and passes it on the appropriate method.

Specified by:
loadSample in interface ISampleLoader
Parameters:
poInFile - incoming sample File object
Returns:
Sample object
Throws:
StorageException - if there was a problem loading the sample
Since:
0.3.0.6
See Also:
loadSample(InputStream)

loadSample

public Sample loadSample(byte[] patFileData)
                  throws StorageException
Converts the byte array into a buffered byte array input stream and passes it on.

Specified by:
loadSample in interface ISampleLoader
Parameters:
patFileData - the byte data 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:
ISampleLoader.loadSample(byte[]), loadSample(InputStream)

loadSample

public Sample loadSample(java.io.InputStream poDataInputStream)
                  throws StorageException
Not implemented. Must be overridden to work.

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

saveSample

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

Specified by:
saveSample in interface ISampleLoader
Parameters:
pstrFilename - filename of a sample to be saved to
Throws:
StorageException - if there was an error saving the sample

saveSample

public void saveSample(byte[] patFileData)
                throws StorageException
Description copied from interface: ISampleLoader
Assumes the file data is in the array of bytes for loading.

Specified by:
saveSample in interface ISampleLoader
Parameters:
patFileData - the byte data of a sample to be read from
Throws:
NotImplementedException - incomplete
StorageException - if there was an error loading the sample
Since:
0.3.0.6
See Also:
ISampleLoader.saveSample(byte[])

saveSample

public void saveSample(java.io.File poOutFile)
                throws StorageException
Description copied from interface: ISampleLoader
Prime SampleLoader interface. Must be overridden by a concrete loader that knows how to save a specific sample.

Specified by:
saveSample in interface ISampleLoader
Parameters:
poOutFile - File object of a sample to be saved to
Throws:
StorageException - if there was an error saving the sample
Since:
0.3.0.6
See Also:
ISampleLoader.saveSample(java.io.File)

saveSample

public void saveSample(java.io.OutputStream poDataOutputStream)
                throws StorageException
Description copied from interface: ISampleLoader
Assumes the output stream is the sample file data.

Specified by:
saveSample in interface ISampleLoader
Parameters:
poDataOutputStream - the stream of a sample to be written to
Throws:
StorageException - if there was an error loading the sample
Since:
0.3.0.6
See Also:
ISampleLoader.saveSample(java.io.OutputStream)

updateSample

public void updateSample()
                  throws StorageException

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.

Specified by:
updateSample in interface ISampleLoader
Throws:
StorageException - if there was an error updating the sample data array

reset

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

Specified by:
reset in interface ISampleLoader
Throws:
StorageException - if there was an error resetting the audio stream

getSampleSize

public long getSampleSize()
                   throws StorageException
Retrieves the length of the sample (# of audio data in the audio stream).

Specified by:
getSampleSize in interface ISampleLoader
Returns:
sample size, long
Throws:
StorageException - if there was an error getting sample size

getSample

public final Sample getSample()
Returns internal reference to a Sample object.

Specified by:
getSample in interface ISampleLoader
Returns:
Sample reference

setSample

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

Specified by:
setSample in interface ISampleLoader
Parameters:
poSample - Sample object

getRequiredBitSize

public int getRequiredBitSize()

setRequiredBitSize

public void setRequiredBitSize(int piRequiredBitSize)

getRequiredChannels

public int getRequiredChannels()

setRequiredChannels

public void setRequiredChannels(int piRequiredChannels)

getRequiredFrequency

public float getRequiredFrequency()

setRequiredFrequency

public void setRequiredFrequency(float piRequiredFrequency)

getMARFSourceCodeRevision

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

Returns:
revision string
Since:
0.3.0.2


SourceForge Logo