com.groovemanager.sampled.waveform
Class DynamicPeakWaveForm

java.lang.Object
  extended by com.groovemanager.sampled.waveform.AbstractWaveForm
      extended by com.groovemanager.sampled.waveform.PeakWaveForm
          extended by com.groovemanager.sampled.waveform.DynamicPeakWaveForm
All Implemented Interfaces:
WaveForm

public class DynamicPeakWaveForm
extends PeakWaveForm

This class extends PeakWaveForm for being able to handle dynamically growing audio files especially for recording situations. This class is used by DynamicAudioFileWaveForm.

Author:
Manu Robledo

Field Summary
private static int ARRAY_SIZE
          size of one pool element
private  boolean bigEndian
          endianess of the audio format
private  byte[] dataBuffer
          Temporary buffer
private  int dataPos
          Current write position for peak data to append
private  byte[][] datas
          peak data pool
private  java.io.File f
          The file into which the peak data should be written
private  int frameSize
          Frame size of the audio format in bytes
private  int index
          Current index inside the pool
private  int[] positions
          peak data pool positions
private  java.io.RandomAccessFile raFile
          RandomAccessFile wor reading and writing the peak data
private  int sampleSize
          Frame size of the audio format in bytes
private  int tempCount
          Temporary counter
 
Fields inherited from class com.groovemanager.sampled.waveform.PeakWaveForm
data, DEFAULT_PEAKFILE_EXTENSION, source
 
Fields inherited from class com.groovemanager.sampled.waveform.AbstractWaveForm
channels, displayWidth, intervallSize, nullWave, position, realLength
 
Constructor Summary
DynamicPeakWaveForm(javax.sound.sampled.AudioFormat format, int iSize)
          Construct a new DynamicPeakWaveForm
 
Method Summary
 void append(byte[] data, int offset, int length)
          Dynamically append audio data to this WaveForm
 void close(long lastModified)
          Close this WaveForm indicating that no more data will be appended.
private  byte[] getCurrentData()
          Get the peak data for the current position.
private  int getCurrentIndex()
          Get the index of the peak data at the current position
 byte getMax(int channel)
          Get the maximum value at the current read position in the given channel
 byte getMin(int channel)
          Get the minimum value at the current read position in the given channel
private  void readDataAt(int index, byte[] b)
          Read peak data from the peak file at the given index
 
Methods inherited from class com.groovemanager.sampled.waveform.PeakWaveForm
checkPeakFile, createPeakWaveForm, getAdditionalToString, getData, getHeader, getPeak, readFromFile, subWaveForm, writeToStream
 
Methods inherited from class com.groovemanager.sampled.waveform.AbstractWaveForm
canProvide, getChannels, getDisplayableLength, getIntervallSize, getPosition, getRealLength, getRealPosition, getZoomFactor, next, rewind, setPosition, setRealPosition, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ARRAY_SIZE

private static final int ARRAY_SIZE
size of one pool element

See Also:
Constant Field Values

bigEndian

private boolean bigEndian
endianess of the audio format


dataBuffer

private byte[] dataBuffer
Temporary buffer


dataPos

private int dataPos
Current write position for peak data to append


datas

private byte[][] datas
peak data pool


f

private java.io.File f
The file into which the peak data should be written


frameSize

private int frameSize
Frame size of the audio format in bytes


index

private int index
Current index inside the pool


positions

private int[] positions
peak data pool positions


raFile

private java.io.RandomAccessFile raFile
RandomAccessFile wor reading and writing the peak data


sampleSize

private int sampleSize
Frame size of the audio format in bytes


tempCount

private int tempCount
Temporary counter

Constructor Detail

DynamicPeakWaveForm

public DynamicPeakWaveForm(javax.sound.sampled.AudioFormat format,
                           int iSize)
Construct a new DynamicPeakWaveForm

Parameters:
format - The format of the source audio format
iSize - The interval size to be used
Method Detail

append

public void append(byte[] data,
                   int offset,
                   int length)
Dynamically append audio data to this WaveForm

Parameters:
data - The audio data to append
offset - Start position inside the data Array
length - The length of data to append

close

public void close(long lastModified)
Close this WaveForm indicating that no more data will be appended. The header will be written into the file with the given audio file modification date

Parameters:
lastModified - The modification date of the audio file this WaveForm belongs to id it is known, otherwise -1

getCurrentData

private byte[] getCurrentData()
Get the peak data for the current position. This data will either be read from the peak file or from the pool of peak data

Returns:
The peak data that contains the peak values for the current position

getCurrentIndex

private int getCurrentIndex()
Get the index of the peak data at the current position

Returns:
The index of the peak data for the current position

getMax

public byte getMax(int channel)
Description copied from interface: WaveForm
Get the maximum value at the current read position in the given channel

Specified by:
getMax in interface WaveForm
Overrides:
getMax in class PeakWaveForm
Parameters:
channel - the zero-based index of the channel
Returns:
the maximum value at this position as byte

getMin

public byte getMin(int channel)
Description copied from interface: WaveForm
Get the minimum value at the current read position in the given channel

Specified by:
getMin in interface WaveForm
Overrides:
getMin in class PeakWaveForm
Parameters:
channel - the zero-based index of the channel
Returns:
the minimum value at this position as byte

readDataAt

private void readDataAt(int index,
                        byte[] b)
Read peak data from the peak file at the given index

Parameters:
index - The index to read
b - The byte Array to read the data into