public static void main(String[] args) throws Exception {
    SoftSynthesizer synth = new SoftSynthesizer();
    synth.openStream(new AudioFormat(44100, 16, 1, true, false), null);

    SoftAudioBuffer in1 = new SoftAudioBuffer(250, synth.getFormat());
    SoftAudioBuffer out1 = new SoftAudioBuffer(250, synth.getFormat());

    float[] testdata1 = new float[in1.getSize()];
    float[] n1a = in1.array();
    float[] out1a = out1.array();
    for (int i = 0; i < n1a.length; i++) {
      testdata1[i] = (float) Math.sin(i * 0.3) * 0.9f;
      n1a[i] = testdata1[i];
      out1a[i] = 1;
    }

    SoftLimiter limiter = new SoftLimiter();
    limiter.init(44100, 147);
    limiter.setMixMode(false);
    limiter.setInput(0, in1);
    limiter.setOutput(0, out1);
    limiter.processControlLogic();
    limiter.processAudio();
    limiter.processControlLogic();
    limiter.processAudio();
    // Limiter should delay audio by one buffer,
    // and there should almost no different in output v.s. input
    for (int i = 0; i < n1a.length; i++) {
      if (Math.abs(out1a[i] - testdata1[i]) > 0.00001) throw new Exception("input != output");
    }

    synth.close();
  }
 protected void mixAudioStream(
     SoftAudioBuffer in, SoftAudioBuffer out, float amp_from, float amp_to) {
   int bufferlen = in.getSize();
   if (amp_from < 0.000000001 && amp_to < 0.000000001) return;
   if (amp_from == amp_to) {
     float[] fout = out.array();
     float[] fin = in.array();
     for (int i = 0; i < bufferlen; i++) fout[i] += fin[i] * amp_to;
   } else {
     float amp = amp_from;
     float amp_delta = (amp_to - amp_from) / bufferlen;
     float[] fout = out.array();
     float[] fin = in.array();
     for (int i = 0; i < bufferlen; i++) {
       amp += amp_delta;
       fout[i] += fin[i] * amp;
     }
   }
 }