public abstract class WindowFunction
extends java.lang.Object
Windowing
Windowing is the process of shaping the audio samples before transforming them to the frequency domain. The Fourier Transform assumes the sample buffer is is a repetitive signal, if a sample buffer is not truly periodic within the measured interval sharp discontinuities may arise that can introduce spectral leakage. Spectral leakage is the speading of signal energy across multiple FFT bins. This "spreading" can drown out narrow band signals and hinder detection.
A windowing function
attempts to reduce spectral leakage by attenuating the measured sample buffer
at its end points to eliminate discontinuities. If you call the window()
function with an appropriate WindowFunction, such as HammingWindow()
,
the sample buffers passed to the object for analysis will be shaped by the current
window before being transformed. The result of using a window is to reduce
the leakage in the spectrum somewhat.
WindowFunction
handles work associated with various window functions
such as the Hamming window. To create your own window function you must extend
WindowFunction
and implement the value
method which defines the shape of the window at a given offset.
WindowFunction
will call this method to apply the window to
a sample buffer. The number passed to the method is an offset within the length
of the window curve.
Modifier and Type | Field and Description |
---|---|
protected int |
length |
protected static float |
TWO_PI
The float value of 2*PI.
|
Constructor and Description |
---|
WindowFunction() |
Modifier and Type | Method and Description |
---|---|
void |
apply(float[] samples)
Apply the window function to a sample buffer.
|
void |
apply(float[] samples,
int offset,
int length)
Apply the window to a portion of this sample buffer,
given an offset from the beginning of the buffer
and the number of samples to be windowed.
|
float[] |
generateCurve(int length)
Generates the curve of the window function.
|
protected abstract float |
value(int length,
int index) |
protected static final float TWO_PI
protected int length
public void apply(float[] samples)
samples
- a sample bufferpublic void apply(float[] samples, int offset, int length)
public float[] generateCurve(int length)
length
- the length of the windowprotected abstract float value(int length, int index)