marytts.signalproc.window
Class Window

java.lang.Object
  extended by marytts.signalproc.window.Window
All Implemented Interfaces:
CopyingDataProcessor, InlineDataProcessor
Direct Known Subclasses:
BartlettWindow, BlackmanWindow, FlattopWindow, GaussWindow, HammingWindow, HanningWindow, RectWindow

public abstract class Window
extends java.lang.Object
implements CopyingDataProcessor, InlineDataProcessor

Author:
Marc Schröder Interface for windowing functions.

Field Summary
static int BARTLETT
           
static int BLACKMAN
           
protected  boolean evenLength
           
static int FLATTOP
           
static int GAUSS
           
static int HAMMING
           
static int HANNING
           
protected  double prescalingFactor
           
static int RECT
           
protected  double[] window
          This array, whose length is the window length, holds the multiplication factors for each sample across the window.
 
Constructor Summary
protected Window()
          Default constructor for subclasses that need to do something themselves before calling initialise().
  Window(int length)
          Create a new window of length length.
  Window(int length, double prescalingFactor)
          Create a new window of length length, and apply the given prescaling factor to each point.
 
Method Summary
 double[] apply(double[] src)
           
 double[] apply(double[] src, int pos)
          Apply this window on the given source data array, at the given position.
 void apply(double[] src, int srcPos, double[] target, int targetPos)
          Apply this window on the given source data array, at the given position.
 void apply(double[] src, int srcPos, double[] target, int targetPos, int len)
          Apply this window on the given source data array, at the given position.
 void apply(double[] src, int srcPos, double[] target, int targetPos, int off, int len)
          Apply a part of this window on the given source data array, at the given position.
 void applyInline(double[] data)
           
 void applyInline(double[] data, int pos)
           
 void applyInline(double[] data, int pos, int len)
          Apply the window function in-line, i.e.
static Window get(int windowType, int length)
          Convenience method for requesting a window of the requested type.
static Window get(int windowType, int length, double prescale)
          Convenience method for requesting a window of the requested type.
static int[] getAvailableTypes()
          List all available window types
 double[] getCoeffs()
           
 double[] getCoeffsLeftHalf()
           
 double[] getCoeffsRightHalf()
           
 int getLength()
          Return the length of this window, in samples.
static int getTypeByName(java.lang.String typeName)
          For a given type name (e.g., "Hanning window", or "BARTLETT"), return the type code.
static java.lang.String getTypeName(int windowType)
          Get the type name of a window type.
protected abstract  void initialise()
          The initialisation of the window array with multiplication factors corresponding to the specific windowing function.
 void normalize()
           
 void normalize(float val)
           
 void normalizePeakValue(float desiredPeakValue)
           
 void normalizeRange(float minVal, float maxVal)
           
 void normalizeSquaredSum(float val)
           
 int type()
          Return this window's type, as defined by the constants in Window, or -1 if the window is not of a known type.
 double value(int i)
          Get the value of the window function at index position i
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECT

public static final int RECT
See Also:
Constant Field Values

HAMMING

public static final int HAMMING
See Also:
Constant Field Values

BLACKMAN

public static final int BLACKMAN
See Also:
Constant Field Values

HANNING

public static final int HANNING
See Also:
Constant Field Values

GAUSS

public static final int GAUSS
See Also:
Constant Field Values

BARTLETT

public static final int BARTLETT
See Also:
Constant Field Values

FLATTOP

public static final int FLATTOP
See Also:
Constant Field Values

prescalingFactor

protected double prescalingFactor

evenLength

protected boolean evenLength

window

protected double[] window
This array, whose length is the window length, holds the multiplication factors for each sample across the window. It must be initialised in the constructor, using the method #initialise().

Constructor Detail

Window

protected Window()
Default constructor for subclasses that need to do something themselves before calling initialise().


Window

public Window(int length)
Create a new window of length length. This will call #initialise() in the respective subclass in order to fill the window array with meaningful multiplication values.

Parameters:
length - the window length, in samples; this should be an odd number, so that the window can be symmetric around the center point.

Window

public Window(int length,
              double prescalingFactor)
Create a new window of length length, and apply the given prescaling factor to each point. This will call #initialise() in the respective subclass in order to fill the window array with meaningful multiplication values.

Parameters:
length - the window length, in samples; this should be an odd number, so that the window can be symmetric around the center point.
prescalingFactor - a factor to apply to each window point.
Method Detail

apply

public double[] apply(double[] src,
                      int pos)
Apply this window on the given source data array, at the given position. This method returns the resulting data in a new array of the same length as this window (@see getLength()). If src has less than getLength() data points left at pos, zeros are added at the end.

Parameters:
src - the source data array to apply the windowing function to.
pos - the position from which to apply the windowing function
Returns:
an array of the same length as this window, computed by applying this window to the source data.
Throws:
java.lang.IllegalArgumentException - if targetLength is smaller than this window's length as returned by #getLength().

apply

public double[] apply(double[] src)

applyInline

public void applyInline(double[] data,
                        int pos,
                        int len)
Apply the window function in-line, i.e. by modifying the original data.

Specified by:
applyInline in interface InlineDataProcessor
Parameters:
data -
pos - the position in the data array where to start applying the window function.
len - the amount of data after position pos to process. len must be less than or equal to getLength(). If it is less than getLength(), a truncated window will be applied.
Throws:
java.lang.IllegalArgumentException - if len != getLength().

applyInline

public void applyInline(double[] data,
                        int pos)

applyInline

public void applyInline(double[] data)

apply

public void apply(double[] src,
                  int srcPos,
                  double[] target,
                  int targetPos)
Apply this window on the given source data array, at the given position. This method returns the resulting data in the given target array, at the target position given by targetPos. If src has less than getLength() data points left at pos, zeros are added at the end.

Parameters:
src - the source data array to apply the windowing function to.
srcPos - the position in the source array from which to apply the windowing function
target - an array to receive the target data, computed by applying this window to the source data. The target array must be long enough to receive getLength() bytes after targetPos. if target == source and targetPos == srcPos, then the window function is applied in-place.
Throws:
java.lang.IllegalArgumentException - if target.length-targetPos is smaller than this window's length as returned by #getLength().

apply

public void apply(double[] src,
                  int srcPos,
                  double[] target,
                  int targetPos,
                  int len)
Apply this window on the given source data array, at the given position. This method returns the resulting data in the given target array, at the target position given by targetPos. If src has less than getLength() data points left at pos, zeros are added at the end.

Specified by:
apply in interface CopyingDataProcessor
Parameters:
src - the source data array to apply the windowing function to.
srcPos - the position in the source array from which to apply the windowing function. If srcPos is negative, abs(srcPos) zeroes will be pre-pended before the first data from src is taken into account; if it is greater than src.length-getLength(), the result will be filled up with trailing zeroes behind the last data.
target - an array to receive the target data, computed by applying this window to the source data. The target array must be long enough to receive getLength() bytes after targetPos. if target == source and targetPos == srcPos, then the window function is applied in-place.
len - the number of samples of the window to apply; this must be less than or equal getLength(). If it is less than getLength(), a truncated window will be applied.
Throws:
java.lang.IllegalArgumentException - if target.length-targetPos is smaller than this window's length as returned by #getLength(), or if len >= getLength.

apply

public void apply(double[] src,
                  int srcPos,
                  double[] target,
                  int targetPos,
                  int off,
                  int len)
Apply a part of this window on the given source data array, at the given position. For example, by setting off to getLength()/2 and len to getLength()/2, only the right half of the window will be applied. This method returns the resulting data in the given target array, at the target position given by targetPos. If src has less than len data points left at srcPos, zeros are added at the end.

Parameters:
src - the source data array to apply the windowing function to.
srcPos - the position in the source array from which to apply the windowing function. If srcPos is negative, abs(srcPos) zeroes will be pre-pended before the first data from src is taken into account; if it is greater than src.length-getLength(), the result will be filled up with trailing zeroes behind the last data.
target - an array to receive the target data, computed by applying this window to the source data. The target array must be long enough to receive getLength() bytes after targetPos. if target == source and targetPos == srcPos, then the window function is applied in-place.
off - the offset from the start of the window from where on the window is to be applied.
len - the number of samples of the window to apply; off+len must be less than or equal getLength().
Throws:
java.lang.IllegalArgumentException - if target.length-targetPos is smaller than this window's length as returned by #getLength(), or if len >= getLength.

initialise

protected abstract void initialise()
The initialisation of the window array with multiplication factors corresponding to the specific windowing function. This needs to be implemented by each subclass.


getLength

public int getLength()
Return the length of this window, in samples.

Throws:
java.lang.NullPointerException - if the window has not yet been initialised.

value

public double value(int i)
Get the value of the window function at index position i

Parameters:
i - the index position in the window for which to return the value
Returns:
the value of the window function, between 0 and 1.
Throws:
java.lang.IllegalArgumentException - if i<0 or i>getLength().
java.lang.NullPointerException - if the window has not yet been initialised.

type

public int type()
Return this window's type, as defined by the constants in Window, or -1 if the window is not of a known type.

Returns:

get

public static Window get(int windowType,
                         int length)
Convenience method for requesting a window of the requested type.

Parameters:
windowType - one of the constants defined in Window.
length - window length (should be an odd number)
Returns:
a window of the requested type and length
Throws:
java.lang.IllegalArgumentException - if windowType is not a valid window type, or if length is an even number

get

public static Window get(int windowType,
                         int length,
                         double prescale)
Convenience method for requesting a window of the requested type.

Parameters:
windowType - one of the constants defined in Window.
length - window length (should be an odd number)
prescale - a prescaling factor applied to all points in the window
Returns:
a window of the requested type and length
Throws:
java.lang.IllegalArgumentException - if windowType is not a valid window type, or if length is an even number

getAvailableTypes

public static int[] getAvailableTypes()
List all available window types

Returns:
an integer corresponding to the constants defined in Window.

getTypeByName

public static int getTypeByName(java.lang.String typeName)
For a given type name (e.g., "Hanning window", or "BARTLETT"), return the type code. Matching is done as case-insensitive prefix matching.

Parameters:
typeName - the type name.
Returns:
the type code corresponding to typeName, or -1 if none could be determined.

getTypeName

public static java.lang.String getTypeName(int windowType)
Get the type name of a window type.

Parameters:
windowType - a valid window type
Returns:
a string representing the type name
Throws:
java.lang.IllegalArgumentException - if windowType is not a valid window type

normalize

public void normalize()

normalizePeakValue

public void normalizePeakValue(float desiredPeakValue)

normalize

public void normalize(float val)

normalizeSquaredSum

public void normalizeSquaredSum(float val)

normalizeRange

public void normalizeRange(float minVal,
                           float maxVal)

getCoeffs

public double[] getCoeffs()

getCoeffsLeftHalf

public double[] getCoeffsLeftHalf()

getCoeffsRightHalf

public double[] getCoeffsRightHalf()