Package toxi.audio

Class AudioSource

java.lang.Object
toxi.geom.Vec3D
toxi.audio.AudioSource
All Implemented Interfaces:
Comparable<ReadonlyVec3D>, ReadonlyVec3D

public class AudioSource extends Vec3D
A wrapper for AudioBuffers and similar to the built in JOAL net.java.games.sound3d.Source, though less restrictive. The class extends Vec3D and so can be used to position the sound in 3D space (provided the underlying audio hardware does support 3D audio). Unfortunately due to OpenAL's limitations only mono samples can be positioned in that way. Stereo samples will can only manipulated in terms of gain/volume.

If the position of an AudioSource is changed via the public x,y,z vector components, the updatePosition() method needs to be called afterwards in order to reflect the changes in the OpenAL context.

  • Constructor Details

    • AudioSource

      public AudioSource(net.java.games.joal.AL al, int id)
    • AudioSource

      public AudioSource(net.java.games.joal.AL al, int id, AudioBuffer buf)
  • Method Details

    • delete

      public boolean delete()
      Deletes this source, and free its resources. Note, this method does NOT release the associated audio buffer. If you want to remove a source including its wave data use JOALUtil.deleteSource(AudioSource, boolean) instead.
      Returns:
      true, if source was removed successfully
    • getBuffer

      public AudioBuffer getBuffer()
      Gets the buffer associated with this source.
      Returns:
      the buffer associated with this source
    • getBuffersProcessed

      public int getBuffersProcessed()
      Gets the number of buffers already processed on this source.
      Returns:
      the number of buffers already processed on this source.
    • getDirection

      public final float[] getDirection()
    • getID

      public final int getID()
    • getOffset

      public final int getOffset()
    • getPosition

      public final float[] getPosition()
    • getVelocity

      public final float[] getVelocity()
    • isLooping

      public final boolean isLooping()
    • length

      public final int length()
    • play

      public AudioSource play()
    • rewind

      public AudioSource rewind()
    • setBuffer

      public AudioSource setBuffer(AudioBuffer buffer)
      Sets the buffer associated with this source.
      Parameters:
      buffer - the buffer associated with this source
    • setDirection

      public AudioSource setDirection(float xx, float yy, float zz)
    • setDirection

      public AudioSource setDirection(float[] d)
    • setDirection

      public AudioSource setDirection(Vec3D dir)
    • setGain

      public AudioSource setGain(float gain)
    • setLooping

      public AudioSource setLooping(boolean state)
    • setOffset

      public AudioSource setOffset(int off)
    • setPitch

      public AudioSource setPitch(float pitch)
    • setPosition

      public AudioSource setPosition(float xx, float yy, float zz)
    • setPosition

      public AudioSource setPosition(float[] p)
    • setPosition

      public AudioSource setPosition(Vec3D p)
    • setReferenceDistance

      public AudioSource setReferenceDistance(float d)
    • setVelocity

      public AudioSource setVelocity(float xx, float yy, float zz)
    • setVelocity

      public AudioSource setVelocity(float[] v)
    • setVelocity

      public AudioSource setVelocity(Vec3D p)
    • stop

      public AudioSource stop()
    • toString

      public String toString()
      Overrides:
      toString in class Vec3D
    • updatePosition

      public AudioSource updatePosition()