public static AudioInputStream convertSampleRate(AudioInputStream in, float sampleRate) throws IllegalArgumentException
  {
      AudioInputStream converted;
      AudioFormat sourceFormat, targetFormat;

      //check for not null
      if(in == null)
        throw new IllegalArgumentException("the inputstream must not be null values");

      //check sample rate
      if(sampleRate < 0 || sampleRate > in.getFormat().getSampleRate())
        throw new IllegalArgumentException("the sample rate to convert to must be greater null and less or equal the sample rate of the input stream");

      converted = in;

      sourceFormat = in.getFormat();
      targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                                   sampleRate,
                                   sourceFormat.getSampleSizeInBits(),
                                   sourceFormat.getChannels(),
                                   sourceFormat.getFrameSize(),
                                   sampleRate,
                                   false);

      if (sourceFormat.getSampleRate() != targetFormat.getSampleRate())
      {
        if (AudioSystem.isConversionSupported(targetFormat, sourceFormat))
          converted = AudioSystem.getAudioInputStream(targetFormat, in);
        else
          throw new IllegalArgumentException("Conversion to specified sample rate not supported.");
      }
      return converted;
  }