System responsible for managing audio playback, mixing, and spatialization. More...
#include <AudioSystem.hpp>
Classes | |
| struct | StandaloneAudio |
Public Member Functions | |
| AudioSystem (vex::Registry ®) | |
| Constructor for AudioSystem. | |
| void | Init (vex::VirtualFileSystem *vfs) |
| Initializes the audio subsystem and binding to the VFS. | |
| void | Update (vex::Entity cameraEntity) |
| Main update loop for the audio system. | |
| void | Shutdown () |
| Shuts down the audio system. | |
| void | PlaySound2D (const std::string &filePath, float volume=1.0f, float pitch=1.0f, bool loop=false) |
| Quickly plays a 2D sound without requiring an entity or AudioSourceComponent. | |
Private Member Functions | |
| void | OnAudioComponentDestroyed (vex::Registry ®istry, vex::Entity entity) |
| Callback triggered when an AudioSourceComponent is destroyed. | |
Private Attributes | |
| SDL_AudioDeviceID | deviceID |
| VirtualFileSystem * | vfs = nullptr |
| vex::Registry & | registry |
| std::unordered_map< std::string, std::unique_ptr< AudioClip > > | clipCache |
| Cache of loaded audio clips to prevent reloading the same file multiple times. Key is the file path. | |
| std::unordered_map< vex::Entity, SDL_AudioStream * > | streamMap |
| Map linking entities to their active SDL audio streams. | |
| std::vector< StandaloneAudio > | standaloneStreams |
System responsible for managing audio playback, mixing, and spatialization.
Handles the lifecycle of SDL audio streams, loads audio clips via the VirtualFileSystem, and updates audio properties (volume, pitch, 3D position) every frame.
Definition at line 27 of file AudioSystem.hpp.
| vex::AudioSystem::AudioSystem | ( | vex::Registry & | reg | ) |
Constructor for AudioSystem.
| vex::Registry& | reg - Reference to the main EnTT registry used for component lookups. |
Definition at line 55 of file AudioSystem.cpp.
| void vex::AudioSystem::Init | ( | vex::VirtualFileSystem * | vfs | ) |
Initializes the audio subsystem and binding to the VFS.
Sets up the SDL audio subsystem, opens the default playback device, and connects the component destruction signal to handle automatic stream cleanup.
| vex::VirtualFileSystem* | vfs - Pointer to the initialized VirtualFileSystem for loading audio assets. |
Definition at line 58 of file AudioSystem.cpp.
|
private |
Callback triggered when an AudioSourceComponent is destroyed.
Ensures the associated SDL audio stream is destroyed to prevent memory leaks or playing "ghost" audio.
| vex::Registry& | registry - The registry where the destruction occurred. |
| vex::Entity | entity - The entity that was destroyed or had the component removed. |
Definition at line 198 of file AudioSystem.cpp.
| void vex::AudioSystem::PlaySound2D | ( | const std::string & | filePath, |
| float | volume = 1.0f, | ||
| float | pitch = 1.0f, | ||
| bool | loop = false ) |
Quickly plays a 2D sound without requiring an entity or AudioSourceComponent.
Creates Standalone stream for the sound, plays it, and automatically cleans up when playback completes.
| const | std::string& filePath - Path to the audio file to play. |
| float | volume - Volume level (default 1.0f). Range: 0.0 - 1.0+ |
| float | pitch - Pitch/speed multiplier (default 1.0f). Range: > 0.0 |
| bool | loop - Whether the sound should loop (default false). |
Definition at line 206 of file AudioSystem.cpp.
| void vex::AudioSystem::Shutdown | ( | ) |
Shuts down the audio system.
Destroys all active audio streams, clears the clip cache, and closes the SDL audio device.
Definition at line 184 of file AudioSystem.cpp.
| void vex::AudioSystem::Update | ( | vex::Entity | cameraEntity | ) |
Main update loop for the audio system.
Iterates over all entities with AudioSourceComponents. It handles:
| vex::Entity | cameraEntity - The entity representing the listener (usually the active camera) for 3D calculations. |
Definition at line 72 of file AudioSystem.cpp.
|
private |
Cache of loaded audio clips to prevent reloading the same file multiple times. Key is the file path.
Definition at line 76 of file AudioSystem.hpp.
|
private |
Definition at line 71 of file AudioSystem.hpp.
|
private |
Definition at line 73 of file AudioSystem.hpp.
|
private |
Definition at line 94 of file AudioSystem.hpp.
|
private |
Map linking entities to their active SDL audio streams.
Definition at line 79 of file AudioSystem.hpp.
|
private |
Definition at line 72 of file AudioSystem.hpp.