Class SoundSystem
java.lang.Object
com.blackrook.gloop.openal.util.system.SoundSystem
The main sound system.
This is a high-level implementation of OpenAL which performs a lot of
out-of-the-box conveniences for sound playback.
If this class is used, do NOT use the OALSystem class for sound playback.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceThe function type to use for figuring out an occlusion scalar.static classA playback group type.static class -
Constructor Summary
ConstructorsConstructorDescriptionCreates and initializes a new sound system.SoundSystem(int voices) Creates and initializes a new sound system.SoundSystem(int voices, int cacheSize) Creates and initializes a new sound system. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SoundSystem.Listener listener) Adds a listener to this sound system.voidcacheSounds(SoundData... resources) Precaches a series of sound resources.static SoundCategoryTypecategory(SoundRolloffType rolloff) Creates a new rolloff category type.static SoundCategoryTypecategory(SoundRolloffType rolloff, SoundRolloffType rolloffConic) Creates a new rolloff category type.static SoundCategoryTypecategory(SoundRolloffType rolloff, SoundRolloffType rolloffLF, SoundRolloffType rolloffHF, SoundRolloffType rolloffConic) Creates a new rolloff category type.static SoundDataCreates a new sound data type.static SoundDatafileData(File file, boolean stream, boolean replacesOldSounds, boolean alwaysPlayed, int limit, float pitchVariance) Creates a new sound data type.static SoundDataCreates a new sound data type.static SoundDataCreates a new sound data type.static SoundDataCreates a new sound data type.static SoundDataCreates a new sound data type.static SoundDataCreates a new sound data type.intlonglongintstatic SoundSystem.SoundGroupgroup(boolean occludable, boolean twoDimensional, boolean zeroPosition, int maxVoices) Creates a new group type with defaults set, no parent.static SoundSystem.SoundGroupgroup(SoundGroupType parent, boolean occludable, boolean twoDimensional, boolean zeroPosition, int maxVoices) Creates a new group type with defaults set.static SoundLocationlocation(float x, float y, float z, float angle) Creates a new location instance.static SoundOcclusionTypeocclusion(float maximumWidth, float gain, float lowPassGain, float highPassGain) Creates a new set of occlusion parameters.voidpauseGroup(SoundSystem.SoundGroup group) Pauses all instances of sounds playing in a group.voidpauseLocation(SoundLocation location) Pauses all instances of sounds playing on a location.voidplay(SoundData data, SoundGroupType group) Plays a sound.voidplay(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location) Plays a sound.voidplay(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location, Integer channel) Plays a sound.voidplay(SoundData data, SoundGroupType group, SoundLocation location) Plays a sound.voidplayLooping(SoundData data, SoundGroupType group) Plays a looping sound.voidplayLooping(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location) Plays a looping sound.voidplayLooping(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location, Integer channel) Plays a looping sound.voidplayLooping(SoundData data, SoundGroupType group, SoundLocation location) Plays a looping sound.voidremoveListener(SoundSystem.Listener listener) Adds a listener to this sound system.static SoundDataresourceData(String resourcePath) Creates a new sound data type.static SoundDataresourceData(String resourcePath, boolean stream, boolean replacesOldSounds, boolean alwaysPlayed, int limit, float pitchVariance) Creates a new sound data type.static SoundDataresourceData(String resourcePath, boolean stream, boolean replacesOldSounds, int limit, float pitchVariance) Creates a new sound data type.static SoundDataresourceData(String resourcePath, boolean stream, int limit) Creates a new sound data type.static SoundDataresourceData(String resourcePath, boolean stream, int limit, float pitchVariance) Creates a new sound data type.static SoundDataresourceData(String resourcePath, int limit) Creates a new sound data type.static SoundDataresourceData(String resourcePath, int limit, float pitchVariance) Creates a new sound data type.voidResumes all instances of sounds playing in a group.voidresumeLocation(SoundLocation location) Resumes all instances of sounds playing on a location.static SoundRolloffTyperolloff(float minDistance, float maxDistance, SoundRolloffFunction rolloffFunction) Creates a new rolloff type instance.voidsetObserver(SoundLocation location) Sets the observer location.voidsetOcclusionFunction(SoundSystem.OcclusionFunction occlusionFunction) Sets the occlusion function to use to calculate occlusion.voidsetSoundScape(SoundScapeType soundScape) Sets the soundscape to use.voidshutDown()Stops all threads, sounds, and deallocates everything.static com.blackrook.gloop.openal.util.system.SoundSystem.SoundScapesoundScape(SoundEchoType echoType, SoundReverbType reverbType, SoundOcclusionType occlusionType, float minEffectGain, float maxEffectDistance) Creates a new SoundScape.voidstopGroup(SoundSystem.SoundGroup group) Stops all sounds in a group.voidstopLocation(SoundLocation location, Integer channel) Stops all sounds on a location.voidStops all instances of a sound playing.
-
Constructor Details
-
SoundSystem
public SoundSystem()Creates and initializes a new sound system. -
SoundSystem
public SoundSystem(int voices) Creates and initializes a new sound system.- Parameters:
voices- the total amount of voices to allocate.
-
SoundSystem
public SoundSystem(int voices, int cacheSize) Creates and initializes a new sound system.- Parameters:
voices- the total amount of voices to allocate.cacheSize- the cache size for the sound clip cache.
-
-
Method Details
-
fileData
-
fileData
-
fileData
-
fileData
-
fileData
Creates a new sound data type.- Parameters:
file- the file to load.stream- if true, the data is streamed, not loaded fully.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
fileData
public static SoundData fileData(File file, boolean stream, boolean replacesOldSounds, int limit, float pitchVariance) Creates a new sound data type.- Parameters:
file- the file to load.stream- if true, the data is streamed, not loaded fully.replacesOldSounds- if true, hitting the limit will replace a sound, not cull it.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
fileData
public static SoundData fileData(File file, boolean stream, boolean replacesOldSounds, boolean alwaysPlayed, int limit, float pitchVariance) Creates a new sound data type.- Parameters:
file- the file to load.stream- if true, the data is streamed, not loaded fully.replacesOldSounds- if true, hitting the limit will replace a sound, not cull it.alwaysPlayed- if true, must play once it is able to.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
resourceData
-
resourceData
-
resourceData
Creates a new sound data type.- Parameters:
resourcePath- the path to the internal resource.stream- if true, the data is streamed, not loaded fully.limit- the concurrent play limit until a cull or replace.- Returns:
- a new category.
-
resourceData
Creates a new sound data type.- Parameters:
resourcePath- the path to the internal resource.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
resourceData
public static SoundData resourceData(String resourcePath, boolean stream, int limit, float pitchVariance) Creates a new sound data type.- Parameters:
resourcePath- the path to the internal resource.stream- if true, the data is streamed, not loaded fully.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
resourceData
public static SoundData resourceData(String resourcePath, boolean stream, boolean replacesOldSounds, int limit, float pitchVariance) Creates a new sound data type.- Parameters:
resourcePath- the path to the internal resource.stream- if true, the data is streamed, not loaded fully.replacesOldSounds- if true, hitting the limit will replace a sound, not cull it.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
resourceData
public static SoundData resourceData(String resourcePath, boolean stream, boolean replacesOldSounds, boolean alwaysPlayed, int limit, float pitchVariance) Creates a new sound data type.- Parameters:
resourcePath- the path to the internal resource.stream- if true, the data is streamed, not loaded fully.replacesOldSounds- if true, hitting the limit will replace a sound, not cull it.alwaysPlayed- if true, must play once it is able to.limit- the concurrent play limit until a cull or replace.pitchVariance- the pitch variance scalar.- Returns:
- a new category.
-
soundScape
public static com.blackrook.gloop.openal.util.system.SoundSystem.SoundScape soundScape(SoundEchoType echoType, SoundReverbType reverbType, SoundOcclusionType occlusionType, float minEffectGain, float maxEffectDistance) Creates a new SoundScape.- Parameters:
echoType- the echo type.reverbType- the reverb type.occlusionType- the occlusion type.minEffectGain- the minimum effect gain at distance 0 (gain is 1.0 at max distance).maxEffectDistance- the distance in world units at which the effect gain is 1.0.- Returns:
- a new soundscape.
-
group
public static SoundSystem.SoundGroup group(boolean occludable, boolean twoDimensional, boolean zeroPosition, int maxVoices) Creates a new group type with defaults set, no parent.- Parameters:
occludable- if true, the sounds played from the this group are occludable.twoDimensional- if true, the sounds played from the this group are panned, not spacialized.zeroPosition- if true, the sounds played from the this group are always played from the observer and unattenuated.maxVoices- the maximum amount of voices for this group. 0 is unlimited.- Returns:
- a new group.
-
group
public static SoundSystem.SoundGroup group(SoundGroupType parent, boolean occludable, boolean twoDimensional, boolean zeroPosition, int maxVoices) Creates a new group type with defaults set.- Parameters:
parent- the parent group to accumulate from.occludable- if true, the sounds played from the this group are occludable.twoDimensional- if true, the sounds played from the this group are panned, not spacialized.zeroPosition- if true, the sounds played from the this group are always played from the observer and unattenuated.maxVoices- the maximum amount of voices for this group. 0 is unlimited.- Returns:
- a new group.
-
category
Creates a new rolloff category type.- Parameters:
rolloff- the main rolloff.- Returns:
- a new category.
-
category
Creates a new rolloff category type.- Parameters:
rolloff- the main rolloff.rolloffConic- the conic gain rolloff.- Returns:
- a new category.
-
category
public static SoundCategoryType category(SoundRolloffType rolloff, SoundRolloffType rolloffLF, SoundRolloffType rolloffHF, SoundRolloffType rolloffConic) Creates a new rolloff category type.- Parameters:
rolloff- the main rolloff.rolloffLF- the low-pass gain rolloff.rolloffHF- the high-pass gain rolloff.rolloffConic- the conic gain rolloff.- Returns:
- a new category.
-
rolloff
public static SoundRolloffType rolloff(float minDistance, float maxDistance, SoundRolloffFunction rolloffFunction) Creates a new rolloff type instance.- Parameters:
minDistance- the minimum distance that attenuation starts occurring.maxDistance- the maximum distance that full attenuation happens.rolloffFunction- the rolloff function for the distance betweeen min and max.- Returns:
- a new rolloff.
-
occlusion
public static SoundOcclusionType occlusion(float maximumWidth, float gain, float lowPassGain, float highPassGain) Creates a new set of occlusion parameters.- Parameters:
maximumWidth- the maximum occlusion width for max occlusion.gain- the full gain attenuation.lowPassGain- the full low-pass gain attenuation.highPassGain- the full high-pass gain attenuation.- Returns:
- a new occlusion.
-
location
Creates a new location instance.- Parameters:
x- the location x-coordinate, in world units.y- the location y-coordinate, in world units.z- the location z-coordinate, in world units.angle- the location angle, in degrees.- Returns:
- a new location.
-
getVendorName
- Returns:
- the vendor name for this OpenAL implementation.
-
getVersionName
- Returns:
- the version name for this OpenAL implementation.
-
getRendererName
- Returns:
- the renderer name for this OpenAL implementation.
-
getExtensions
-
addListener
Adds a listener to this sound system.- Parameters:
listener- the listener to add.
-
removeListener
Adds a listener to this sound system.- Parameters:
listener- the listener to add.
-
setObserver
Sets the observer location.- Parameters:
location- the observer's location reference.
-
setSoundScape
Sets the soundscape to use.- Parameters:
soundScape- the new soundscape. Can be null.
-
setOcclusionFunction
Sets the occlusion function to use to calculate occlusion.- Parameters:
occlusionFunction- the function.
-
cacheSounds
Precaches a series of sound resources. Will NOT cache sounds if they designated as not cacheable or if they are streaming: instead, they are "primed" - which means that it is prebuffered and ready to be played later.- Parameters:
resources- the list of resources to cache.
-
play
Plays a sound. No virtual channel, location, nor rolloff.- Parameters:
data- the sound data.group- the sound group it plays under.
-
play
Plays a sound. No virtual channel, nor rolloff.- Parameters:
data- the sound data.group- the sound group it plays under.location- the sound location in the world.
-
play
public void play(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location) Plays a sound. No virtual channel.- Parameters:
data- the sound data.group- the sound group it plays under.category- the sound rolloff category.location- the sound location in the world.
-
play
public void play(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location, Integer channel) Plays a sound.- Parameters:
data- the sound data.group- the sound group it plays under.category- the sound rolloff category.location- the sound location in the world.channel- the virtual channel on the location.
-
playLooping
Plays a looping sound. Be careful - you need to be able to stop this sound!- Parameters:
data- the sound data.group- the sound group it plays under.
-
playLooping
Plays a looping sound. Be careful - you need to be able to stop this sound!- Parameters:
data- the sound data.group- the sound group it plays under.location- the sound location in the world.
-
playLooping
public void playLooping(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location) Plays a looping sound. Be careful - you need to be able to stop this sound!- Parameters:
data- the sound data.group- the sound group it plays under.category- the sound rolloff category.location- the sound location in the world.
-
playLooping
public void playLooping(SoundData data, SoundGroupType group, SoundCategoryType category, SoundLocation location, Integer channel) Plays a looping sound. Be careful - you need to be able to stop this sound!- Parameters:
data- the sound data.group- the sound group it plays under.category- the sound rolloff category.location- the sound location in the world.channel- the virtual channel on the location.
-
pauseGroup
Pauses all instances of sounds playing in a group.- Parameters:
group- the group object.
-
pauseLocation
Pauses all instances of sounds playing on a location.- Parameters:
location- the location object.
-
resumeGroup
Resumes all instances of sounds playing in a group.- Parameters:
group- the group object.
-
resumeLocation
Resumes all instances of sounds playing on a location.- Parameters:
location- the location object.
-
stopSound
Stops all instances of a sound playing.- Parameters:
data- the sound data.
-
stopGroup
Stops all sounds in a group.- Parameters:
group- the sound group.
-
stopLocation
Stops all sounds on a location.- Parameters:
location- the location object.channel- the optional channel.
-
getUpdateVoiceNanos
public long getUpdateVoiceNanos()- Returns:
- the amount of time it took the voice update loop to update in nanoseconds.
-
getUpdateEventNanos
public long getUpdateEventNanos()- Returns:
- the amount of time it took the event loop to update in nanoseconds.
-
getAvailableVoiceCount
public int getAvailableVoiceCount()- Returns:
- the amount of available voices.
-
getUsedVoiceCount
public int getUsedVoiceCount()- Returns:
- the amount of used voices.
-
shutDown
public void shutDown()Stops all threads, sounds, and deallocates everything.
-