Class OALSource

java.lang.Object
com.blackrook.gloop.openal.OALObject
com.blackrook.gloop.openal.OALSource

public final class OALSource extends OALObject
Encapsulating class for OpenAL sources.
Author:
Matthew Tropiano
  • Field Details

  • Method Details

    • allocate

      protected final int allocate()
      Description copied from class: OALObject
      Allocates a new type of this object in OpenAL. Called by OALObject constructor.
      Specified by:
      allocate in class OALObject
      Returns:
      the ALId of this new object.
    • free

      protected final void free()
      Destroys this sound source (BUT NOT ATTACHED BUFFER(s)).
      Specified by:
      free in class OALObject
    • reset

      public void reset()
      Sets this Source's settings to defaults, and releases all buffers bound to it.
    • setEffectSlot

      public void setEffectSlot(int slot, OALEffectSlot eSlot)
      Sets an auxiliary effect in a particular slot (nullifies the filter slot).
      Parameters:
      slot - the slot to add this to.
      eSlot - the effect slot to add (can be null).
      Throws:
      ArrayIndexOutOfBoundsException - if slot is less than 0 or greater than the amount of effect slots.
    • setEffectSlotFilter

      public void setEffectSlotFilter(int slot, OALFilter filt)
      Sets a filter in a particular aux slot (nullifies the effect slot).
      Parameters:
      slot - the slot to add this to.
      filt - the filter to use on the output of this effect (can be null).
      Throws:
      ArrayIndexOutOfBoundsException - if slot is less than 0 or greater than the amount of effect slots.
    • setEffectSlot

      public void setEffectSlot(int slot, OALEffectSlot effectSlot, OALFilter wetFilter)
      Sets an auxiliary effect and filter in a particular slot.
      Parameters:
      slot - the slot to add this to.
      effectSlot - the effect slot to add (can be null).
      wetFilter - the filter to use on the output of this effect (can be null).
      Throws:
      ArrayIndexOutOfBoundsException - if slot is less than 0 or greater than the amount of effect slots.
    • setFilter

      public void setFilter(OALFilter dryFilter)
      Sets the "dry" filter to use for the dry signal for the effects later.
      Parameters:
      dryFilter - the filter to use (can be null).
    • setPosition

      public void setPosition(float x, float y, float z)
      Sets the Listener's position attributes.
      Parameters:
      x - the x-axis value.
      y - the y-axis value.
      z - the z-axis value.
    • setPosition

      public void setPosition(float[] f)
      Sets the Source's position attributes using an array of values. Values are copied.
      Parameters:
      f - the float array.
    • setVelocity

      public void setVelocity(float x, float y, float z)
      Sets the Source's velocity attributes.
      Parameters:
      x - the x-axis value.
      y - the y-axis value.
      z - the z-axis value.
    • setVelocity

      public void setVelocity(float[] f)
      Sets the Source's velocity attributes using an array of values. Values are copied.
      Parameters:
      f - the float array.
    • setDirection

      public void setDirection(float x, float y, float z)
      Sets the Source's direction attributes.
      Parameters:
      x - the x-axis value.
      y - the y-axis value.
      z - the z-axis value.
    • setDirection

      public void setDirection(float[] f)
      Sets the Source's direction attributes using an array of values. Values are copied.
      Parameters:
      f - the float array.
    • setGain

      public void setGain(float f)
      Sets the gain for this Source.
      Parameters:
      f - the new gain.
    • setMinGain

      public void setMinGain(float f)
      Sets the minimum gain for this Source. Used in gain attenuation by distance.
      Parameters:
      f - the new gain.
    • setMaxGain

      public void setMaxGain(float f)
      Sets the maximum gain for this Source. Used in gain attenuation by distance.
      Parameters:
      f - the new gain.
    • setPitch

      public void setPitch(float f)
      Sets the pitch for this Source.
      Parameters:
      f - the new pitch.
    • setPitchUsingSemitones

      public void setPitchUsingSemitones(int semitones)
      Sets the pitch by semitones. Setting this to 0 is equivalent to setting the pitch to 1. Every 12 semitones is one octave.
      Parameters:
      semitones - the amount of semitones of adjustment.
    • setPitchUsingCents

      public void setPitchUsingCents(int cents)
      Sets the pitch by cents. Setting this to 0 is equivalent to setting the pitch to 1. Every 1200 cents is one octave.
      Parameters:
      cents - the amount of cents of adjustment.
    • setRolloff

      public void setRolloff(float f)
      Sets the rolloff factor for this Source.
      Parameters:
      f - the new rolloff factor.
    • setOuterConeGain

      public void setOuterConeGain(float f)
      Sets the gain of this Source when the Listener lies outside of this Source's cone.
      Parameters:
      f - the gain value.
    • setOuterConeAngle

      public void setOuterConeAngle(float f)
      Sets the angle of this Source's outer cone. Sounds heard by the listener outside of this Source's conic projection are attenuated.
      Parameters:
      f - the angle in degrees.
    • setInnerConeAngle

      public void setInnerConeAngle(float f)
      Sets the angle of this Source's inner cone. Sounds heard by the listener inside of this Source's conic projection are not attenuated.
      Parameters:
      f - the angle in degrees.
    • setMaxDistance

      public void setMaxDistance(float f)
      Sets the maximum distance that Source attenuation can occur. The algorithm in determining this Source's final gain is dependent upon the current distance model.
      Parameters:
      f - the maximum distance in units.
    • setReferenceDistance

      public void setReferenceDistance(float f)
      Sets the minimum (reference) distance that Source attenuation can occur. The algorithm in determining this Source's final gain is dependent upon the current distance model.
      Parameters:
      f - the reference distance in units.
    • setLooping

      public void setLooping(boolean loop)
      Sets the looping attribute for this Source. Looping Sources loop the current queued buffer.
      Parameters:
      loop - true to set, false to clear.
    • setRelative

      public void setRelative(boolean rel)
      Sets the "relative to listener" attribute for this Source.
      Parameters:
      rel - true to set, false to clear.
    • isAutoVelocityOn

      public boolean isAutoVelocityOn()
      Checks if "auto velocity" is on.
      Returns:
      true of so, false if not.
    • getGain

      public float getGain()
      Returns:
      the gain scalar for this Source.
    • isLooping

      public boolean isLooping()
      Checks if this source loops the playing buffer.
      Returns:
      true of so, false if not.
    • getPitch

      public float getPitch()
      Gets the pitch factor for this Source.
      Returns:
      the pitch scalar.
    • isRelative

      public boolean isRelative()
      Checks if this source is relative to the listener.
      Returns:
      true if so, false if not.
    • getRolloff

      public float getRolloff()
      Returns:
      the rolloff factor
    • getMinGain

      public float getMinGain()
    • getMaxGain

      public float getMaxGain()
    • getReferenceDistance

      public float getReferenceDistance()
    • getMaxDistance

      public float getMaxDistance()
    • getInnerCone

      public float getInnerCone()
    • getOuterCone

      public float getOuterCone()
    • getOuterConeGain

      public float getOuterConeGain()
    • getFilter

      public OALFilter getFilter()
    • peekBuffer

      public OALBuffer peekBuffer()
      Returns:
      the foremost buffer in the buffer queue.
    • setBuffer

      public void setBuffer(OALBuffer b)
      Enqueues a single buffer on this Source, making sure that it is the only Buffer enqueued by it. If null is provided, this clears the buffer assignment. This does NOT check if the Source is currently playing before dequeuing the bound buffers.
      Parameters:
      b - the Buffer to bind to this Source.
    • dequeueBuffer

      public OALBuffer dequeueBuffer()
      Returns the buffer dequeued, or null if no Buffer is queued. Thread safe. This does NOT check if the Source is currently playing.
      Returns:
      the buffer dequeued.
    • enqueueBuffers

      public void enqueueBuffers(OALBuffer... buffers)
      Enqueues a bunch of buffers onto this source in the order specified.
      Parameters:
      buffers - the buffers to enqueue.
    • enqueueBuffer

      public void enqueueBuffer(OALBuffer b)
      Enqueues a buffer on this Source.
      Parameters:
      b - the buffer to enqueue.
    • getQueuedBufferCount

      public int getQueuedBufferCount()
      Gets how many buffers are queued up for this source.
      Returns:
      the amount of buffers queued.
    • getProcessedBufferCount

      public int getProcessedBufferCount()
      Gets many buffers were processed on this source. This is the amount of buffers that need to be dequeued, filled, and requeued.
      Returns:
      the amount of buffers processed.
    • addSourceListener

      public void addSourceListener(OALSourceListener listener)
      Adds a source listener to this Source.
      Parameters:
      listener - the SourceListener to add.
    • removeSourceListener

      public void removeSourceListener(OALSourceListener listener)
      Removes a source listener from this Source.
      Parameters:
      listener - the SourceListener to remove.
    • removeAllListeners

      public void removeAllListeners()
      Removes all source listeners from the Source.
    • waitForEnd

      public void waitForEnd()
      Makes the calling thread wait for this source to stop playing. Pausing this does not make the thread continue.
      See Also:
    • play

      public void play()
      Plays this source. This does nothing if this is not bound to a buffer.
    • playAndWait

      public void playAndWait()
      Plays this source and makes the calling thread wait until it ends. Pausing this does not make the thread continue.
      See Also:
    • pause

      public void pause()
      Pauses this source.
    • stop

      public void stop()
      Stops playing this source.
    • rewind

      public void rewind()
      Rewinds this source.
    • isPlaying

      public boolean isPlaying()
      Is this source playing?
      Returns:
      true if so, false if not.
    • isReady

      public boolean isReady()
      Is this source ready to play?
      Returns:
      true if so, false if not.
    • isStopped

      public boolean isStopped()
      Is this source stopped?
      Returns:
      true if so, false if not.
    • isPaused

      public boolean isPaused()
      Is this source paused?
      Returns:
      true if so, false if not.
    • isBoundToABuffer

      public boolean isBoundToABuffer()
      Is this Source bound to a Buffer object?
      Returns:
      true if so, false if not.
    • getState

      protected final int getState()
      Get this source's state. Returns an AL constant.
      Returns:
      one of AL_INITIAL, AL_PLAYING, AL_STOPPED, or AL_PAUSED.
    • setAutoVelocity

      public void setAutoVelocity(boolean autovel)
      Enables/Disables automatic velocity calculation.
      Parameters:
      autovel - should velocity automatically be calculated?
    • toString

      public String toString()
      Overrides:
      toString in class OALObject