Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
SoundEngine.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/client/sound/SoundMapping.h"
7#include "mc/client/sound/VolumeMultipliers.h"
8#include "mc/deps/audio/SoundEventRepository.h"
9#include "mc/deps/audio/SoundPauseSource.h"
10#include "mc/deps/audio/SoundPlayerInterface.h"
11#include "mc/deps/core/file/PathBuffer.h"
12#include "mc/deps/core/utility/NonOwnerPointer.h"
13#include "mc/deps/core/utility/UniqueOwnerPointer.h"
14#include "mc/deps/core/utility/pub_sub/Connector.h"
15#include "mc/deps/core/utility/pub_sub/Subscription.h"
16#include "mc/deps/game_refs/WeakRef.h"
17
18// auto generated forward declare list
19// clang-format off
20class IFileAccess;
26class SoundEvent;
27class SoundItem;
29class SoundSystemBase;
32class Vec3;
33struct ListenerState;
36struct PlayMusicOptions;
37struct PlaySoundOptions;
40namespace Audio { class OnlineAudioStream; }
41namespace Audio { class OnlineAudioStreamManager; }
42namespace Audio { class SoundStartOptions; }
43namespace Bedrock::Resources { class PreloadedPathHandle; }
44namespace Core { class FileSystem; }
45namespace Core { class Path; }
46namespace Core { class PathView; }
47// clang-format on
48
50public:
51 // SoundEngine inner types define
52 enum class MusicVolumeSource : uint64 {
53 CurrentTrack = 0,
54 Option = 1,
55 MusicCommand = 2,
56 BiomeDuck = 3,
57 JukeboxDuck = 4,
58 Count = 5,
59 };
60
61 using SoundEventQueue = ::std::vector<::std::pair<::std::string, ::std::shared_ptr<::SoundEvent>>>;
62
63 using ListenerStatesSpan = ::gsl::span<::std::pair<int, ::ListenerState>>;
64
65public:
66 // member variables
67 // NOLINTBEGIN
68 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::SoundSystemBase>> const> mSoundSystem;
69 ::ll::TypedStorage<8, 64, ::std::unordered_set<uint64>> mFrameUniqueSoundSet;
70 ::ll::TypedStorage<8, 144, ::SoundEventRepository> mSoundEventRepository;
71 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::IReadWriteOptions>> mOptions;
72 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::TextToSpeechClient>> mTTSClient;
73 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mMainVolumeOptionSubscription;
74 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mSoundVolumeOptionSubscription;
75 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mMusicVolumeOptionSubscription;
76 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mTextToSpeechVolumeOptionSubscription;
77 ::ll::TypedStorage<8, 16, ::Bedrock::PubSub::Subscription> mOnPauseStateChangeSubscription;
78 ::ll::TypedStorage<8, 24, ::std::vector<::Bedrock::PubSub::Subscription>> mSoundCategoryVolumeOptionSubscriptions;
79 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::ResourcePackManager>> mResourceManager;
80 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::LinkedAssetValidator>> mLinkedAssetValidator;
81 ::ll::TypedStorage<4, 140, ::VolumeMultipliers<5>> mMusicVolumeMultipliers;
82 ::ll::TypedStorage<4, 4, float> mMainVolume;
83 ::ll::TypedStorage<4, 4, float> mTTSVolume;
84 ::ll::TypedStorage<1, 1, bool> mMuted;
85 ::ll::TypedStorage<1, 1, bool> mFadeToStopMusic;
86 ::ll::TypedStorage<1, 1, bool> mSoundsReady;
87 ::ll::TypedStorage<8, 392, ::SoundMapping> mSounds;
88 ::ll::TypedStorage<8, 16, ::Bedrock::UniqueOwnerPointer<::Audio::OnlineAudioStreamManager>> mOnlineStreamManager;
89 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::StreamingAudioExperiment> const> mStreamingExperiment;
90 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::Core::FileSystem>> mFileSystem;
91 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::IFileAccess>> mFileAccess;
92 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDataPath;
93 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::SoundLoadScheduler>> const> mSoundLoadScheduler;
94 ::ll::TypedStorage<8, 8, ::std::shared_mutex> mResourceLoadManagerMutex;
95 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::ResourceLoadManager>> mResourceLoadManager;
96 // NOLINTEND
97
98public:
99 // virtual functions
100 // NOLINTBEGIN
101 virtual ~SoundEngine() /*override*/ = default;
102
103 virtual void pauseMusic(bool state) /*override*/;
104
105 virtual uint64 play(
106 ::std::string const& name,
107 ::Vec3 const& pos,
108 float volume,
109 float pitch,
110 ::std::optional<::ServerSoundHandle> serverSoundHandle
111 ) /*override*/;
112
113 virtual uint64 play(::PlaySoundOptions options) /*override*/;
114
115 virtual void stop(::std::string const& name) /*override*/;
116
117 virtual void stop(uint64 handle) /*override*/;
118
119 virtual void stop(::ServerSoundHandle serverSoundHandle) /*override*/;
120
121 virtual void setVolume(::ServerSoundHandle serverSoundHandle, float volume) /*override*/;
122
123 virtual void setPitch(::ServerSoundHandle serverSoundHandle, float pitch) /*override*/;
124
125 virtual void fade(::ServerSoundHandle serverSoundHandle, float duration, float targetVolume) /*override*/;
126
127 virtual void setPlaybackPosition(::ServerSoundHandle serverSoundHandle, float seconds) /*override*/;
128
129 virtual void pause(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source) /*override*/;
130
131 virtual void resume(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source) /*override*/;
132
133 virtual void stopAllSounds() /*override*/;
134
135 virtual void pauseAllPlayingSounds(::SoundPauseSource source) /*override*/;
136
137 virtual void resumeAllPreviouslyPlayingSounds(::SoundPauseSource source) /*override*/;
138
139 virtual ::std::optional<::std::string> getSubtitle(::std::string const& name) const /*override*/;
140
141 virtual uint64 playUI(::std::string const& name, float volume, float pitch) /*override*/;
142
143 virtual void playMusic(::PlayMusicOptions options) /*override*/;
144
145 virtual void playMusic(::PlayMusicOptions options, uint& playlistIndex) /*override*/;
146
147 virtual bool isLoadingMusic() const /*override*/;
148
149 virtual bool isPlayingMusicEvent(::std::string const& eventName) const /*override*/;
150
151 virtual bool isPlayingMusic(::Core::PathView soundPath) const /*override*/;
152
153 virtual void fadeToStopMusic(float fadeSeconds) /*override*/;
154
155 virtual void setMusicCommandVolumeMultiplier(float volumeMultiplier) /*override*/;
156
157 virtual void fadeOut(uint64 handle, float duration) /*override*/;
158
159 virtual void stopMusic() /*override*/;
160
161 virtual uint64 registerLoop(
162 ::std::string const& name,
163 ::std::function<void(::LoopingSoundState&)> getSoundState,
164 float fadeInDuration,
165 float fadeOutDuration
166 ) /*override*/;
167
168 virtual void unregisterLoop(uint64 handle, bool hard) /*override*/;
169
170 virtual bool isPlayingSound(uint64 handle) const /*override*/;
171
172 virtual bool isPlayingSound(::Core::Path const& soundName) const /*override*/;
173
174 virtual bool isPlayingSound(::ServerSoundHandle serverSoundHandle) const /*override*/;
175
176 virtual bool wasSoundStoppedExplicitly(::ServerSoundHandle serverSoundHandle) const /*override*/;
177
178 virtual uint64 playAttached(
179 ::std::string const& eventName,
180 ::std::function<void(::SoundInstanceProperties&)>&& getSoundProperties
181 ) /*override*/;
182
183 virtual bool getItem(::std::string const& eventName, ::Core::PathView soundPath, ::SoundItem& soundItem) const
184 /*override*/;
185
186 virtual ::Core::PathView getCurrentlyPlayingMusicPath() const /*override*/;
187
188 virtual void displaySoundEngineStats(::std::string& debugOutputFormat) const;
189
190 virtual ::std::optional<::PlayingSoundAttributes> tryGetPlayingSoundAttributes(uint64 handle) const /*override*/;
191
192 virtual ::std::optional<::PlayingSoundAttributes>
193 tryGetPlayingSoundAttributes(::ServerSoundHandle serverSoundHandle) const /*override*/;
194
195 virtual ::std::optional<::LoopingSoundAttributes> tryGetLoopingSoundAttributes(uint64 handle) const /*override*/;
196 // NOLINTEND
197
198public:
199 // member functions
200 // NOLINTBEGIN
201 MCNAPI void _playMusic(::PlayMusicOptions options, ::SoundItem soundItem);
202
203 MCNAPI void load(
204 bool,
205 ::Bedrock::NonOwnerPointer<::LinkedAssetValidator> validator,
206 ::std::shared_ptr<::std::vector<::Bedrock::Resources::PreloadedPathHandle>> preloadHandles
207 );
208
209 MCAPI uint64 playFromMemory(
210 ::Core::Path const& soundName,
211 char const* data,
212 uint64 dataSize,
213 bool is3D,
214 float minDistance,
215 float maxDistance,
216 float volume,
217 float pitch,
218 bool useLegacyMaxDistance,
219 bool isTTS
220 );
221
222 MCNAPI uint64 playOnlineMusic(
223 ::std::string const& eventName,
224 ::WeakRef<::Audio::OnlineAudioStream> stream,
225 float volume,
226 ::Audio::SoundStartOptions startOptions
227 );
228
229 MCNAPI void registerPauseManagerCallback(::Bedrock::PubSub::Connector<void(bool)>& connector);
230
232
233 MCNAPI void setOptions(::std::shared_ptr<::IReadWriteOptions> options);
234
235 MCNAPI void setTTSClient(::std::shared_ptr<::TextToSpeechClient> ttsClient);
236
237 MCNAPI void update(::gsl::span<::std::pair<int, ::ListenerState>> listenerStates, float elapsedTime);
238 // NOLINTEND
239
240public:
241 // virtual function thunks
242 // NOLINTBEGIN
243 MCNAPI void $pauseMusic(bool state);
244
245 MCNAPI uint64 $play(
246 ::std::string const& name,
247 ::Vec3 const& pos,
248 float volume,
249 float pitch,
250 ::std::optional<::ServerSoundHandle> serverSoundHandle
251 );
252
253 MCNAPI uint64 $play(::PlaySoundOptions options);
254
255 MCNAPI void $stop(::std::string const& name);
256
257 MCNAPI void $stop(uint64 handle);
258
259 MCNAPI void $stop(::ServerSoundHandle serverSoundHandle);
260
261 MCNAPI void $setVolume(::ServerSoundHandle serverSoundHandle, float volume);
262
263 MCNAPI void $setPitch(::ServerSoundHandle serverSoundHandle, float pitch);
264
265 MCNAPI void $fade(::ServerSoundHandle serverSoundHandle, float duration, float targetVolume);
266
267 MCNAPI void $setPlaybackPosition(::ServerSoundHandle serverSoundHandle, float seconds);
268
269 MCNAPI void $pause(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source);
270
271 MCNAPI void $resume(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source);
272
273 MCNAPI void $stopAllSounds();
274
275 MCNAPI void $pauseAllPlayingSounds(::SoundPauseSource source);
276
277 MCNAPI void $resumeAllPreviouslyPlayingSounds(::SoundPauseSource source);
278
279 MCNAPI ::std::optional<::std::string> $getSubtitle(::std::string const& name) const;
280
281 MCNAPI uint64 $playUI(::std::string const& name, float volume, float pitch);
282
283 MCNAPI void $playMusic(::PlayMusicOptions options);
284
285 MCNAPI void $playMusic(::PlayMusicOptions options, uint& playlistIndex);
286
287 MCNAPI bool $isLoadingMusic() const;
288
289 MCNAPI bool $isPlayingMusicEvent(::std::string const& eventName) const;
290
291 MCNAPI bool $isPlayingMusic(::Core::PathView soundPath) const;
292
293 MCNAPI void $fadeToStopMusic(float fadeSeconds);
294
295 MCNAPI void $setMusicCommandVolumeMultiplier(float volumeMultiplier);
296
297 MCNAPI void $fadeOut(uint64 handle, float duration);
298
299 MCNAPI void $stopMusic();
300
301 MCAPI uint64 $registerLoop(
302 ::std::string const& name,
303 ::std::function<void(::LoopingSoundState&)> getSoundState,
304 float fadeInDuration,
305 float fadeOutDuration
306 );
307
308 MCNAPI void $unregisterLoop(uint64 handle, bool hard);
309
310 MCNAPI bool $isPlayingSound(uint64 handle) const;
311
312 MCNAPI bool $isPlayingSound(::Core::Path const& soundName) const;
313
314 MCNAPI bool $isPlayingSound(::ServerSoundHandle serverSoundHandle) const;
315
316 MCNAPI bool $wasSoundStoppedExplicitly(::ServerSoundHandle serverSoundHandle) const;
317
318 MCNAPI uint64 $playAttached(
319 ::std::string const& eventName,
320 ::std::function<void(::SoundInstanceProperties&)>&& getSoundProperties
321 );
322
323 MCNAPI bool $getItem(::std::string const& eventName, ::Core::PathView soundPath, ::SoundItem& soundItem) const;
324
325 MCNAPI ::Core::PathView $getCurrentlyPlayingMusicPath() const;
326
327 MCNAPI void $displaySoundEngineStats(::std::string& debugOutputFormat) const;
328
329 MCNAPI ::std::optional<::PlayingSoundAttributes> $tryGetPlayingSoundAttributes(uint64 handle) const;
330
331 MCNAPI ::std::optional<::PlayingSoundAttributes>
333
334 MCNAPI ::std::optional<::LoopingSoundAttributes> $tryGetLoopingSoundAttributes(uint64 handle) const;
335 // NOLINTEND
336};
Definition OnlineAudioStreamManager.h:23
Definition OnlineAudioStream.h:7
Definition SoundStartOptions.h:7
Definition PreloadedPathHandle.h:16
Definition Connector.h:19
Definition FileSystem.h:28
Definition PathView.h:19
Definition Path.h:10
Definition IFileAccess.h:15
Definition IReadWriteOptions.h:5
Definition LinkedAssetValidator.h:9
Definition Path.h:16
Definition ResourceLoadManager.h:22
Definition ResourcePackManager.h:29
Definition ServerSoundHandle.h:5
Definition SoundEngine.h:5
MCAPI void $pauseMusic(bool state)
MCAPI void $stop(::std::string const &name)
MCAPI bool $isPlayingSound(uint64 handle) const
MCAPI void $resume(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source)
MCAPI void update(::gsl::span<::std::pair< int, ::ListenerState > > listenerStates, float elapsedTime)
MCAPI uint64 $play(::std::string const &name, ::Vec3 const &pos, float volume, float pitch, ::std::optional<::ServerSoundHandle > serverSoundHandle)
MCAPI void $pauseAllPlayingSounds(::SoundPauseSource source)
MCAPI uint64 $playUI(::std::string const &name, float volume, float pitch)
MCAPI void _playMusic(::PlayMusicOptions options, ::SoundItem soundItem)
MCAPI ::std::optional<::PlayingSoundAttributes > $tryGetPlayingSoundAttributes(uint64 handle) const
MCAPI void $playMusic(::PlayMusicOptions options)
MCAPI void $fade(::ServerSoundHandle serverSoundHandle, float duration, float targetVolume)
MCAPI void $fadeToStopMusic(float fadeSeconds)
MCAPI void $pause(::ServerSoundHandle serverSoundHandle, ::SoundPauseSource source)
MCAPI bool $getItem(::std::string const &eventName, ::Core::PathView soundPath, ::SoundItem &soundItem) const
MCAPI uint64 $playAttached(::std::string const &eventName, ::std::function< void(::SoundInstanceProperties &)> &&getSoundProperties)
MCAPI void $setVolume(::ServerSoundHandle serverSoundHandle, float volume)
MCAPI void $fadeOut(uint64 handle, float duration)
MCAPI void $setPlaybackPosition(::ServerSoundHandle serverSoundHandle, float seconds)
MCAPI bool $isPlayingMusicEvent(::std::string const &eventName) const
MCAPI void $resumeAllPreviouslyPlayingSounds(::SoundPauseSource source)
MCAPI ::std::optional<::LoopingSoundAttributes > $tryGetLoopingSoundAttributes(uint64 handle) const
MCAPI void $stopMusic()
MCAPI void $unregisterLoop(uint64 handle, bool hard)
MCAPI bool $isLoadingMusic() const
MCAPI void setOptions(::std::shared_ptr<::IReadWriteOptions > options)
MCAPI uint64 playOnlineMusic(::std::string const &eventName, ::WeakRef<::Audio::OnlineAudioStream > stream, float volume, ::Audio::SoundStartOptions startOptions)
MCAPI void $setPitch(::ServerSoundHandle serverSoundHandle, float pitch)
MCAPI void load(bool, ::Bedrock::NonOwnerPointer<::LinkedAssetValidator > validator, ::std::shared_ptr<::std::vector<::Bedrock::Resources::PreloadedPathHandle > > preloadHandles)
MCAPI void $setMusicCommandVolumeMultiplier(float volumeMultiplier)
MCAPI bool $wasSoundStoppedExplicitly(::ServerSoundHandle serverSoundHandle) const
MCAPI void registerPauseManagerCallback(::Bedrock::PubSub::Connector< void(bool)> &connector)
MCAPI void $stopAllSounds()
MCAPI void releaseSoundFileHandles()
MCAPI bool $isPlayingMusic(::Core::PathView soundPath) const
MCAPI ::std::optional<::std::string > $getSubtitle(::std::string const &name) const
MCAPI void $displaySoundEngineStats(::std::string &debugOutputFormat) const
MCAPI::Core::PathView $getCurrentlyPlayingMusicPath() const
MCAPI void setTTSClient(::std::shared_ptr<::TextToSpeechClient > ttsClient)
Definition SoundEvent.h:10
Definition SoundItem.h:5
Definition SoundLoadScheduler.h:5
Definition SoundPlayerInterface.h:24
Definition SoundSystemBase.h:31
Definition StreamingAudioExperiment.h:11
Definition TextToSpeechClient.h:5
Definition Vec3.h:10
Definition WeakRef.h:8
STL namespace.
Definition ListenerState.h:5
Definition LoopingSoundAttributes.h:8
Definition LoopingSoundState.h:5
Definition PlayMusicOptions.h:5
Definition PlaySoundOptions.h:10
Definition PlayingSoundAttributes.h:5
Definition SoundInstanceProperties.h:5