Class WaveShaperNode
java.lang.Object
com.codename1.media.audio.AudioNode
com.codename1.media.audio.WaveShaperNode
Applies a transfer curve to every sample, for distortion and saturation:
the Web Audio WaveShaperNode.
An input of -1 maps to the first curve entry and +1 to the last, linearly interpolated between and held past both ends. With no curve the node passes its input through.
OfflineAudioContext audio = new OfflineAudioContext(2, 44100, 44100);
float[] curve = new float[1024];
for (int i = 0; i < curve.length; i++) {
double x = i * 2.0 / (curve.length - 1) - 1;
curve[i] = (float) (x * 3 / (1 + Math.abs(x * 3))); // soft clip
}
WaveShaperNode drive = audio.createWaveShaper();
drive.setCurve(curve);
drive.setOversample(OverSampleType.FOUR_X);
-
Method Summary
Modifier and TypeMethodDescriptionfloat[]getCurve()The curve, or null when the node passes its input through.The oversampling applied with the curve.voidsetCurve(float[] curve) Sets the transfer curve.voidsetOversample(OverSampleType type) Sets the oversampling applied with the curve.Methods inherited from class AudioNode
connect, connect, connect, connect, disconnect, disconnect, disconnect, disconnect, disconnect, getChannelCount, getChannelCountMode, getChannelInterpretation, getContext, getNumberOfInputs, getNumberOfOutputs, setChannelCount, setChannelCountMode, setChannelInterpretation
-
Method Details
-
getCurve
public float[] getCurve()The curve, or null when the node passes its input through.
Returns
a copy of the curve or null
-
setCurve
public void setCurve(float[] curve) Sets the transfer curve. It is copied, so later changes to the array do not reach the node.
Parameters
curve: at least 2 values, or null to pass the input through
-
getOversample
The oversampling applied with the curve.
Returns
the oversampling
-
setOversample
Sets the oversampling applied with the curve.
Parameters
type: the oversampling
-