Class BufferedSoundSource


public class BufferedSoundSource extends SongSource
A sound source that is backed by a single buffer.
  • Method Details

    • setVolume

      public void setVolume(float volume)
      Description copied from class: SoundSource
      Sets the base volume of this sound source. The final output volume might differ depending on the source's position, listener position etc.
      Overrides:
      setVolume in class SoundSource
      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: SoundSource
      Sets the pitch of this sound source.
      Overrides:
      setPitch in class SoundSource
      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: SoundSource
      Starts the playback of this sound source.
      Overrides:
      play in class SoundSource
    • 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 to play() will not play the sound immediately anymore. In order to delete the play-at-time, call stop().
      Parameters:
      time - the time in nanoseconds, use AudioDevice.getClockTime() to get the current time
    • setRelative

      public void setRelative(boolean relative)
      Description copied from class: SoundSource
      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.
      Overrides:
      setRelative in class SoundSource
      Parameters:
      relative - true = relative, false = absolute
    • setPosition

      public void setPosition(float x, float y, float z)
      Description copied from class: SoundSource
      Sets the positions of this sound source in the virtual world.
      Overrides:
      setPosition in class SoundSource
      Parameters:
      x - x
      y - y
      z - z
    • enableAttenuation

      public void enableAttenuation()
      Description copied from class: SoundSource
      Enables the distance attenuation of this sound source.
      Overrides:
      enableAttenuation in class SoundSource
    • disableAttenuation

      public void disableAttenuation()
      Description copied from class: SoundSource
      Disables the distance attenuation of this sound source.
      Overrides:
      disableAttenuation in class SoundSource
    • setAttenuationFactor

      public void setAttenuationFactor(float rolloff)
      Description copied from class: SoundSource
      This 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:
      setAttenuationFactor in class SoundSource
      Parameters:
      rolloff - (default depends on the attenuation model)
    • setAttenuationMinDistance

      public void setAttenuationMinDistance(float minDistance)
      Description copied from class: SoundSource
      Sets 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:
      setAttenuationMinDistance in class SoundSource
      Parameters:
      minDistance - (default depends on the attenuation model)
    • setAttenuationMaxDistance

      public void setAttenuationMaxDistance(float maxDistance)
      Description copied from class: SoundSource
      Sets 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:
      setAttenuationMaxDistance in class SoundSource
      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: SoundSource
      Makes 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). Call SoundSource.makeOmniDirectional() to make the source non-directional again.
      Overrides:
      makeDirectional in class SoundSource
      Parameters:
      direction - the direction the source is facing
      coneInnerAngle - the inner cone angle
      coneOuterAngle - the outer cone angle
      outOfConeVolume - 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: SoundSource
      Sets the direction of this sound source. You need to call SoundSource.makeDirectional(Vector3, float, float, float) first, otherwise the direction will be ignored.
      Overrides:
      setDirection in class SoundSource
      Parameters:
      direction - the direction
    • makeOmniDirectional

      public void makeOmniDirectional()
      Description copied from class: SoundSource
      Makes 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:
      makeOmniDirectional in class SoundSource
    • setSpeed

      public void setSpeed(float x, float y, float z)
      Description copied from class: SoundSource
      Sets 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:
      setSpeed in class SoundSource
      Parameters:
      x - the speed on the x-axis
      y - the speed on the y-axis
      z - the speed on the z-axis
    • setLooping

      public void setLooping(boolean looping)
      Description copied from class: SoundSource
      Sets wether this sound source should loop. When looping is enabled, the source will immediately play the sound again when it's finished playing.
      Overrides:
      setLooping in class SoundSource
      Parameters:
      looping - true for looped playback
    • pause

      public void pause()
      Description copied from class: SoundSource
      Pauses the sound playback.
      Overrides:
      pause in class SoundSource
    • stop

      public void stop()
      Description copied from class: SoundSource
      Stops the sound playback and rewinds it.
      Overrides:
      stop in class SoundSource
    • getDuration

      public float getDuration()
      Returns the duration of the attached sound in seconds.
      Specified by:
      getDuration in class SongSource
      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:
      getPlaybackPosition in class SongSource
      Returns:
      the playback position
    • attachEffect

      public SoundEffect attachEffect(SoundEffect effect)
      Description copied from class: SoundSource
      Attaches 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.
      Call AudioDevice.getNumberOfEffectSlots() to retrieve the number of available effect slots.
      Overrides:
      attachEffect in class SoundSource
      Parameters:
      effect - the sound effect
      Returns:
      the effect that was kicked out or null otherwise
    • detachEffect

      public boolean detachEffect(SoundEffect effect)
      Description copied from class: SoundSource
      Detaches the given SoundEffect from this sound source.
      Overrides:
      detachEffect in class SoundSource
      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: SoundSource
      Detaches all currently attached sound effects from this sound source.
      Overrides:
      detachAllEffects in class SoundSource
    • getBuffer

      public SoundBuffer 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.