com.threerings.openal
Class Stream

java.lang.Object
  extended by com.threerings.openal.Stream
Direct Known Subclasses:
URLStream

public abstract class Stream
extends Object

Represents a streaming source of sound data.


Nested Class Summary
protected static class Stream.FadeMode
          Fading modes.
 
Field Summary
protected  ByteBuffer _abuf
          The buffer used to store audio data temporarily.
protected  Buffer[] _buffers
          The buffers through which we cycle.
protected  float _fadeElapsed
          The interval and elapsed time for fading.
protected  float _fadeInterval
          The interval and elapsed time for fading.
protected  Stream.FadeMode _fadeMode
          The type of fading being performed.
protected  float _gain
          The gain of the stream.
protected  IntBuffer _nbuf
          The buffer used to store names.
protected  int _qidx
          The starting index and length of the current queue in _buffers.
protected  int _qlen
          The starting index and length of the current queue in _buffers.
protected  SoundManager _soundmgr
          The manager to which the stream was added.
protected  Source _source
          The source through which the stream plays.
protected  int _state
          The OpenAL state of the stream.
 
Constructor Summary
Stream(SoundManager soundmgr)
          Creates a new stream.
 
Method Summary
 void dispose()
          Releases the resources held by this stream and removes it from the manager.
 void fadeIn(float interval)
          Fades this stream in over the specified interval.
 void fadeOut(float interval, boolean dispose)
          Fades this stream out over the specified interval.
protected  int getBufferSize()
          Returns the size in bytes of the buffers to use.
protected abstract  int getFormat()
          Returns the OpenAL audio format of the stream.
protected abstract  int getFrequency()
          Returns the stream's playback frequency in samples per second.
protected  int getNumBuffers()
          Returns the number of buffers to use.
 Source getSource()
          Returns a reference to the stream source.
 boolean isPlaying()
          Determines whether this stream is currently playing.
 void pause()
          Pauses this stream.
 void play()
          Starts playing this stream.
protected  boolean populateBuffer(Buffer buffer)
          Populates the identified buffer with as much data as it can hold.
protected abstract  int populateBuffer(ByteBuffer buf)
          Populates the given buffer with audio data.
protected  void queueBuffers(int buffers)
          Queues (up to) the specified number of buffers.
 void setGain(float gain)
          Sets the base gain of the stream.
 void stop()
          Stops this stream.
protected  void update(float time)
          Updates the state of this stream, loading data into buffers and adjusting gain as necessary.
protected  void updateFade(float time)
          Updates the gain of the stream according to the fade state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_soundmgr

protected SoundManager _soundmgr
The manager to which the stream was added.


_source

protected Source _source
The source through which the stream plays.


_buffers

protected Buffer[] _buffers
The buffers through which we cycle.


_qidx

protected int _qidx
The starting index and length of the current queue in _buffers.


_qlen

protected int _qlen
The starting index and length of the current queue in _buffers.


_gain

protected float _gain
The gain of the stream.


_fadeInterval

protected float _fadeInterval
The interval and elapsed time for fading.


_fadeElapsed

protected float _fadeElapsed
The interval and elapsed time for fading.


_fadeMode

protected Stream.FadeMode _fadeMode
The type of fading being performed.


_nbuf

protected IntBuffer _nbuf
The buffer used to store names.


_abuf

protected ByteBuffer _abuf
The buffer used to store audio data temporarily.


_state

protected int _state
The OpenAL state of the stream.

Constructor Detail

Stream

public Stream(SoundManager soundmgr)
Creates a new stream. Call dispose() when finished with the stream.

Parameters:
soundmgr - a reference to the sound manager that will update the stream
Method Detail

setGain

public void setGain(float gain)
Sets the base gain of the stream.


getSource

public Source getSource()
Returns a reference to the stream source.


isPlaying

public boolean isPlaying()
Determines whether this stream is currently playing.


play

public void play()
Starts playing this stream.


pause

public void pause()
Pauses this stream.


stop

public void stop()
Stops this stream.


fadeIn

public void fadeIn(float interval)
Fades this stream in over the specified interval. If the stream isn't playing, it will be started.


fadeOut

public void fadeOut(float interval,
                    boolean dispose)
Fades this stream out over the specified interval.

Parameters:
dispose - if true, dispose of the stream when done fading out

dispose

public void dispose()
Releases the resources held by this stream and removes it from the manager.


update

protected void update(float time)
Updates the state of this stream, loading data into buffers and adjusting gain as necessary. Called periodically by the SoundManager.

Parameters:
time - the amount of time elapsed since the last update

updateFade

protected void updateFade(float time)
Updates the gain of the stream according to the fade state.


queueBuffers

protected void queueBuffers(int buffers)
Queues (up to) the specified number of buffers.


populateBuffer

protected boolean populateBuffer(Buffer buffer)
Populates the identified buffer with as much data as it can hold.

Returns:
true if data was read into the buffer and it should be enqueued, false if the end of the stream has been reached and no data was read into the buffer

getFormat

protected abstract int getFormat()
Returns the OpenAL audio format of the stream.


getFrequency

protected abstract int getFrequency()
Returns the stream's playback frequency in samples per second.


populateBuffer

protected abstract int populateBuffer(ByteBuffer buf)
                               throws IOException
Populates the given buffer with audio data.

Returns:
the total number of bytes read into the buffer, or -1 if the end of the stream has been reached
Throws:
IOException

getBufferSize

protected int getBufferSize()
Returns the size in bytes of the buffers to use.


getNumBuffers

protected int getNumBuffers()
Returns the number of buffers to use.