toxi.audio
Class AudioSource

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

public class AudioSource
extends toxi.geom.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.


Nested Class Summary
 
Nested classes/interfaces inherited from class toxi.geom.Vec3D
toxi.geom.Vec3D.Axis
 
Field Summary
 
Fields inherited from class toxi.geom.Vec3D
MAX_VALUE, MIN_VALUE, x, X_AXIS, y, Y_AXIS, z, Z_AXIS, ZERO
 
Constructor Summary
AudioSource(net.java.games.joal.AL al, int id)
           
AudioSource(net.java.games.joal.AL al, int id, AudioBuffer buf)
           
 
Method Summary
 boolean delete()
          Deletes this source, and free its resources.
 AudioBuffer getBuffer()
          Gets the buffer associated with this source.
 int getBuffersProcessed()
          Gets the number of buffers already processed on this source.
 float[] getDirection()
           
 int getID()
           
 int getOffset()
           
 float[] getPosition()
           
 float[] getVelocity()
           
 boolean isLooping()
           
 int length()
           
 AudioSource play()
           
 AudioSource rewind()
           
 AudioSource setBuffer(AudioBuffer buffer)
          Sets the buffer associated with this source.
 AudioSource setDirection(float[] d)
           
 AudioSource setDirection(float xx, float yy, float zz)
           
 AudioSource setDirection(toxi.geom.Vec3D dir)
           
 AudioSource setGain(float gain)
           
 AudioSource setLooping(boolean state)
           
 AudioSource setOffset(int off)
           
 AudioSource setPitch(float pitch)
           
 AudioSource setPosition(float[] p)
           
 AudioSource setPosition(float xx, float yy, float zz)
           
 AudioSource setPosition(toxi.geom.Vec3D p)
           
 AudioSource setReferenceDistance(float d)
           
 AudioSource setVelocity(float[] v)
           
 AudioSource setVelocity(float xx, float yy, float zz)
           
 AudioSource setVelocity(toxi.geom.Vec3D p)
           
 AudioSource stop()
           
 java.lang.String toString()
           
 AudioSource updatePosition()
           
 
Methods inherited from class toxi.geom.Vec3D
abs, add, add, add, addSelf, addSelf, angleBetween, angleBetween, clear, compareTo, constrain, constrain, copy, cross, cross, crossInto, crossSelf, distanceTo, distanceToSquared, dot, dot, equals, equalsWithTolerance, floor, frac, fromXYTheta, fromXZTheta, fromYZTheta, getAbs, getComponent, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getNormalized, getNormalizedTo, getReciprocal, getReflected, getRotatedAroundAxis, getRotatedX, getRotatedY, getRotatedZ, getSignum, hashCode, headingXY, headingXZ, headingYZ, immutable, interpolateTo, interpolateTo, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInAABB, isInAABB, isMajorAxis, isZeroVector, jitter, jitter, jitter, jitter, jitter, jitter, limit, magnitude, magSquared, max, maxSelf, min, minSelf, modSelf, modSelf, normalize, normalizeTo, randomVector, randomVector, reciprocal, reflect, rotateAroundAxis, rotateX, rotateY, rotateZ, roundToAxis, scale, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, set, set, set, setComponent, setComponent, setXY, shuffle, signum, sub, sub, sub, subSelf, subSelf, to2DXY, to2DXZ, to2DYZ, toArray, toArray4, toCartesian, toSpherical, x, y, z
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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 Detail

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(toxi.geom.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(toxi.geom.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(toxi.geom.Vec3D p)

stop

public AudioSource stop()

toString

public java.lang.String toString()
Overrides:
toString in class toxi.geom.Vec3D

updatePosition

public AudioSource updatePosition()