marf.Storage
Class Sample

java.lang.Object
  extended by marf.Storage.Sample
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Sample
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Sample data container.

The Sample Bean can contain data samples from audio, images, text, or any other data as a collection of double values. While started with Audio processing, it is not confined to audio data.

$Id: Sample.java,v 1.50 2008/02/20 07:29:06 mokhov Exp $

Since:
0.0.1
Version:
$Revision: 1.50 $
Author:
Serguei Mokhov, Jimmy Nicolacopoulos
See Also:
Serialized Form

Field Summary
protected  double[] adSample
          Sample data array (amplitudes).
static int DEFAULT_CHUNK_SIZE
          Default sample chunk's size (128).
static int DEFAULT_SAMPLE_SIZE
          Default sample array's size (1024).
protected  int iArrayIndex
          Chunk pointer in the sample array.
private  int iFormat
          Local format code.
protected  MARFAudioFileFormat oAudioFileFormat
          Grouping of file format data.
private static long serialVersionUID
          For serialization versioning.
 
Constructor Summary
Sample()
          Constructs default sample object.
Sample(double[] padData)
          Accepts pre-set sample; for testing.
Sample(int piFormat)
          Constructor with format indication.
Sample(int piFormat, double[] padData)
          Constructor with format indication and the sampled data.
Sample(Sample poSample)
          Copy-constructor.
 
Method Summary
 java.lang.Object clone()
          Clones this sample object by copying the sample format and its data.
 boolean equals(java.lang.Object poSample)
          Checks if the parameter is equal to this object.
 int getAudioFileFormatCode()
          Retrieves current sample's format.
 javax.sound.sampled.AudioFormat getAudioFormat()
          Retrieves current sample's audio format data.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 int getNextChunk(double[] padChunkArray)
          Gets the next chunk of the data and places it into padChunkArray.
 double[] getSampleArray()
          Retrieves array containing audio data of the entire sample.
 long getSampleSize()
          Returns the length of the sample.
private  void readObject(java.io.ObjectInputStream poStream)
          Custom implementation of the object reading to be able to restore the transient data.
 void reset()
          Resets the marker used for reading audio data from sample array.
 void resetArrayMark()
          Resets the marker used for reading audio data from sample array.
 void setAudioFileFormatCode(int piFileFormat)
          Sets current format of a sample.
 void setSampleArray(double[] padSampleArray)
          Sets the internal sample array (adSample) with the specified argument.
 void setSampleSize(int piDesiredSize)
          Sets internal size of the sample array.
 java.lang.String toString()
          Returns textual representation of the sample object.
private  void writeObject(java.io.ObjectOutputStream poStream)
          Implements the serialization of the object data to pair-match the readObject.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

oAudioFileFormat

protected transient MARFAudioFileFormat oAudioFileFormat
Grouping of file format data.

Since:
0.3.0.2

iFormat

private int iFormat
Local format code.

Since:
0.3.0.6

DEFAULT_SAMPLE_SIZE

public static final int DEFAULT_SAMPLE_SIZE
Default sample array's size (1024).

Since:
0.3.0.2
See Also:
Constant Field Values

DEFAULT_CHUNK_SIZE

public static final int DEFAULT_CHUNK_SIZE
Default sample chunk's size (128).

Since:
0.3.0.2
See Also:
Constant Field Values

adSample

protected double[] adSample
Sample data array (amplitudes).


iArrayIndex

protected transient int iArrayIndex
Chunk pointer in the sample array.


serialVersionUID

private static final long serialVersionUID
For serialization versioning. When adding new members or make other structural changes regenerate this number with the serialver tool that comes with JDK.

Since:
0.3.0.4
See Also:
Constant Field Values
Constructor Detail

Sample

public Sample()
Constructs default sample object.


Sample

public Sample(double[] padData)
Accepts pre-set sample; for testing.

Parameters:
padData - preset amplitude values

Sample

public Sample(int piFormat)
       throws InvalidSampleFormatException
Constructor with format indication.

Parameters:
piFormat - format number for the enumeration
Throws:
InvalidSampleFormatException - if the parameter format is invalid

Sample

public Sample(int piFormat,
              double[] padData)
       throws InvalidSampleFormatException
Constructor with format indication and the sampled data.

Parameters:
piFormat - format number for the enumeration
padData - preset amplitude values
Throws:
InvalidSampleFormatException - if the parameter format is invalid
Since:
0.3.0.5

Sample

public Sample(Sample poSample)
       throws InvalidSampleFormatException
Copy-constructor. Prior getting parameter's data, it's cloned. Only the data and format are copied.

Parameters:
poSample - sample object to copy data off from
Throws:
InvalidSampleFormatException - if the parameter format is invalid
Since:
0.3.0.5
Method Detail

getAudioFileFormatCode

public int getAudioFileFormatCode()
Retrieves current sample's format.

Returns:
an integer representing the format of the sample
Since:
0.3.0.6

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Retrieves current sample's audio format data. In 0.3.0.6 was changed to return AudioFormat instead of int; a replacement API of getAudioFileFormatCode() was added.

Returns:
an AudioFormat representing the format of the sample
See Also:
getAudioFileFormatCode()

setAudioFileFormatCode

public void setAudioFileFormatCode(int piFileFormat)
                            throws InvalidSampleFormatException
Sets current format of a sample. In 0.3.0.6 was renamed to match getAudioFileFormatCode().

Parameters:
piFileFormat - format number from the enumeration
Throws:
InvalidSampleFormatException - if the parameter format is invalid
See Also:
getAudioFileFormatCode()

setSampleArray

public void setSampleArray(double[] padSampleArray)
Sets the internal sample array (adSample) with the specified argument. Index gets reset as well.

Parameters:
padSampleArray - an array of doubles

getSampleArray

public double[] getSampleArray()
Retrieves array containing audio data of the entire sample.

Returns:
an array of doubles

getNextChunk

public int getNextChunk(double[] padChunkArray)
Gets the next chunk of the data and places it into padChunkArray. Similar to readAudioData() method only it reads from the array instead of the audio stream (file).

Parameters:
padChunkArray - an array of doubles
Returns:
number of datums retrieved

resetArrayMark

public final void resetArrayMark()
Resets the marker used for reading audio data from sample array.


reset

public void reset()
Resets the marker used for reading audio data from sample array. Added for consistency and may be overridden.

Since:
0.3.0.6
See Also:
resetArrayMark()

getSampleSize

public long getSampleSize()
Returns the length of the sample.

Returns:
long Array length

setSampleSize

public void setSampleSize(int piDesiredSize)
Sets internal size of the sample array. If array did not exist, it its created, else cut or enlarged to the desired size. The previous content is retained in full unless the desired size is less than the current (in which case the new size exceeding data is lost).

Parameters:
piDesiredSize - new desired size of the array
Throws:
java.lang.IllegalArgumentException - if the parameter is <= 0
Since:
0.3.0.2

clone

public java.lang.Object clone()
Clones this sample object by copying the sample format and its data.

Overrides:
clone in class java.lang.Object
Since:
0.3.0.5
See Also:
Object.clone()

toString

public java.lang.String toString()
Returns textual representation of the sample object. The contents is the format and length on the first line, and then a column of data.

Overrides:
toString in class java.lang.Object
Returns:
the sample data string
Since:
0.3.0.3
See Also:
Object.toString()

readObject

private void readObject(java.io.ObjectInputStream poStream)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Custom implementation of the object reading to be able to restore the transient data.

Parameters:
poStream - the stream to read this object from
Throws:
java.io.IOException
java.lang.ClassNotFoundException
Since:
0.3.0.6

writeObject

private void writeObject(java.io.ObjectOutputStream poStream)
                  throws java.io.IOException
Implements the serialization of the object data to pair-match the readObject.

Parameters:
poStream -
Throws:
java.io.IOException
See Also:
readObject(java.io.ObjectInputStream)

equals

public boolean equals(java.lang.Object poSample)
Checks if the parameter is equal to this object. The comparison is done by equality of the integer format and the data arrays. The data arrays are equal when they are both nulls or contain the same data.

Overrides:
equals in class java.lang.Object
Since:
0.3.0.6
See Also:
Object.equals(java.lang.Object)

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string
Since:
0.3.0.2


SourceForge Logo