Class BufferedSoundSource
java.lang.Object
de.pottgames.tuningfork.SoundSource
de.pottgames.tuningfork.jukebox.song.SongSource
de.pottgames.tuningfork.BufferedSoundSource
A sound source that is backed by a single buffer.
-
Field Summary
Fields inherited from class SoundSource
sourceId -
Method Summary
Modifier and TypeMethodDescriptionattachEffect(SoundEffect effect) Attaches a sound effect to this sound source.voidDetaches all currently attached sound effects from this sound source.booleandetachEffect(SoundEffect effect) Detaches the given SoundEffect from this sound source.voidDisables the distance attenuation of this sound source.voidEnables the distance attenuation of this sound source.voidfree()Releases this sound source which makes it available again.Returns the SoundBuffer that this source is currently using.floatReturns the duration of the attached sound in seconds.floatReturns the current playback position in seconds.voidmakeDirectional(com.badlogic.gdx.math.Vector3 direction, float coneInnerAngle, float coneOuterAngle, float outOfConeVolume) Makes this sound source emit sound in a cone shape facing a direction.voidMakes this sound source omni-directional.voidpause()Pauses the sound playback.voidplay()Starts the playback of this sound source.voidplayAtTime(long time) Plays the sound at the specified time.voidsetAttenuationFactor(float rolloff) This factor determines how slowly or how quickly the sound source loses volume as the listener moves away from the source.voidsetAttenuationMaxDistance(float maxDistance) Sets the distance the listener must be from the sound source at which the attenuation should stop.voidsetAttenuationMinDistance(float minDistance) Sets the distance the listener must be from the sound source at which the attenuation should begin.voidsetDirection(com.badlogic.gdx.math.Vector3 direction) Sets the direction of this sound source.voidsetLooping(boolean looping) Sets wether this sound source should loop.voidsetPitch(float pitch) Sets the pitch of this sound source.voidsetPlaybackPosition(float seconds) Sets the playback position of this sound source.voidsetPosition(float x, float y, float z) Sets the positions of this sound source in the virtual world.voidsetRelative(boolean relative) Sets whether the position attribute of this sound source should be handled as relative or absolute values to the listener's position.
If set to false, the position is the absolute position in the 3D world.
If set to true, the position is relative to the listener's position, meaning a position of x=0,y=0,z=0 is always identical to the listener's position.voidsetSpeed(float x, float y, float z) Sets the speed of this sound source.voidsetVolume(float volume) Sets the base volume of this sound source.voidstop()Stops the sound playback and rewinds it.Methods inherited from class SoundSource
attachEffect, dispose, getAttenuationFactor, getAttenuationMaxDistance, getAttenuationMinDistance, getPitch, getPosition, getRadius, getResampler, getSpatialization, getVirtualization, getVolume, hasFilter, isDirectional, isPaused, isPlaying, isRelative, setFilter, setPosition, setRadius, setResampler, setResamplerByIndex, setSpatialization, setSpeed, setVirtualization
-
Method Details
-
setVolume
public void setVolume(float volume) Description copied from class:SoundSourceSets the base volume of this sound source. The final output volume might differ depending on the source's position, listener position etc.- Overrides:
setVolumein classSoundSource- Parameters:
volume- in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume. (default 1)
-
setPitch
public void setPitch(float pitch) Description copied from class:SoundSourceSets the pitch of this sound source.- Overrides:
setPitchin classSoundSource- Parameters:
pitch- The pitch value, which must be >= 0. Values less than 1 result in slower playback and a deeper tone, while values > 1 make it faster and produce a higher tone.
-
play
public void play()Description copied from class:SoundSourceStarts the playback of this sound source.- Overrides:
playin classSoundSource
-
playAtTime
public void playAtTime(long time) Plays the sound at the specified time. Negative values for time will result in an error log entry but do nothing else. Positive values that point to the past will make the source play immediately. The source will be in playing-state while waiting for the start time to be reached. A call toplay()will not play the sound immediately anymore. In order to delete the play-at-time, callstop().- Parameters:
time- the time in nanoseconds, useAudioDevice.getClockTime()to get the current time
-
setRelative
public void setRelative(boolean relative) Description copied from class:SoundSourceSets whether the position attribute of this sound source should be handled as relative or absolute values to the listener's position.
If set to false, the position is the absolute position in the 3D world.
If set to true, the position is relative to the listener's position, meaning a position of x=0,y=0,z=0 is always identical to the listener's position.- Overrides:
setRelativein classSoundSource- Parameters:
relative- true = relative, false = absolute
-
setPosition
public void setPosition(float x, float y, float z) Description copied from class:SoundSourceSets the positions of this sound source in the virtual world.- Overrides:
setPositionin classSoundSource- Parameters:
x- xy- yz- z
-
enableAttenuation
public void enableAttenuation()Description copied from class:SoundSourceEnables the distance attenuation of this sound source.- Overrides:
enableAttenuationin classSoundSource
-
disableAttenuation
public void disableAttenuation()Description copied from class:SoundSourceDisables the distance attenuation of this sound source.- Overrides:
disableAttenuationin classSoundSource
-
setAttenuationFactor
public void setAttenuationFactor(float rolloff) Description copied from class:SoundSourceThis factor determines how slowly or how quickly the sound source loses volume as the listener moves away from the source. A factor of 0.5 reduces the volume loss by half. With a factor of 2, the source loses volume twice as fast.- Overrides:
setAttenuationFactorin classSoundSource- Parameters:
rolloff- (default depends on the attenuation model)
-
setAttenuationMinDistance
public void setAttenuationMinDistance(float minDistance) Description copied from class:SoundSourceSets the distance the listener must be from the sound source at which the attenuation should begin. The attenuation itself is controlled by the attenuation model and the attenuation factor of the source.- Overrides:
setAttenuationMinDistancein classSoundSource- Parameters:
minDistance- (default depends on the attenuation model)
-
setAttenuationMaxDistance
public void setAttenuationMaxDistance(float maxDistance) Description copied from class:SoundSourceSets the distance the listener must be from the sound source at which the attenuation should stop. The attenuation itself is controlled by the attenuation model and the attenuation factor of the source.- Overrides:
setAttenuationMaxDistancein classSoundSource- Parameters:
maxDistance- (default depends on the attenuation model)
-
makeDirectional
public void makeDirectional(com.badlogic.gdx.math.Vector3 direction, float coneInnerAngle, float coneOuterAngle, float outOfConeVolume) Description copied from class:SoundSourceMakes this sound source emit sound in a cone shape facing a direction. Inside the inner cone angle, the listener hears the sound at full volume. Outside the outer cone angle the sound is even on the level specified by outOfConeVolume. The volume is faded in between both angles (inside the cone). CallSoundSource.makeOmniDirectional()to make the source non-directional again.- Overrides:
makeDirectionalin classSoundSource- Parameters:
direction- the direction the source is facingconeInnerAngle- the inner cone angleconeOuterAngle- the outer cone angleoutOfConeVolume- the volume of the sound source when outside of the cone
-
setDirection
public void setDirection(com.badlogic.gdx.math.Vector3 direction) Description copied from class:SoundSourceSets the direction of this sound source. You need to callSoundSource.makeDirectional(Vector3, float, float, float)first, otherwise the direction will be ignored.- Overrides:
setDirectionin classSoundSource- Parameters:
direction- the direction
-
makeOmniDirectional
public void makeOmniDirectional()Description copied from class:SoundSourceMakes this sound source omni-directional. This is the default, so you only need to call it if you have made the source directional earlier.- Overrides:
makeOmniDirectionalin classSoundSource
-
setSpeed
public void setSpeed(float x, float y, float z) Description copied from class:SoundSourceSets the speed of this sound source. The speed is not automatically determined by changes to the position, you need to call setSpeed manually.
The speed is only used for calculating a Doppler effect. Note that you need to call set speed on the sound listener as well in order to get a proper Doppler effect.- Overrides:
setSpeedin classSoundSource- Parameters:
x- the speed on the x-axisy- the speed on the y-axisz- the speed on the z-axis
-
setLooping
public void setLooping(boolean looping) Description copied from class:SoundSourceSets wether this sound source should loop. When looping is enabled, the source will immediately play the sound again when it's finished playing.- Overrides:
setLoopingin classSoundSource- Parameters:
looping- true for looped playback
-
pause
public void pause()Description copied from class:SoundSourcePauses the sound playback.- Overrides:
pausein classSoundSource
-
stop
public void stop()Description copied from class:SoundSourceStops the sound playback and rewinds it.- Overrides:
stopin classSoundSource
-
getDuration
public float getDuration()Returns the duration of the attached sound in seconds.- Specified by:
getDurationin classSongSource- Returns:
- the duration of the attached sound.
Returns -1f if no buffer is attached or the duration couldn't be measured.
-
setPlaybackPosition
public void setPlaybackPosition(float seconds) Sets the playback position of this sound source. Invalid values are ignored but an error is logged.- Parameters:
seconds- the position in seconds
-
getPlaybackPosition
public float getPlaybackPosition()Returns the current playback position in seconds.- Specified by:
getPlaybackPositionin classSongSource- Returns:
- the playback position
-
attachEffect
Description copied from class:SoundSourceAttaches a sound effect to this sound source. If you attach more effects than effect slots are available, the oldest attached effect will be kicked out. Attaching an effect that is already attached to this source is a legal NOP.
AudioDeviceConfig.setEffectSlots(int)to change the number of available effect slots.
CallAudioDevice.getNumberOfEffectSlots()to retrieve the number of available effect slots.- Overrides:
attachEffectin classSoundSource- Parameters:
effect- the sound effect- Returns:
- the effect that was kicked out or null otherwise
-
detachEffect
Description copied from class:SoundSourceDetaches the given SoundEffect from this sound source.- Overrides:
detachEffectin classSoundSource- Parameters:
effect- the effect- Returns:
- true if the effect was successfully detached, false if the effect isn't attached to this source (anymore)
-
detachAllEffects
public void detachAllEffects()Description copied from class:SoundSourceDetaches all currently attached sound effects from this sound source.- Overrides:
detachAllEffectsin classSoundSource
-
getBuffer
Returns the SoundBuffer that this source is currently using.- Returns:
- the buffer
-
free
public void free()Releases this sound source which makes it available again. Always call this after you're done using it.
-