marf.Storage
Class Sample

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

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

Audio sample data container.

$Id: Sample.java,v 1.36 2005/07/30 21:38:24 mokhov Exp $

Since:
0.0.1
Version:
$Revision: 1.36 $
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.
 
Constructor Summary
Sample()
          Constructs default sample object.
Sample(double[] padData)
          Accepts pre-set sample; for testing.
Sample(int piFormat)
          Constructor with format indication.
 
Method Summary
 int getAudioFormat()
          Retrieves current sample's format.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 int getNextChunk(double[] padChunkArray)
          Gets the next chunk of audio 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.
 void resetArrayMark()
          Resets the marker used for reading audio data from sample array.
 void setAudioFormat(int piFormat)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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.

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
Method Detail

getAudioFormat

public final int getAudioFormat()
Retrieves current sample's format.

Returns:
an integer representing the format of the sample

setAudioFormat

public final void setAudioFormat(int piFormat)
                          throws InvalidSampleFormatException
Sets current format of a sample.

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

setSampleArray

public final 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 final double[] getSampleArray()
Retrieves array containing audio data of the entire sample.

Returns:
an array of doubles

getNextChunk

public final int getNextChunk(double[] padChunkArray)
Gets the next chunk of audio 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.


getSampleSize

public final 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 unless the desired size is less than the current.

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

toString

public java.lang.String toString()
Returns textual representation of the sample object. The contents is the format and lengthon 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()

getMARFSourceCodeRevision

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

Returns:
revision string
Since:
0.3.0.2