Class WaveShaperNode

java.lang.Object
com.codename1.media.audio.AudioNode
com.codename1.media.audio.WaveShaperNode

public final class WaveShaperNode extends AudioNode

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 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

      public OverSampleType getOversample()

      The oversampling applied with the curve.

      Returns

      the oversampling

    • setOversample

      public void setOversample(OverSampleType type)

      Sets the oversampling applied with the curve.

      Parameters
      • type: the oversampling