com.groovemanager.sampled.waveform
Interface WaveForm

All Known Implementing Classes:
AbstractWaveForm, AudioFileWaveForm, ByteArrayWaveForm, ConcatWaveForm, DynamicAudioFileWaveForm, DynamicPeakWaveForm, EmptyWaveForm, FillUpWaveForm, PeakWaveForm, UpdatingWaveForm, WaveFormPart, ZoomedWaveForm

public interface WaveForm

A WaveForm is a representation of audio data that can be used for displaying the data on the screen. The problem, is that it would make no sense if an audio source would have to be read completely for each redrawing of the data. To avoid this, minimum and maximum values of parts the audio data is stored in some way. Implementers of this interface represent an audio source and can display its content, but do not have to read through the whole data. To keep the memory costs low, each sample is represented as a byte value. That means, that only 256 different values are possible for the drawing position. For most cases this should be enough though.

Author:
Manu Robledo

Method Summary
 boolean canProvide(int begin, int length, int width)
          Tells if this WaveForm sees itself capable of providing a SubWaveForm with the given parameters
 int getChannels()
          Get the number of channels in this WaveForm
 byte[] getData()
          Get the whole Peak data as array.
 int getDisplayableLength()
          Get the total displayable length of this WaveForm.
 int getIntervallSize()
          Get the number of samples of the original Sample which are represented by one step of this WaveForm.
 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
 int getPosition()
          Get the read position of this WaveForm
 int getRealLength()
          Get the Length of the original sample which this WaveForm represents
 int getRealPosition()
          Get the position inside the sample represented by this WaveForm corresponding to the actual read position of this WaveForm.
 double getZoomFactor()
          Get the ratio between the length of the represented Sample and and the displayable length of this WaveForm.
 boolean next()
          Tells the WaveForm to increase its position by one
 void rewind()
          Sets the current read position to the beginning of this WaveForm
 void setPosition(int pos)
          Set the read position of this WaveForm
 void setRealPosition(int pos)
          Set the read position of this WaveForm to the value corresponding to the given real position of the represented sample.
 WaveForm subWaveForm(int begin, int length, int width)
          Get a WaveForm Object that represents the part of this WaveForm specified by begin and length and displays this part in the specified width
 

Method Detail

canProvide

boolean canProvide(int begin,
                   int length,
                   int width)
Tells if this WaveForm sees itself capable of providing a SubWaveForm with the given parameters

Parameters:
begin - The offset to the beginning of this WaveForm. May also be negative.
length - The length in steps of this WaveForm that should be represented by the returned WaveForm.
width - The new width in which the part should be displayed.
Returns:
true if this WaveForm can provide the wanted subWaveForm, false otherwise
See Also:
subWaveForm(int, int, int)

getChannels

int getChannels()
Get the number of channels in this WaveForm

Returns:
The number of channels (1 or bigger)

getData

byte[] getData()
Get the whole Peak data as array. This method could take very long for WaveForms which don't store their data in such an array. Should be very fast for peak Wave Forms.

Returns:
The Peak Data as byte-Array.

getDisplayableLength

int getDisplayableLength()
Get the total displayable length of this WaveForm.

Returns:
The length of this WaveForm

getIntervallSize

int getIntervallSize()
Get the number of samples of the original Sample which are represented by one step of this WaveForm. Especially interesting for PeakWaveForms.

Returns:
The number of samples

getMax

byte getMax(int channel)
Get the maximum value at the current read position in the given channel

Parameters:
channel - the zero-based index of the channel
Returns:
the maximum value at this position as byte

getMin

byte getMin(int channel)
Get the minimum value at the current read position in the given channel

Parameters:
channel - the zero-based index of the channel
Returns:
the minimum value at this position as byte

getPosition

int getPosition()
Get the read position of this WaveForm

Returns:
The current read position

getRealLength

int getRealLength()
Get the Length of the original sample which this WaveForm represents

Returns:
The length of the original sample in sample frames.

getRealPosition

int getRealPosition()
Get the position inside the sample represented by this WaveForm corresponding to the actual read position of this WaveForm. For WaveForms with a zoom factor of 1.0 this method should behave exactly like getPosition()

Returns:
The position in the original sample

getZoomFactor

double getZoomFactor()
Get the ratio between the length of the represented Sample and and the displayable length of this WaveForm.

Returns:
getRealLength() / (double)getDisplayableLength()

next

boolean next()
Tells the WaveForm to increase its position by one

Returns:
true if the end position was not reached before this method call so that the position could be increased, false otherwise. The return value can be used for iteratin over the whole WaveForm like this:
IWaveForm w = ...;
int channel = ...;
w.rewind();
do{
byte min = w.getMin(channel);
byte max = w.getMax(channel);
// ...(do something with those values)
} while(w.next());

rewind

void rewind()
Sets the current read position to the beginning of this WaveForm


setPosition

void setPosition(int pos)
Set the read position of this WaveForm

Parameters:
pos - The new read position

setRealPosition

void setRealPosition(int pos)
Set the read position of this WaveForm to the value corresponding to the given real position of the represented sample. For WaveForms with a zoom factor of 1.0 this method should behave exactly like setPosition(pos)

Parameters:
pos - The new position in the original sample

subWaveForm

WaveForm subWaveForm(int begin,
                     int length,
                     int width)
Get a WaveForm Object that represents the part of this WaveForm specified by begin and length and displays this part in the specified width

Parameters:
begin - The offset to the beginning of this WaveForm. May also be negative.
length - The length in steps of this WaveForm that should be represented by the returned WaveForm.
width - The new width in which the part should be displayed.
Returns:
A WaveForm Object that represents the specified Part of this WaveForm and displays it in the given width. Can also be the same Object with adapted attributes