Class MixingFloatAudioInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class MixingFloatAudioInputStream
    extends javax.sound.sampled.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 Summary

      Constructors 
      Constructor Description
      MixingFloatAudioInputStream​(javax.sound.sampled.AudioFormat audioFormat, javax.sound.sampled.AudioInputStream original, javax.sound.sampled.AudioInputStream background, float backgroundAttenuationFactor)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      The minimum of available() of all input stream is calculated and returned.
      void close()  
      static float decibel2linear​(float decibels)  
      long getFrameLength()
      The maximum of the frame length of the input stream is calculated and returned.
      void mark​(int nReadLimit)
      Calls mark() on all input streams.
      boolean markSupported()
      returns true if all input stream return true for markSupported().
      int read()  
      int read​(byte[] abData, int nOffset, int nLength)  
      void reset()
      Calls reset() on all input streams.
      long skip​(long lLength)
      calls skip() on all input streams.
      • Methods inherited from class javax.sound.sampled.AudioInputStream

        getFormat, read
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MixingFloatAudioInputStream

        public MixingFloatAudioInputStream​(javax.sound.sampled.AudioFormat audioFormat,
                                           javax.sound.sampled.AudioInputStream original,
                                           javax.sound.sampled.AudioInputStream background,
                                           float backgroundAttenuationFactor)
        Parameters:
        audioFormat - the audio Format
        original - the original
        background - the background
        backgroundAttenuationFactor - the backgroundAttenuationFactor
    • Method Detail

      • 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 javax.sound.sampled.AudioInputStream
        Returns:
        the frame length
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class javax.sound.sampled.AudioInputStream
        Returns:
        the byte read
        Throws:
        java.io.IOException - the IOException
      • read

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

        public long skip​(long lLength)
                  throws java.io.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 javax.sound.sampled.AudioInputStream
        Parameters:
        lLength - the length
        Returns:
        the length
        Throws:
        java.io.IOException - the IOException
      • available

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

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class javax.sound.sampled.AudioInputStream
        Throws:
        java.io.IOException - the IOException
      • mark

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

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

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

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