Package org.xjge.core

Class Audio

java.lang.Object
org.xjge.core.Audio

public final class Audio
extends java.lang.Object
Provides an abstraction of the OpenAL API through which sound effects and music may be played.
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int ALL_SOURCES
    A unique value that can be passed to the setSoundSourceState(int, int) method to change the current state of every sound source.
  • Constructor Summary

    Constructors
    Constructor Description
    Audio()  
  • Method Summary

    Modifier and Type Method Description
    static float getMusicMasterVolume()
    Provides the current value of the music master volume.
    static float getSoundMasterVolume()
    Obtains the current value of the sound master volume.
    static void pauseMusic()
    Pauses whatever song is currently playing at its current measure.
    static void playMusic​(Song song)
    Plays a song from the beginning.
    static int playSound​(Sound sound, org.joml.Vector3f position, boolean loop)
    Emits a Sound from some specified position in the game world.
    static void resumeMusic()
    Resumes playing whatever song was previously paused from where it left off.
    static void setMusicMasterVolume​(float masterVolume)
    Sets the master volume that will be used to attenuate the overall volume of the games background music.
    static void setSoundMasterVolume​(float masterVolume)
    Sets the master volume that will be used to attenuate the overall volume of all sound effects.
    static void setSoundSourceState​(int handle, int state)
    Explicitly sets the state of a SoundSource object.
    static void stopMusic()
    Ceases playing a song.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Audio

      public Audio()
  • Method Details

    • playSound

      public static int playSound​(Sound sound, org.joml.Vector3f position, boolean loop)
      Emits a Sound from some specified position in the game world.
      Parameters:
      sound - the sound to play
      position - the position from which the sound will play. If null is passed, the sound will not be attenuated according to its position in the game world.
      loop - if true, the sound will loop indefinitely until stopped
      Returns:
      a value that identifies which SoundSource was used to play the sound
      See Also:
      setSoundSourceState(int, int)
    • playMusic

      public static void playMusic​(Song song)
      Plays a song from the beginning. If the song contains an intro sequence it will be played first before looping the body section.

      NOTE: Calling this method will interrupt and replace any song that was previously playing.

      Parameters:
      song - the song to start playing
    • pauseMusic

      public static void pauseMusic()
      Pauses whatever song is currently playing at its current measure.
      See Also:
      resumeMusic()
    • resumeMusic

      public static void resumeMusic()
      Resumes playing whatever song was previously paused from where it left off.
      See Also:
      pauseMusic()
    • stopMusic

      public static void stopMusic()
      Ceases playing a song. Unlike pauseMusic(), stopping a song will set reset its measure.
    • getSoundMasterVolume

      public static float getSoundMasterVolume()
      Obtains the current value of the sound master volume.

      NOTE: It's encouraged that you multiply this value by some factor of ten to obfuscate the implementations reliance on a floating point value from 0 to 1 and instead provide players with something more practical (0 to 100, etc).

      Returns:
      the value used to attenuate the volume of all sound effects
    • getMusicMasterVolume

      public static float getMusicMasterVolume()
      Provides the current value of the music master volume.

      NOTE: It's encouraged that you multiply this value by some factor of ten to obfuscate the implementations reliance on a floating point value from 0 to 1 and instead provide players with something more practical (0 to 100, etc).

      Returns:
      the value used to attenuate the volume of the games background music
    • setSoundMasterVolume

      public static void setSoundMasterVolume​(float masterVolume)
      Sets the master volume that will be used to attenuate the overall volume of all sound effects.
      Parameters:
      masterVolume - the value used to attenuate the volume of sound effects (between 0 and 1)
    • setMusicMasterVolume

      public static void setMusicMasterVolume​(float masterVolume)
      Sets the master volume that will be used to attenuate the overall volume of the games background music.
      Parameters:
      masterVolume - the value used to attenuate the volume of the games music (between 0 and 1)
    • setSoundSourceState

      public static void setSoundSourceState​(int handle, int state)
      Explicitly sets the state of a SoundSource object.
      Parameters:
      handle - the unique handle used to identify the sound source or ALL_SOURCES
      state - the state to set the source to. One of AL_PLAYING, AL_PAUSED, or AL_STOPPED.