Package arc.audio

Class Sound

All Implemented Interfaces:
Disposable

public class Sound extends AudioSource

A Sound is a short audio clip that can be played numerous times in parallel. It's completely loaded into memory so only load small audio files. Call the AudioSource.dispose() method when you're done using the Sound.

Sound instances are created via a call to Audio.newSound(Fi).

Calling the play() or play(float) method will return a long which is an id to that instance of the sound. You can use this id to modify the playback of that sound instance.

Note: any values provided will not be clamped, it is the developer's responsibility to do so

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     

    Fields inherited from class arc.audio.AudioSource

    handle
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty sound.
    Sound(Fi file)
    Loads a sound from a file.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    at(float x, float y)
    Plays this sound at a certain position, with correct panning and volume applied.
    int
    at(float x, float y, float pitch)
    Plays this sound at a certain position, with correct panning and volume applied.
    int
    at(float x, float y, float pitch, float volume)
    Plays this sound at a certain position, with correct panning and volume applied.
    int
    at(Position pos)
    Plays #at() with this position.
    int
    at(Position pos, float pitch)
    Plays #at() with this position.
    float
    calcFalloff(float x, float y)
     
    float
    calcPan(float x, float y)
     
    float
    calcVolume(float x, float y)
     
    void
    load(Fi file)
     
    int
    Plays the sound, looping.
    int
    loop(float volume)
    Plays the sound, looping.
    int
    loop(float volume, float pitch, float pan)
    Plays the sound, looping.
    int
    Plays the sound.
    int
    play(float volume)
    Plays the sound.
    int
    play(float volume, float pitch, float pan)
    Plays the sound.
    int
    play(float volume, float pitch, float pan, boolean loop)
     
    int
    play(float volume, float pitch, float pan, boolean loop, boolean checkFrame)
    Plays the sound.
    void
    Sets the bus that will be used for the next play of this SFX.
    void
     
     

    Methods inherited from class arc.audio.AudioSource

    dispose, setFilter, setFilter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface arc.util.Disposable

    isDisposed
  • Field Details

  • Constructor Details

    • Sound

      public Sound()
      Creates an empty sound. This sound cannot be played until it is loaded.
    • Sound

      public Sound(Fi file)
      Loads a sound from a file.
  • Method Details

    • load

      public void load(Fi file)
    • play

      public int play(float volume, float pitch, float pan, boolean loop, boolean checkFrame)
      Plays the sound. If the sound is already playing, it will be played again, concurrently.
      Parameters:
      volume - the volume in the range [0,1]
      pitch - the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
      pan - panning in the range -1 (full left) to 1 (full right). 0 is center position.
      checkFrame - if true, this sound will not be able to be played twice in the same frame.
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • setBus

      public void setBus(AudioBus bus)
      Sets the bus that will be used for the next play of this SFX.
    • stop

      public void stop()
    • calcPan

      public float calcPan(float x, float y)
    • calcVolume

      public float calcVolume(float x, float y)
    • calcFalloff

      public float calcFalloff(float x, float y)
    • at

      public int at(float x, float y, float pitch)
      Plays this sound at a certain position, with correct panning and volume applied. Automatically uses the "sfxvolume" setting.
    • at

      public int at(float x, float y, float pitch, float volume)
      Plays this sound at a certain position, with correct panning and volume applied. Automatically uses the "sfxvolume" setting.
    • at

      public int at(float x, float y)
      Plays this sound at a certain position, with correct panning and volume applied. Automatically uses the "sfxvolume" setting.
    • at

      public int at(Position pos)
      Plays #at() with this position.
    • at

      public int at(Position pos, float pitch)
      Plays #at() with this position.
    • play

      public int play()
      Plays the sound. If the sound is already playing, it will be played again, concurrently. Automatically uses the "sfxvolume" setting.
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • play

      public int play(float volume)
      Plays the sound. If the sound is already playing, it will be played again, concurrently. Ignores SFX volume setting.
      Parameters:
      volume - the volume in the range [0,1]
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • play

      public int play(float volume, float pitch, float pan, boolean loop)
    • play

      public int play(float volume, float pitch, float pan)
      Plays the sound. If the sound is already playing, it will be played again, concurrently.
      Parameters:
      volume - the volume in the range [0,1]
      pitch - the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
      pan - panning in the range -1 (full left) to 1 (full right). 0 is center position.
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • loop

      public int loop()
      Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • loop

      public int loop(float volume)
      Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.
      Parameters:
      volume - the volume in the range [0, 1]
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • loop

      public int loop(float volume, float pitch, float pan)
      Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.
      Parameters:
      volume - the volume in the range [0,1]
      pitch - the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
      pan - panning in the range -1 (full left) to 1 (full right). 0 is center position.
      Returns:
      the id of the sound instance if successful, or -1 on failure.
    • toString

      public String toString()
      Overrides:
      toString in class Object