Class MixingFloatAudioInputStream

java.lang.Object
java.io.InputStream
javax.sound.sampled.AudioInputStream
fr.paris.lutece.plugins.captcha.modules.jcaptcha.service.sound.MixingFloatAudioInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class MixingFloatAudioInputStream extends AudioInputStream
Mixing of multiple AudioInputStreams to one AudioInputStream. This class takes a collection of AudioInputStreams and mixes them together. Being a subclass of AudioInputStream itself, reading from instances of this class behaves as if the mixdown result of the input streams is read.

This class uses the FloatSampleBuffer for easy conversion using normalized samples in the buffers.

  • Constructor Details

    • MixingFloatAudioInputStream

      public MixingFloatAudioInputStream(AudioFormat audioFormat, AudioInputStream original, AudioInputStream background, float backgroundAttenuationFactor)
      Parameters:
      audioFormat - the audio Format
      original - the original
      background - the background
      backgroundAttenuationFactor - the backgroundAttenuationFactor
  • Method Details

    • getFrameLength

      public long getFrameLength()
      The maximum of the frame length of the input stream is calculated and returned. If at least one of the input streams has length AudioInputStream.NOT_SPECIFIED, this value is returned.
      Overrides:
      getFrameLength in class AudioInputStream
      Returns:
      the frame length
    • read

      public int read() throws IOException
      Overrides:
      read in class AudioInputStream
      Returns:
      the byte read
      Throws:
      IOException - the IOException
    • read

      public int read(byte[] abData, int nOffset, int nLength) throws IOException
      Overrides:
      read in class AudioInputStream
      Parameters:
      abData - the Data
      nOffset - the Offset
      nLength - the Length
      Returns:
      the byte read
      Throws:
      IOException - the IOException
    • skip

      public long skip(long lLength) throws IOException
      calls skip() on all input streams. There is no way to assure that the number of bytes really skipped is the same for all input streams. Due to that, this method always returns the passed value. In other words: the return value is useless (better ideas appreciated).
      Overrides:
      skip in class AudioInputStream
      Parameters:
      lLength - the length
      Returns:
      the length
      Throws:
      IOException - the IOException
    • available

      public int available() throws IOException
      The minimum of available() of all input stream is calculated and returned.
      Overrides:
      available in class AudioInputStream
      Returns:
      the available
      Throws:
      IOException - the IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AudioInputStream
      Throws:
      IOException - the IOException
    • mark

      public void mark(int nReadLimit)
      Calls mark() on all input streams.
      Overrides:
      mark in class AudioInputStream
      Parameters:
      nReadLimit - the read limit
    • reset

      public void reset() throws IOException
      Calls reset() on all input streams.
      Overrides:
      reset in class AudioInputStream
      Throws:
      IOException - the IOException
    • markSupported

      public boolean markSupported()
      returns true if all input stream return true for markSupported().
      Overrides:
      markSupported in class AudioInputStream
      Returns:
      false if mark supported
    • decibel2linear

      public static float decibel2linear(float decibels)
      Parameters:
      decibels - the decibels
      Returns:
      the decibel linear