Class SoundEngine
SoundEngine class handles the management and playback of sounds in the game.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelAccessprivate static final longThe default interval in milliseconds for checking the audio device stateprivate final AtomicReference<SoundEngine.DeviceCheckState> The current state of the audio device checkprivate final SoundEngineExecutorprivate final Multimap<SoundSource, SoundInstance> private final Map<SoundInstance, ChannelAccess.ChannelHandle> private longprivate final Libraryprivate final ListenerThe listener object responsible for managing the sound listener position and orientationprivate final List<SoundEventListener> private booleanSet to true when the SoundManager has been initialised.private static final org.slf4j.Loggerprivate static final org.slf4j.MarkerThe marker used for loggingprivate static final intstatic final Stringprivate static final Set<ResourceLocation> A set of resource locations for which a missing sound warning has been issuedstatic final Stringstatic final intprivate final OptionsReference to the GameSettings object.private static final floatprivate static final floatprivate final Map<SoundInstance, Integer> Contains sounds to play in n ticks.private final List<TickableSoundInstance> private final SoundBufferLibraryprivate final Map<SoundInstance, Integer> The future time in which to stop this sound.final SoundManagerA reference to the sound handler.private intA counter for how long the sound manager has been runningprivate final List<TickableSoundInstance> A subset of playingSounds, this contains only TickableSoundInstanceprivate static final floatprivate static final float -
Constructor Summary
ConstructorsConstructorDescriptionSoundEngine(SoundManager pSoundManager, Options pOptions, ResourceProvider pResourceManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(SoundEventListener pListener) private floatcalculatePitch(SoundInstance pSound) Calculates the pitch of the sound being played.private floatcalculateVolume(float pVolumeMultiplier, SoundSource pSource) Calculates the volume of the sound being played.private floatcalculateVolume(SoundInstance pSound) Calculates the volume for the sound being played.voiddestroy()voidprivate floatgetVolume(SoundSource pCategory) Returns the volume value pinned between 0.0f and 1.0f for a given SoundSource category.booleanisActive(SoundInstance pSound) private voidvoidpause()voidplay(SoundInstance pSound) Plays a given sound instance.voidplayDelayed(SoundInstance pSound, int pDelay) Adds a sound to play in n ticksvoidqueueTickingSound(TickableSoundInstance pTickableSound) Queues a newinvalid reference
TickingCodeInstance
voidreload()voidremoveEventListener(SoundEventListener pListener) voidrequestPreload(Sound pSound) Requests a specific Sound instance to be preloaded.private static booleanrequiresManualLooping(SoundInstance pSound) Returns invalid input: 'Returns {@code true} if the SoundInstance requires manual looping, {@code false} otherwise @param pSound the SoundInstance to check'.voidresume()voidsetVolume(SoundInstance pSoundInstance, float pVolume) private booleanprivate static booleanshouldLoopAutomatically(SoundInstance pSound) private static booleanshouldLoopManually(SoundInstance pSound) voidstop(SoundInstance pSound) Stops the providedfrom continuing to play.invalid reference
SoundInstace
voidstop(ResourceLocation pSoundName, SoundSource pCategory) voidstopAll()voidtick(boolean pIsGamePaused) Ticks all active instances ofTickableSoundInstanceprivate voidvoidupdateCategoryVolume(SoundSource pCategory, float pVolume) Updates the volume for a specific sound category.voidupdateSource(Camera pRenderInfo)
-
Field Details
-
MARKER
private static final org.slf4j.Marker MARKERThe marker used for logging -
LOGGER
private static final org.slf4j.Logger LOGGER -
PITCH_MIN
private static final float PITCH_MIN- See Also:
-
PITCH_MAX
private static final float PITCH_MAX- See Also:
-
VOLUME_MIN
private static final float VOLUME_MIN- See Also:
-
VOLUME_MAX
private static final float VOLUME_MAX- See Also:
-
MIN_SOURCE_LIFETIME
private static final int MIN_SOURCE_LIFETIME- See Also:
-
ONLY_WARN_ONCE
A set of resource locations for which a missing sound warning has been issued -
DEFAULT_DEVICE_CHECK_INTERVAL_MS
private static final long DEFAULT_DEVICE_CHECK_INTERVAL_MSThe default interval in milliseconds for checking the audio device state- See Also:
-
MISSING_SOUND
- See Also:
-
OPEN_AL_SOFT_PREFIX
- See Also:
-
OPEN_AL_SOFT_PREFIX_LENGTH
public static final int OPEN_AL_SOFT_PREFIX_LENGTH -
soundManager
A reference to the sound handler. -
options
Reference to the GameSettings object. -
loaded
private boolean loadedSet to true when the SoundManager has been initialised. -
library
-
listener
The listener object responsible for managing the sound listener position and orientation -
soundBuffers
-
executor
-
channelAccess
-
tickCount
private int tickCountA counter for how long the sound manager has been running -
lastDeviceCheckTime
private long lastDeviceCheckTime -
devicePoolState
The current state of the audio device check -
instanceToChannel
-
instanceBySource
-
tickingSounds
A subset of playingSounds, this contains only TickableSoundInstance -
queuedSounds
Contains sounds to play in n ticks. Type: HashMapinvalid input: '<'ISound, Integer> -
soundDeleteTime
The future time in which to stop this sound. Type: HashMapinvalid input: '<'String, Integer> -
listeners
-
queuedTickableSounds
-
preloadQueue
-
-
Constructor Details
-
SoundEngine
-
-
Method Details
-
reload
public void reload() -
loadLibrary
private void loadLibrary() -
getVolume
Returns the volume value pinned between 0.0f and 1.0f for a given SoundSource category.- Returns:
- the volume value pinned between 0.0f and 1.0f for a given SoundSource category
-
updateCategoryVolume
Updates the volume for a specific sound category.If the sound engine has not been loaded, the method returns without performing any action.
If the category is the "MASTER" category, the overall listener gain (volume) is set to the specified value.
For other categories, the volume is updated for each sound instance associated with the category.
If the calculated volume for an instance is less than or equal to 0.0, the instance is stopped. Otherwise, the volume of the instance is set to the calculated value.
-
destroy
public void destroy() -
emergencyShutdown
public void emergencyShutdown() -
stop
Stops the providedfrom continuing to play.invalid reference
SoundInstace
-
setVolume
-
stopAll
public void stopAll() -
addEventListener
-
removeEventListener
-
shouldChangeDevice
private boolean shouldChangeDevice() -
tick
public void tick(boolean pIsGamePaused) Ticks all active instances ofTickableSoundInstance -
tickNonPaused
private void tickNonPaused() -
requiresManualLooping
Returns invalid input: 'Returns {@code true} if the SoundInstance requires manual looping, {@code false} otherwise @param pSound the SoundInstance to check'.- Returns:
- invalid input: 'Returns {@code true} if the SoundInstance requires manual looping, {@code false} otherwise @param pSound the SoundInstance to check'
-
shouldLoopManually
- Parameters:
pSound- The SoundInstance to check- Returns:
- Returns
trueif the SoundInstance should loop manually,falseotherwise
-
shouldLoopAutomatically
- Parameters:
pSound- The SoundInstance to check- Returns:
- Returns
trueif the SoundInstance should loop automatically,falseotherwise
-
isActive
- Parameters:
pSound- the SoundInstance to check- Returns:
trueif the SoundInstance is active,falseotherwise
-
play
Plays a given sound instance.If the sound engine is not loaded or the sound instance cannot be played, the method returns early.
The method fulfills the following parts:
- Performs a series of checks to determine if it can play a sound
- Handles the playing of instances of
SoundInstance - Logs potential errors that may have occured
- Handles mapping instances of
SoundInstanceto specific audio channels - Handles deletion times for active instances of
SoundInstance - Calculates and handles various sound properties such as volume, pitch, attenuation, looping, position and relative,
- Parameters:
pSound- the sound instance to be played.
-
queueTickingSound
Queues a newinvalid reference
TickingCodeInstance
- Parameters:
pTickableSound- the TickableSoundInstance to queue
-
requestPreload
Requests a specific Sound instance to be preloaded. -
calculatePitch
Calculates the pitch of the sound being played.Clamps the sound between 0.5f and 2.0f.
- Parameters:
pSound- the SoundInstance being played
-
calculateVolume
Calculates the volume for the sound being played.Delegates to
#calculateVolume(float, SoundSource) -
calculateVolume
Calculates the volume of the sound being played.Clamps the sound between 0.0f and 1.0f.
-
pause
public void pause() -
resume
public void resume() -
playDelayed
Adds a sound to play in n ticks -
updateSource
-
stop
-
getDebugString
-
getAvailableSoundDevices
-
getListenerTransform
-