com.jme3.audio
Class AudioStream

java.lang.Object
  extended by com.jme3.util.NativeObject
      extended by com.jme3.audio.AudioData
          extended by com.jme3.audio.AudioStream
All Implemented Interfaces:
java.io.Closeable, java.lang.Cloneable

public class AudioStream
extends AudioData
implements java.io.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.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme3.audio.AudioData
AudioData.DataType
 
Field Summary
protected  float duration
           
protected  int[] ids
           
protected  java.io.InputStream in
           
protected  boolean open
           
 
Fields inherited from class com.jme3.audio.AudioData
bitsPerSample, channels, sampleRate
 
Fields inherited from class com.jme3.util.NativeObject
handleRef, id, type, updateNeeded
 
Constructor Summary
  AudioStream()
           
protected AudioStream(int[] ids)
           
 
Method Summary
 void close()
          Closes the stream, releasing all data relating to it.
 NativeObject createDestructableClone()
          Creates a shallow clone of this GL Object.
 void deleteObject(java.lang.Object rendererObject)
          Deletes the GL object from the GPU when it is no longer used.
 AudioData.DataType getDataType()
           
 float getDuration()
           
 int getId()
           
 int getId(int index)
           
 int[] getIds()
           
 void initIds(int count)
           
 boolean isOpen()
           
 int readSamples(byte[] buf)
          Reads samples from the stream.
 int readSamples(byte[] buf, int offset, int length)
          Reads samples from the stream.
 void resetObject()
          Called when the GL context is restarted to reset all IDs.
 void setId(int id)
          Sets the ID of the GLObject.
 void setId(int index, int id)
           
 void setIds(int[] ids)
           
 void setTime(float time)
           
 void updateData(java.io.InputStream in, float duration)
           
 
Methods inherited from class com.jme3.audio.AudioData
getBitsPerSample, getChannels, getSampleRate, setupFormat
 
Methods inherited from class com.jme3.util.NativeObject
clearUpdateNeeded, clone, isUpdateNeeded, setUpdateNeeded, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

in

protected java.io.InputStream in

duration

protected float duration

open

protected boolean open

ids

protected int[] ids
Constructor Detail

AudioStream

public AudioStream()

AudioStream

protected AudioStream(int[] ids)
Method Detail

updateData

public void updateData(java.io.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:
readSamples(byte[], int, int)

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 GLObject. 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(java.lang.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

isOpen

public boolean isOpen()
Returns:
Whether the stream is open or not. Reading from a closed stream will always return eof.

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 java.io.Closeable
Throws:
java.io.IOException

setTime

public void setTime(float time)