Class AudioStream

All Implemented Interfaces:
Closeable, AutoCloseable, Cloneable

public class AudioStream extends AudioData implements Closeable
AudioStream is an implementation of AudioData that acquires the audio from an InputStream. Audio can be streamed from network, hard drive etc. It is assumed the data coming from the input stream is uncompressed.
  • Field Details

    • in

      protected InputStream in
    • duration

      protected float duration
    • open

      protected boolean open
    • eof

      protected boolean eof
    • ids

      protected int[] ids
    • unqueuedBuffersBytes

      protected int unqueuedBuffersBytes
  • Constructor Details

    • AudioStream

      public AudioStream()
    • AudioStream

      protected AudioStream(int[] ids)
  • Method Details

    • updateData

      public void updateData(InputStream in, float duration)
    • readSamples

      public int readSamples(byte[] buf, int offset, int length)
      Reads samples from the stream. The format of the data depends on the getSampleRate(), getChannels(), getBitsPerSample() values.
      Parameters:
      buf - Buffer where to read the samples
      offset - The offset in the buffer where to read samples
      length - The length inside the buffer where to read samples
      Returns:
      number of bytes read.
    • readSamples

      public int readSamples(byte[] buf)
      Reads samples from the stream.
      Parameters:
      buf - Buffer where to read the samples
      Returns:
      number of bytes read.
      See Also:
    • getDuration

      public float getDuration()
      Specified by:
      getDuration in class AudioData
      Returns:
      the duration in seconds of the audio clip.
    • getId

      public int getId()
      Overrides:
      getId in class NativeObject
      Returns:
      The ID of the object. Should not be used by user code in most cases.
    • setId

      public void setId(int id)
      Description copied from class: NativeObject
      Sets the ID of the NativeObject. This method is used in Renderer and must not be called by the user.
      Overrides:
      setId in class NativeObject
      Parameters:
      id - The ID to set
    • initIds

      public void initIds(int count)
    • getId

      public int getId(int index)
    • setId

      public void setId(int index, int id)
    • getIds

      public int[] getIds()
    • setIds

      public void setIds(int[] ids)
    • getDataType

      public AudioData.DataType getDataType()
      Specified by:
      getDataType in class AudioData
      Returns:
      The data type, either Buffer or Stream.
    • resetObject

      public void resetObject()
      Description copied from class: NativeObject
      Called when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.
      Specified by:
      resetObject in class NativeObject
    • deleteObject

      public void deleteObject(Object rendererObject)
      Description copied from class: NativeObject
      Deletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.
      Specified by:
      deleteObject in class NativeObject
      Parameters:
      rendererObject - The renderer to be used to delete the object
    • createDestructableClone

      public NativeObject createDestructableClone()
      Description copied from class: NativeObject
      Creates a shallow clone of this GL Object. The deleteObject method should be functional for this object.
      Specified by:
      createDestructableClone in class NativeObject
      Returns:
      a new instance
    • isEOF

      public boolean isEOF()
    • close

      public void close()
      Closes the stream, releasing all data relating to it. Reading from the stream will return eof.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isSeekable

      public boolean isSeekable()
    • getUnqueuedBufferBytes

      public int getUnqueuedBufferBytes()
    • setUnqueuedBufferBytes

      public void setUnqueuedBufferBytes(int unqueuedBuffers)
    • setTime

      public void setTime(float time)
    • getUniqueId

      public long getUniqueId()
      Description copied from class: NativeObject
      Returns a unique ID for this NativeObject. No other NativeObject shall have the same ID.
      Specified by:
      getUniqueId in class NativeObject
      Returns:
      unique ID for this NativeObject.