Class WavInputStream

java.lang.Object
de.pottgames.tuningfork.decoder.WavInputStream
All Implemented Interfaces:
AudioStream, Closeable, AutoCloseable

public class WavInputStream extends Object implements AudioStream
An AudioStream implementation to read wav files.
  • Constructor Details

    • WavInputStream

      public WavInputStream(com.badlogic.gdx.files.FileHandle file)
      Initializes a WavInputStream from a FileHandle.
      Parameters:
      file - the file handle
    • WavInputStream

      public WavInputStream(com.badlogic.gdx.files.FileHandle file, boolean forStreaming)
      Initializes a WavInputStream from a FileHandle.
      Parameters:
      file - the file handle
      forStreaming - true if this will be used for streaming
    • WavInputStream

      public WavInputStream(InputStream stream)
      Initializes a WavInputStream from an InputStream. This stream does not support the reset function. Use WavInputStream(FileHandle) instead to get the full functionality.
      Parameters:
      stream - the input stream
    • WavInputStream

      public WavInputStream(InputStream stream, boolean forStreaming)
      Initializes a WavInputStream from an InputStream. This stream does not support the reset function. Use WavInputStream(FileHandle) instead to get the full functionality.
      Parameters:
      stream - the input stream
      forStreaming - true if this will be used for streaming
  • Method Details

    • read

      public int read(byte[] bytes)
      Description copied from interface: AudioStream
      Reads bytes from the stream until the given array is full or the stream ends. Returns the number of bytes that were actually read.
      Specified by:
      read in interface AudioStream
      Parameters:
      bytes - the byte array to store the bytes in
      Returns:
      number of bytes read or -1 if there are no bytes left
    • getDuration

      public float getDuration()
      Description copied from interface: AudioStream
      Returns the duration in seconds or -1 if this information is not available.
      Specified by:
      getDuration in interface AudioStream
      Returns:
      duration in seconds or -1 if the information is not available
    • reset

      public AudioStream reset()
      Description copied from interface: AudioStream
      Resets the audio stream as if it was re-opened. Implementations are free to close themselves and provide a new AudioStream. The AudioStream returned by this function will be used, regardless of whether it is a new instance or the old one.
      Specified by:
      reset in interface AudioStream
      Returns:
      an AudioStream
    • totalSamplesPerChannel

      public long totalSamplesPerChannel()
    • getChannels

      public int getChannels()
      Description copied from interface: AudioStream
      Returns the number of audio channels.
      Specified by:
      getChannels in interface AudioStream
      Returns:
      number of channels
    • getSampleRate

      public int getSampleRate()
      Description copied from interface: AudioStream
      Returns the sample rate.
      Specified by:
      getSampleRate in interface AudioStream
      Returns:
      the sample rate
    • getBitsPerSample

      public int getBitsPerSample()
      Description copied from interface: AudioStream
      Returns the number of bits per sample, also known as the sample depth.
      Specified by:
      getBitsPerSample in interface AudioStream
      Returns:
      the number of bits per sample
    • getPcmDataType

      public PcmFormat.PcmDataType getPcmDataType()
      Description copied from interface: AudioStream
      Returns the output data format of this AudioStream.
      Specified by:
      getPcmDataType in interface AudioStream
      Returns:
      the pcm data type
    • getBlockAlign

      public int getBlockAlign()
      Description copied from interface: AudioStream
      Returns the block alignment in sample frames. This only applies for data that is organized in blocks like ADPCM, all other implementations should return -1.
      Specified by:
      getBlockAlign in interface AudioStream
      Returns:
      the block size in sample frames
    • getBlockSize

      public int getBlockSize()
      Description copied from interface: AudioStream
      Returns the block size in bytes. This only applies for data that is organized in blocks like ADPCM, all other implementations should return -1.
      Specified by:
      getBlockSize in interface AudioStream
      Returns:
      block size in bytes
    • bytesRemaining

      public long bytesRemaining()
    • isClosed

      public boolean isClosed()
      Description copied from interface: AudioStream
      Returns true if the AudioStream is closed.
      Specified by:
      isClosed in interface AudioStream
      Returns:
      true if closed, false if open
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException