Class AudioDevice

java.lang.Object
de.pottgames.tuningfork.AudioDevice

public class AudioDevice extends Object
A class that gives access to some audio hardware device specific settings. Allows to query and change hardware specific settings.
  • Constructor Details

  • Method Details

    • availableDevices

      public static List<String> availableDevices()
      Returns a list of identifiers of available sound devices. You can use an identifier in AudioDeviceConfig.setDeviceSpecifier(String) to request a specific sound device for audio playback or switch to a device at runtime with switchToDevice(String).
      Returns:
      the list
    • isExtensionAvailable

      protected boolean isExtensionAvailable(ALExtension extension)
    • isConnected

      public boolean isConnected()
      Returns whether the audio output device is still connected. While most people are using either PCI audio cards or a chip welded to their motherboard, there are many devices that are more dynamic in nature, such as USB and Firewire based-units. Such units may lose external power or may have their cables unplugged at runtime.

      Note: Not all operating systems and/or drivers will report a disconnected device.
      Returns:
      true if the device is connected, false otherwise
    • switchToDevice

      public boolean switchToDevice(String deviceSpecifier)
      Switches to another audio device.
      Parameters:
      deviceSpecifier - must be one of the devices returned by availableDevices() or null to switch to the default device.
      Returns:
      true if successful
    • setDeviceRerouter

      public void setDeviceRerouter(AudioDeviceRerouter rerouter)
      Sets the device rerouter, calls setup and start on it. If there was another rerouter active, it gets disposed.
      Parameters:
      rerouter - the rerouter
    • getDeviceRerouter

      public AudioDeviceRerouter getDeviceRerouter()
      Returns the currently active AudioDeviceRerouter.
      Returns:
      the device rerouter
    • getOutputMode

      public OutputMode getOutputMode()
      Returns the output mode of the device. It includes the channel configuration of the physical (if not virtual) sound hardware this device is connected to.
      Returns:
      the output mode
    • isHrtfSupported

      public boolean isHrtfSupported()
      Returns true if HRTF is supported by this device. This does not necessarily mean that a hrtf profile is available, call getAvailableHrtfs() to query for profiles.
      Returns:
      true if supported
    • isHrtfEnabled

      public boolean isHrtfEnabled()
      Returns true if HRTF is enabled.
      Returns:
      true if enabled
    • getAvailableHrtfs

      public com.badlogic.gdx.utils.Array<String> getAvailableHrtfs()
      Returns a list of available hrtf configurations of this device.
      Returns:
      list of available hrtf configurations
    • enableHrtf

      public boolean enableHrtf(String specifier)
      Enables hrtf on this device.
      Parameters:
      specifier - the hrtf configuration specifier. Must be one of the strings included in the list from getAvailableHrtfs()
      Returns:
      true on success, false on failure
    • disableHrtf

      public void disableHrtf()
      Disables hrtf on this device.
    • getAvailableResamplers

      public com.badlogic.gdx.utils.Array<String> getAvailableResamplers()
      Returns a list of available resamplers for this device. The list is ordered by performance impact. That is, indices closer to 0 are of lower impact, and the higher index values have higher impact.
      Mostly, a higher performance impact also means a better result in terms of quality, though this isn't true in all cases.

      If you need more information on what resampler is best for you, here's a video recommendation: https://www.youtube.com/watch?v=62U6UnaUGDE
      Returns:
      list of available resamplers
    • getNumberOfEffectSlots

      public int getNumberOfEffectSlots()
      Returns the number of available effect slots. If you want to change the number, see AudioDeviceConfig.setEffectSlots(int).
      Returns:
      the number of effect slots available for each source
    • getResamplerIndexByName

      protected int getResamplerIndexByName(String name)
      Returns the index of the first occurrence of the value in the array, or -1 if no such value exists.
      Parameters:
      name - the name of the resampler
      Returns:
      the index of the first occurrence of the value in the array or -1 if no such value exists
    • getDefaultResamplerIndex

      protected int getDefaultResamplerIndex()
    • getDefaultResampler

      public String getDefaultResampler()
      Returns the name of the default resampler currently in use.
      Returns:
      name of the default resampler
    • getClockTime

      public long getClockTime()
      Returns the clock time in nanoseconds as seen by the audio device, which may be slightly different than the system clock's tick rate (the infamous timer drift).
      Returns:
      the device time in nanoseconds
    • getLatency

      public long getLatency()
      Returns the current audio device latency in nanoseconds. This is effectively the delay for the samples rendered at the the device's current clock time from reaching the physical output.
      Returns:
      latency in nanoseconds
    • getClockTimeAndLatency

      public long[] getClockTimeAndLatency()
      This method fetches the audio device clock time and latency at the same time, avoiding the imprecision by calling both functions separately.
      See getClockTime() and getLatency() for a detailed explanation.
      The returned long array is "owned" by the AudioDevice class, so you shouldn't hold a reference to it but rather copy the values.
      Returns:
      a long array that holds the time at index 0 and the latency at index 1. The length of 2 is guaranteed.
    • onAlEvent

      protected void onAlEvent(AlEvent event)
      This method is invoked from OpenAL on an arbitrary thread when an event occurs for which TuningFork has registered.
      Parameters:
      event - the OpenAL event
    • onDisconnect

      protected void onDisconnect()
    • dispose

      protected void dispose(boolean log)