public class Convolver extends java.lang.Object implements AudioEffect
Convolver
is an effect that convolves a signal with a kernal.
The kernal can be thought of as the impulse response of an audio filter, or
simply as a set of weighting coefficients. Convolver
performs
brute-force convolution, meaning that it is slow, relatively speaking.
However, the algorithm is very straighforward. Each output sample
i
is calculated by multiplying each kernal value
j
with the input sample i - j
and then summing
the resulting values. The output will be
kernal.length + signal.length - 1
samples long, so the extra
samples are stored in an overlap array. The overlap array from the previous
signal convolution is added into the beginning of the output array, which
results in a output signal without pops.Modifier and Type | Field and Description |
---|---|
protected float[] |
kernal |
protected float[] |
outputL |
protected float[] |
outputR |
protected float[] |
overlapL |
protected float[] |
overlapR |
protected int |
sigLen |
Constructor and Description |
---|
Convolver(float[] k,
int sigLength)
Constructs a Convolver with the kernal
k that expects buffer
of length sigLength . |
Modifier and Type | Method and Description |
---|---|
void |
process(float[] signal)
Processes
signal in some way. |
void |
process(float[] sigLeft,
float[] sigRight)
Processes
sigLeft and sigRight in some way. |
void |
setKernal(float[] k)
Sets the kernal to
k . |
protected float[] kernal
protected float[] outputL
protected float[] overlapL
protected float[] outputR
protected float[] overlapR
protected int sigLen
public Convolver(float[] k, int sigLength)
k
that expects buffer
of length sigLength
.k
- the kernal of the filtersigLength
- the length of the buffer that will be convolved with the kernalpublic void setKernal(float[] k)
k
. The values in k
are
copied so it is not possible to alter the kernal after it has been set
except by setting it again.k
- the kernal to usepublic void process(float[] signal)
AudioEffect
signal
in some way.process
in interface AudioEffect
signal
- an array of audio samples, representing a mono sound stream.public void process(float[] sigLeft, float[] sigRight)
AudioEffect
sigLeft
and sigRight
in some way.process
in interface AudioEffect
sigLeft
- an array of audio samples, representing the left channel of a
stereo sound streamsigRight
- an array of audio samples, representing the right channel of a
stereo sound stream