Class SoundEngine

java.lang.Object
net.minecraft.client.sounds.SoundEngine

public class SoundEngine extends Object
The SoundEngine class handles the management and playback of sounds in the game.
  • Field Details

    • MARKER

      private static final org.slf4j.Marker MARKER
      The 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

      private static final Set<ResourceLocation> 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_MS
      The default interval in milliseconds for checking the audio device state
      See Also:
    • MISSING_SOUND

      public static final String MISSING_SOUND
      See Also:
    • OPEN_AL_SOFT_PREFIX

      public static final String OPEN_AL_SOFT_PREFIX
      See Also:
    • OPEN_AL_SOFT_PREFIX_LENGTH

      public static final int OPEN_AL_SOFT_PREFIX_LENGTH
    • musicManager

      private final MusicManager musicManager
    • soundManager

      public final SoundManager soundManager
      A reference to the sound handler.
    • options

      private final Options options
      Reference to the GameSettings object.
    • loaded

      private boolean loaded
      Set to true when the SoundManager has been initialised.
    • library

      private final Library library
    • listener

      private final Listener listener
      The listener object responsible for managing the sound listener position and orientation
    • soundBuffers

      private final SoundBufferLibrary soundBuffers
    • executor

      private final SoundEngineExecutor executor
    • channelAccess

      private final ChannelAccess channelAccess
    • tickCount

      private int tickCount
      A counter for how long the sound manager has been running
    • lastDeviceCheckTime

      private long lastDeviceCheckTime
    • devicePoolState

      private final AtomicReference<SoundEngine.DeviceCheckState> devicePoolState
      The current state of the audio device check
    • instanceToChannel

      private final Map<SoundInstance,ChannelAccess.ChannelHandle> instanceToChannel
    • instanceBySource

      private final com.google.common.collect.Multimap<SoundSource,SoundInstance> instanceBySource
    • tickingSounds

      private final List<TickableSoundInstance> tickingSounds
      A subset of playingSounds, this contains only TickableSoundInstance
    • queuedSounds

      private final Map<SoundInstance,Integer> queuedSounds
      Contains sounds to play in n ticks. Type: HashMapinvalid input: '<'ISound, Integer>
    • soundDeleteTime

      private final Map<SoundInstance,Integer> soundDeleteTime
      The future time in which to stop this sound. Type: HashMapinvalid input: '<'String, Integer>
    • listeners

      private final List<SoundEventListener> listeners
    • queuedTickableSounds

      private final List<TickableSoundInstance> queuedTickableSounds
    • preloadQueue

      private final List<Sound> preloadQueue
  • Constructor Details

  • Method Details

    • reload

      public void reload()
    • loadLibrary

      private void loadLibrary()
    • getVolume

      private float getVolume(@Nullable SoundSource pCategory)
      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

      public void updateCategoryVolume(SoundSource pCategory, float pVolume)
      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

      public void stop(SoundInstance pSound)
      Stops the provided SoundInstance from continuing to play.
    • setVolume

      public void setVolume(SoundInstance pSoundInstance, float pVolume)
    • stopAll

      public void stopAll()
    • addEventListener

      public void addEventListener(SoundEventListener pListener)
    • removeEventListener

      public void removeEventListener(SoundEventListener pListener)
    • shouldChangeDevice

      private boolean shouldChangeDevice()
    • tick

      public void tick(boolean pIsGamePaused)
      Ticks all active instances of TickableSoundInstance
    • tickInGameSound

      private void tickInGameSound()
    • tickMusicWhenPaused

      private void tickMusicWhenPaused()
    • requiresManualLooping

      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'.
      Returns:
      invalid input: 'Returns {@code true} if the SoundInstance requires manual looping, {@code false} otherwise @param pSound the SoundInstance to check'
    • shouldLoopManually

      private static boolean shouldLoopManually(SoundInstance pSound)
      Parameters:
      pSound - The SoundInstance to check
      Returns:
      Returns true if the SoundInstance should loop manually, false otherwise
    • shouldLoopAutomatically

      private static boolean shouldLoopAutomatically(SoundInstance pSound)
      Parameters:
      pSound - The SoundInstance to check
      Returns:
      Returns true if the SoundInstance should loop automatically, false otherwise
    • isActive

      public boolean isActive(SoundInstance pSound)
      Returns true if the SoundInstance is active, false otherwise.
      Parameters:
      pSound - the SoundInstance to check
      Returns:
      true if the SoundInstance is active, false otherwise
    • play

      public SoundEngine.PlayResult play(SoundInstance p_120313_)
    • queueTickingSound

      public void queueTickingSound(TickableSoundInstance pTickableSound)
      Queues a new
      invalid reference
      TickingCodeInstance
      Parameters:
      pTickableSound - the TickableSoundInstance to queue
    • requestPreload

      public void requestPreload(Sound pSound)
      Requests a specific Sound instance to be preloaded.
    • calculatePitch

      private float calculatePitch(SoundInstance pSound)
      Calculates the pitch of the sound being played.

      Clamps the sound between 0.5f and 2.0f.

      Parameters:
      pSound - the SoundInstance being played
    • calculateVolume

      private float calculateVolume(SoundInstance pSound)
      Calculates the volume for the sound being played.

      Delegates to #calculateVolume(float, SoundSource)

    • calculateVolume

      private float calculateVolume(float pVolumeMultiplier, SoundSource pSource)
      Calculates the volume of the sound being played.

      Clamps the sound between 0.0f and 1.0f.

    • pauseAllExcept

      public void pauseAllExcept(SoundSource... pSoundSources)
    • resume

      public void resume()
    • playDelayed

      public void playDelayed(SoundInstance pSound, int pDelay)
      Adds a sound to play in n ticks
    • updateSource

      public void updateSource(Camera pRenderInfo)
    • stop

      public void stop(@Nullable ResourceLocation pSoundName, @Nullable SoundSource pCategory)
    • getDebugString

      public String getDebugString()
    • getAvailableSoundDevices

      public List<String> getAvailableSoundDevices()
    • getListenerTransform

      public ListenerTransform getListenerTransform()