Class AudioDevice
java.lang.Object
de.pottgames.tuningfork.AudioDevice
A class that gives access to some audio hardware device specific settings. Allows to query and change hardware specific settings.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAudioDevice(AudioDeviceConfig config, TuningForkLogger logger) -
Method Summary
Modifier and TypeMethodDescriptionReturns a list of identifiers of available sound devices.voidDisables hrtf on this device.protected voiddispose(boolean log) booleanenableHrtf(String specifier) Enables hrtf on this device.com.badlogic.gdx.utils.Array<String> Returns a list of available hrtf configurations of this device.com.badlogic.gdx.utils.Array<String> Returns a list of available resamplers for this device.longReturns 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).long[]This method fetches the audio device clock time and latency at the same time, avoiding the imprecision by calling both functions separately.
SeegetClockTime()andgetLatency()for a detailed explanation.
The returned long array is "owned" by theAudioDeviceclass, so you shouldn't hold a reference to it but rather copy the values.Returns the name of the default resampler currently in use.protected intReturns the currently activeAudioDeviceRerouter.longReturns the current audio device latency in nanoseconds.intReturns the number of available effect slots.Returns the output mode of the device.protected intReturns the index of the first occurrence of the value in the array, or -1 if no such value exists.booleanReturns whether the audio output device is still connected.protected booleanisExtensionAvailable(ALExtension extension) booleanReturns true if HRTF is enabled.booleanReturns true if HRTF is supported by this device.protected voidThis method is invoked from OpenAL on an arbitrary thread when an event occurs for which TuningFork has registered.protected voidvoidsetDeviceRerouter(AudioDeviceRerouter rerouter) booleanswitchToDevice(String deviceSpecifier) Switches to another audio device.
-
Constructor Details
-
AudioDevice
protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws OpenDeviceException, UnsupportedAudioDeviceException
-
-
Method Details
-
availableDevices
Returns a list of identifiers of available sound devices. You can use an identifier inAudioDeviceConfig.setDeviceSpecifier(String)to request a specific sound device for audio playback or switch to a device at runtime withswitchToDevice(String).- Returns:
- the list
-
isExtensionAvailable
-
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
Switches to another audio device.- Parameters:
deviceSpecifier- must be one of the devices returned byavailableDevices()or null to switch to the default device.- Returns:
- true if successful
-
setDeviceRerouter
-
getDeviceRerouter
Returns the currently activeAudioDeviceRerouter.- Returns:
- the device rerouter
-
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, callgetAvailableHrtfs()to query for profiles.- Returns:
- true if supported
-
isHrtfEnabled
public boolean isHrtfEnabled()Returns true if HRTF is enabled.- Returns:
- true if enabled
-
getAvailableHrtfs
Returns a list of available hrtf configurations of this device.- Returns:
- list of available hrtf configurations
-
enableHrtf
Enables hrtf on this device.- Parameters:
specifier- the hrtf configuration specifier. Must be one of the strings included in the list fromgetAvailableHrtfs()- Returns:
- true on success, false on failure
-
disableHrtf
public void disableHrtf()Disables hrtf on this device. -
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, seeAudioDeviceConfig.setEffectSlots(int).- Returns:
- the number of effect slots available for each source
-
getResamplerIndexByName
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
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.
SeegetClockTime()andgetLatency()for a detailed explanation.
The returned long array is "owned" by theAudioDeviceclass, 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
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)
-