com.threerings.openal
Class ClipBuffer

java.lang.Object
  extended by com.threerings.openal.ClipBuffer

public class ClipBuffer
extends Object

Represents a sound that has been loaded into the OpenAL system.


Nested Class Summary
static interface ClipBuffer.Observer
          Used to notify parties interested in when a clip is loaded.
 
Field Summary
protected  int _bound
           
protected  Buffer _buffer
           
protected  SoundManager _manager
           
protected  ObserverList<ClipBuffer.Observer> _observers
           
protected  String _path
           
protected  ClipProvider _provider
           
protected  int _size
           
protected  int _state
           
protected static int LOADED
           
protected static int LOADING
           
protected static int UNLOADED
           
protected static int UNLOADING
           
 
Constructor Summary
ClipBuffer(SoundManager manager, ClipProvider provider, String path)
          Creates a new clip buffer with the specified path that will obtain its clip data from the specified source.
 
Method Summary
protected  boolean bind(Clip clip)
          This method is called back on the main thread and instructs this buffer to bind the clip data to this buffer's OpenAL buffer.
 void dispose()
          Frees up the internal audio buffers associated with this clip.
protected  void failed()
          Called when we fail in some part of the process in resolving our clip data.
 Buffer getBuffer()
          Returns a reference to this clip's buffer or null if it is not loaded.
 ClipProvider getClipProvider()
          Returns the provider used to load this clip.
 String getKey()
          Returns the unique key for this clip buffer.
 String getPath()
          Returns the path that identifies this sound clip.
 int getSize()
          Returns the size (in bytes) of this clip as reported by OpenAL.
 boolean isPlayable()
          Returns true if this buffer is loaded and ready to go.
protected  Clip load()
          This method is called by the background sound loading thread and actually loads the sound data from wherever it cometh.
static String makeKey(ClipProvider provider, String path)
          Create a key that uniquely identifies this combination of clip provider and path.
 void resolve(ClipBuffer.Observer observer)
          Instructs this buffer to resolve its underlying clip and be ready to be played ASAP.
protected  void sourceBound()
          Notifies the buffer that a source has been bound to it.
protected  void sourceUnbound()
          Notifies the buffer that a source has been unbound from it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_manager

protected SoundManager _manager

_provider

protected ClipProvider _provider

_path

protected String _path

_state

protected int _state

_buffer

protected Buffer _buffer

_size

protected int _size

_observers

protected ObserverList<ClipBuffer.Observer> _observers

_bound

protected int _bound

UNLOADED

protected static final int UNLOADED
See Also:
Constant Field Values

LOADING

protected static final int LOADING
See Also:
Constant Field Values

LOADED

protected static final int LOADED
See Also:
Constant Field Values

UNLOADING

protected static final int UNLOADING
See Also:
Constant Field Values
Constructor Detail

ClipBuffer

public ClipBuffer(SoundManager manager,
                  ClipProvider provider,
                  String path)
Creates a new clip buffer with the specified path that will obtain its clip data from the specified source. The clip will automatically queue itself up to be loaded into memory.

Method Detail

makeKey

public static String makeKey(ClipProvider provider,
                             String path)
Create a key that uniquely identifies this combination of clip provider and path.


getKey

public String getKey()
Returns the unique key for this clip buffer.


getClipProvider

public ClipProvider getClipProvider()
Returns the provider used to load this clip.


getPath

public String getPath()
Returns the path that identifies this sound clip.


isPlayable

public boolean isPlayable()
Returns true if this buffer is loaded and ready to go.


getBuffer

public Buffer getBuffer()
Returns a reference to this clip's buffer or null if it is not loaded.


getSize

public int getSize()
Returns the size (in bytes) of this clip as reported by OpenAL. This value will not be valid until the clip is bound.


resolve

public void resolve(ClipBuffer.Observer observer)
Instructs this buffer to resolve its underlying clip and be ready to be played ASAP.


dispose

public void dispose()
Frees up the internal audio buffers associated with this clip.


load

protected Clip load()
             throws IOException
This method is called by the background sound loading thread and actually loads the sound data from wherever it cometh.

Throws:
IOException

bind

protected boolean bind(Clip clip)
This method is called back on the main thread and instructs this buffer to bind the clip data to this buffer's OpenAL buffer.

Returns:
true if the binding succeeded, false if we were unable to load the sound data into OpenAL.

failed

protected void failed()
Called when we fail in some part of the process in resolving our clip data. Notifies our observers and resets the clip to the UNLOADED state.


sourceBound

protected void sourceBound()
Notifies the buffer that a source has been bound to it.


sourceUnbound

protected void sourceUnbound()
Notifies the buffer that a source has been unbound from it.