Package net.minecraft.client.sounds
Class SoundEngine
java.lang.Object
net.minecraft.client.sounds.SoundEngine
The
SoundEngine
class handles the management and playback of sounds in the game.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelAccess
private static final long
The default interval in milliseconds for checking the audio device stateprivate final AtomicReference
<SoundEngine.DeviceCheckState> The current state of the audio device checkprivate final SoundEngineExecutor
private final com.google.common.collect.Multimap
<SoundSource, SoundInstance> private final Map
<SoundInstance, ChannelAccess.ChannelHandle> private long
private final Library
private final Listener
The listener object responsible for managing the sound listener position and orientationprivate final List
<SoundEventListener> private boolean
Set to true when the SoundManager has been initialised.private static final org.slf4j.Logger
private static final org.slf4j.Marker
The marker used for loggingprivate static final int
static final String
private final MusicManager
private static final Set
<ResourceLocation> A set of resource locations for which a missing sound warning has been issuedstatic final String
static final int
private final Options
Reference to the GameSettings object.private static final float
private static final float
private final Map
<SoundInstance, Integer> Contains sounds to play in n ticks.private final List
<TickableSoundInstance> private final SoundBufferLibrary
private final Map
<SoundInstance, Integer> The future time in which to stop this sound.final SoundManager
A reference to the sound handler.private int
A counter for how long the sound manager has been runningprivate final List
<TickableSoundInstance> A subset of playingSounds, this contains only TickableSoundInstanceprivate static final float
private static final float
-
Constructor Summary
ConstructorsConstructorDescriptionSoundEngine
(MusicManager pMusicManager, SoundManager pSoundManager, Options pOptions, ResourceProvider pResourceManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEventListener
(SoundEventListener pListener) private float
calculatePitch
(SoundInstance pSound) Calculates the pitch of the sound being played.private float
calculateVolume
(float pVolumeMultiplier, SoundSource pSource) Calculates the volume of the sound being played.private float
calculateVolume
(SoundInstance pSound) Calculates the volume for the sound being played.void
destroy()
void
private float
getVolume
(SoundSource pCategory) Returns the volume value pinned between 0.0f and 1.0f for a given SoundSource category.boolean
isActive
(SoundInstance pSound) private void
void
pauseAllExcept
(SoundSource... pSoundSources) play
(SoundInstance p_120313_) void
playDelayed
(SoundInstance pSound, int pDelay) Adds a sound to play in n ticksvoid
queueTickingSound
(TickableSoundInstance pTickableSound) Queues a newinvalid reference
TickingCodeInstance
void
reload()
void
removeEventListener
(SoundEventListener pListener) void
requestPreload
(Sound pSound) Requests a specific Sound instance to be preloaded.private static boolean
requiresManualLooping
(SoundInstance pSound) Returns invalid input: 'Returns {@code true} if the SoundInstance requires manual looping, {@code false} otherwise @param pSound the SoundInstance to check'.void
resume()
void
setVolume
(SoundInstance pSoundInstance, float pVolume) private boolean
private static boolean
shouldLoopAutomatically
(SoundInstance pSound) private static boolean
shouldLoopManually
(SoundInstance pSound) void
stop
(SoundInstance pSound) Stops the provided SoundInstance from continuing to play.void
stop
(ResourceLocation pSoundName, SoundSource pCategory) void
stopAll()
void
tick
(boolean pIsGamePaused) Ticks all active instances ofTickableSoundInstance
private void
private void
void
updateCategoryVolume
(SoundSource pCategory, float pVolume) Updates the volume for a specific sound category.void
updateSource
(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 -
musicManager
-
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
public SoundEngine(MusicManager pMusicManager, SoundManager pSoundManager, Options pOptions, ResourceProvider pResourceManager)
-
-
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 provided SoundInstance from continuing to play. -
setVolume
-
stopAll
public void stopAll() -
addEventListener
-
removeEventListener
-
shouldChangeDevice
private boolean shouldChangeDevice() -
tick
public void tick(boolean pIsGamePaused) Ticks all active instances ofTickableSoundInstance
-
tickInGameSound
private void tickInGameSound() -
tickMusicWhenPaused
private void tickMusicWhenPaused() -
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
true
if the SoundInstance should loop manually,false
otherwise
-
shouldLoopAutomatically
- Parameters:
pSound
- The SoundInstance to check- Returns:
- Returns
true
if the SoundInstance should loop automatically,false
otherwise
-
isActive
- Parameters:
pSound
- the SoundInstance to check- Returns:
true
if the SoundInstance is active,false
otherwise
-
play
-
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.
-
pauseAllExcept
-
resume
public void resume() -
playDelayed
Adds a sound to play in n ticks -
updateSource
-
stop
-
getDebugString
-
getAvailableSoundDevices
-
getListenerTransform
-