|
Engine²
Open-source game engine written in C++.
|
#include <SoundManager.hpp>
Classes | |
| struct | Sound |
| struct | TransparentHash |
| struct | TransparentEqual |
Public Member Functions | |
| SoundManager ()=default | |
| ~SoundManager () | |
| SoundManager (const SoundManager &)=delete | |
| SoundManager & | operator= (const SoundManager &)=delete |
| SoundManager (SoundManager &&other) noexcept | |
| SoundManager & | operator= (SoundManager &&other) noexcept |
| void | Init (Engine::Core &core) |
| Initialize the sound system. | |
| void | CheckCallbackErrors () |
| Check and log any deferred errors from the audio callback. | |
| void | RegisterSound (const std::string &soundName, const std::string &filePath, bool loop=false) |
| Register the provided sound file. | |
| void | UnregisterSound (const std::string &soundName) |
| Unregister the target sound file from the sound vector. | |
| void | Play (const std::string &soundName) |
| Play the target sound. | |
| void | Stop (const std::string &soundName) |
| Stop the target sound. | |
| void | Pause (const std::string &soundName) |
| Pause the target sound. | |
| bool | IsPlaying (const std::string &soundName) |
| Check if the target sound is playing. | |
| void | SetVolume (const std::string &soundName, float volume) |
| Set the volume of a specific sound. | |
| void | SetPitch (const std::string &soundName, float pitch) |
| Set the playback pitch (speed) for a sound. | |
| void | SetLoop (const std::string &soundName, bool shouldLoop) |
| Set whether the sound should loop. | |
| void | SetLoopPoints (const std::string &soundName, float startSeconds, float endSeconds=0) |
| Set the loop start and end points for a sound. | |
| double | GetPlayPosition (const std::string &soundName) |
| Get the current playback position of a sound in seconds. | |
| FunctionUtils::FunctionID | AddCustomCallback (const CustomDataCallback &callback) |
| bool | RemoveCustomCallback (FunctionUtils::FunctionID id) |
| Remove a custom audio callback by its ID. | |
| bool | HasCustomCallback (FunctionUtils::FunctionID id) const |
| Check if a custom callback exists by its ID. | |
| void | ClearCustomCallbacks () |
| Clear all custom callbacks. | |
Static Public Member Functions | |
| static void | data_callback (ma_device *pDevice, void *pOutput, const void *, ma_uint32 frameCount) |
| Audio data callback used by the playback device to fill the output buffer. | |
Private Attributes | |
| ma_result | _result |
| ma_device_config | _deviceConfig |
| ma_device | _device |
| bool | _deviceInit = false |
| ma_engine | _engine |
| bool | _engineInit = false |
| std::atomic< uint32_t > | _callbackErrorFlags {0} |
| std::unordered_map< std::string, Sound, TransparentHash, TransparentEqual > | _soundsToPlay |
| FunctionUtils::FunctionContainer< void, ma_device *, void *, ma_uint32 > | _customCallbacks |
Static Private Attributes | |
| static constexpr uint32_t | ERROR_FRAME_TOO_LARGE = 0x1 |
| static constexpr uint32_t | ERROR_DECODER_READ = 0x2 |
| static constexpr uint32_t | ERROR_UNKNOWN_FORMAT = 0x4 |
|
default |
Constructor.
| Sound::Resource::SoundManager::~SoundManager | ( | ) |
Destructor.
|
delete |
Deleted copy constructor (contains non-copyable FunctionContainer).
|
inlinenoexcept |
Move constructor.
|
inline |
|
inline |
Check and log any deferred errors from the audio callback.
Call this method periodically from the main thread (e.g., in an Update system) to report errors that occurred in the real-time audio callback without blocking it.
|
inline |
Clear all custom callbacks.
|
inlinestatic |
Audio data callback used by the playback device to fill the output buffer.
| pDevice | Pointer to the audio playback device. |
| pOutput | Pointer to the output buffer that will be filled with audio samples. |
| pInput | Unused input buffer (typically nullptr for playback-only). |
| frameCount | Number of audio frames that must be written to the output buffer. |
Custom callbacks are invoked first, then all playing sounds are mixed. The mix buffer is cleared initially and all sounds are mixed with their respective volumes. Format conversion supports f32, s32, s16, and u8 with saturated addition to prevent overflow.
|
inline |
Get the current playback position of a sound in seconds.
Return value is related to the absolute begin of the sound, not the start frame.
| soundName | The name of the target sound to query. |
|
inline |
Check if a custom callback exists by its ID.
| id | ID of the callback to check. |
|
inline |
Initialize the sound system.
|
inline |
Check if the target sound is playing.
| soundName | Name of the target sound |
|
delete |
Deleted copy assignment operator (contains non-copyable FunctionContainer).
|
inlinenoexcept |
Move assignment operator.
|
inline |
Pause the target sound.
| soundName | Name of the target sound to pause |
|
inline |
Play the target sound.
| soundName | Name of the target sound to play |
|
inline |
Register the provided sound file.
| soundName | Name to assign to the registered sound |
| filePath | Path of the sound file to register |
| loop | Set the sound param to loop, default: False |
|
inline |
Remove a custom audio callback by its ID.
| id | ID of the callback to remove. |
|
inline |
Set whether the sound should loop.
| soundName | Name of the sound. |
| shouldLoop | Whether the sound should loop. |
|
inline |
Set the loop start and end points for a sound.
| soundName | Name of the sound. |
| startSeconds | Time in seconds where the loop starts. |
| endSeconds | Time in seconds where the loop ends (0 = end of file). |
|
inline |
Set the playback pitch (speed) for a sound.
| soundName | Name of the sound. |
| pitch | Pitch factor (> 0), 1.0 = normal. |
|
inline |
Set the volume of a specific sound.
| soundName | Name of the sound. |
| volume | Volume level (0.0 = silent, 1.0 = full volume). |
|
inline |
Stop the target sound.
| soundName | Name of the target sound to stop |
|
inline |
Unregister the target sound file from the sound vector.
| soundName | Name of the target sound to remove |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |