private static int[] generateSine(final int sampleCount,
                                    final int amplitude,
                                    final int periode)
  {
    if (sampleCount < 0) {
      return new int[0];
    }
    double phase = 0;
    double frequency;
    if (periode == 0) {
      frequency = 1.0;
    }
    else {
      frequency = 1.0 / ((double) periode);
    }
    double phaseIncrement = 2.0 * Math.PI * frequency;
    int[] signal = new int[sampleCount];
    for (int i=0; i<sampleCount; i++) {
      signal[i] = (int) (amplitude * Math.sin(phase));
      // check saturation
      if (signal[i] > 32767)
        signal[i] = 32767;
      if (signal[i] < -32768)
        signal[i] = -32768;
      phase += phaseIncrement;
    }
    return signal;
  }