![]() |
VR-Forces Developer's Guide
|
Manages the lifetime of a single audio source attached to an entity or world position.
A DtSoundComponent wraps either a file-based makAudio::DtSound or a procedural sound channel and integrates it into the DtSoundComponentSystem tick loop. Callers populate a DtSoundComponentData struct, call initialize(), then call play() to start playback.
Scene object attachment can be expressed either as a raw pointer (mySceneObject) or as a unique ID (mySceneObjectId). If only mySceneObjectId is set, the pointer is resolved lazily when createAndInitializeSound() first runs. If both are set, mySceneObject takes precedence.
Classes | |
| struct | DtSoundComponentData |
Public Types | |
| enum | DtSoundState { DtSoundState::STOPPED, DtSoundState::PAUSED, DtSoundState::PLAYED } |
Public Member Functions | |
| DtSoundComponent (DtDe &de, DtUniqueID id) | |
| virtual | ~DtSoundComponent () |
| virtual void | initialize (const DtSoundComponentData &soundData) |
| virtual void | initialize (const std::string &modelDefinition) |
| virtual void | play () |
| virtual void | playOnce () |
| virtual void | pause () |
| virtual void | stop () |
| virtual makAudio::DtSound * | sound () |
| virtual const makAudio::DtSound * | sound () const |
| virtual void | setIs3d (bool is3d) |
| virtual void | setPosition (const DtVector &position) |
| virtual void | setDecibel (float decibels) |
| virtual void | setIsLooping (bool isLooping) |
| virtual void | setSceneObjectId (DtUniqueID sceneObjectId) |
| virtual void | setElementIdAndModelSet (DtElementID sceneObjectId, DtModelSetId modelSet) |
| virtual void | setModelSet (DtModelSetId modelSet) |
Static Public Member Functions | |
| static void | populateFromSoundSchema (const DtModelDefinition &definition, const DtDePathConfiguration &pathConfig, DtSoundComponentData &outData) |
Protected Member Functions | |
| virtual void | createAndInitializeSound () |
Protected Attributes | |
| DtDe & | myDe |
| DtUniqueID | myId |
| DtSoundComponentData | mySoundData |
| DtSoundComponentSystem & | mySystem |
| makAudio::DtSound * | mySound |
| DtProceduralSound * | myProceduralSound |
| bool | myIsAddedToSystem |
Friends | |
| class | DtSoundComponentSystem |
| class | DtSoundComponentSystemImGui |
|
strong |
Playback state of the sound component.
| Enumerator | |
|---|---|
| STOPPED |
Sound is stopped and will not play when added to the system. |
| PAUSED |
Sound is paused and will resume from the current position on play(). |
| PLAYED |
Sound is playing or will begin playing when added to the system. |
| makVrv::DtSoundComponent::DtSoundComponent | ( | DtDe & | de, |
| DtUniqueID | id | ||
| ) |
Constructs a DtSoundComponent owned by the given DE, identified by id.
| de | The distributed environment this component belongs to. |
| id | Unique identifier of the owning entity. |
|
virtual |
Destructor. Removes the component from DtSoundComponentSystem if still registered.
|
static |
Populate the six audio fields of a DtSoundComponentData from a Sound-schema model definition.
Reads sound_filepath (or legacy filename, or procedural_sound_name), isLooping, sound_decibels (clamped to unity with the same one-shot warning as initialize(std::string)), min_audible_distance_m, max_audible_distance_m, and sound_priority. Writes them into outData.mySoundDescriptor.mySoundFilename / myIsLooping, outData.myAuthoredDbfs, outData.myMinAudibleDistanceM, outData.myMaxAudibleDistanceM, and outData.myPriority. Pins outData.mySoundDescriptor.myDecibels to DtAudioLevel::kDefaultSourceSplDb.
Caller-owned fields on outData (myPosition, myVelocity, mySceneObject, mySceneObjectId, myModelSet, mySoundState, myIsInteraction, myBehaviorKey, myBehaviorParams, myLocalWeatherAreaEnabled) are NOT touched.
| [in] | definition | The model definition to read from. |
| [in] | pathConfig | The DE's path configuration used to resolve tokens and the MEAF fallback path for a raw filename. |
| [out] | outData | Populated on return. Fields not owned by the Sound schema (see above) are left untouched. |
|
virtual |
Initializes the component from a fully populated DtSoundComponentData struct.
| soundData | Configuration bundle describing the audio source and attachment. |
Has no effect if the component has already been added to the system. Must be called before play().
|
virtual |
Initializes the component by looking up a named model definition.
| modelDefinition | Name of a model definition that uses the Sound schema. |
Has no effect if the component has already been added to the system. The definition must contain a "filename" or "proceduralSoundscapeKey" parameter.
|
virtual |
Starts or resumes playback.
If the component has not yet been added to the DtSoundComponentSystem, it is added now. Audio creation for a 3D scene-object-attached component is deferred until the scene object has completed an update.
|
virtual |
Plays the sound once as a non-looping interaction, then stops.
For world-position sounds (no scene object), the sound is played immediately via the audio manager as a one-shot effect. For scene-object-attached sounds the component is added to the system with myIsInteraction set. Not supported for procedural sounds; use play() instead.
|
virtual |
Pauses playback without resetting the playback position.
|
virtual |
Stops playback and resets the playback position.
|
virtual |
Returns a non-owning pointer to the underlying makAudio::DtSound, or null if not yet created or if this is a procedural sound.
|
virtual |
Returns a const non-owning pointer to the underlying makAudio::DtSound.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
virtual |
Sets whether the sound is spatialized in 3D.
| is3d | True for 3D (positional) audio, false for 2D (screen-space) audio. |
|
virtual |
Sets the local-space or world-space position of the sound.
| position | World position (no scene object) or local offset from the scene object. |
Has no effect while a scene object is attached; position is derived from the object each frame in that case.
|
virtual |
Sets the volume level in decibels.
| decibels | Volume in dB relative to full scale (0 dB = full scale). |
|
virtual |
Sets whether the sound loops continuously.
| isLooping | True to loop; false to play once and stop. |
Looping cannot be changed at runtime for procedural sounds.
|
virtual |
Attaches the sound to a scene object identified by unique ID.
| sceneObjectId | Unique ID of the scene object to track. |
Resolves the ID to a DtSceneObject pointer immediately via the agent manager. Prefer setting DtSoundComponentData::mySceneObjectId before initialize() when lazy resolution is acceptable.
|
virtual |
Attaches the sound to a scene object looked up by element ID and model set.
| sceneObjectId | Element ID of the owning entity. |
| modelSet | Model set used to resolve the correct scene object instance. |
|
virtual |
Overrides the model set used for scene object resolution.
| modelSet | The new model set ID. |
|
protectedvirtual |
Creates and initializes the underlying audio resource.
Called by DtSoundComponentSystem during its tick. Resolves mySceneObjectId to a pointer if mySceneObject is not already set, creates the makAudio::DtSound, positions it, and begins playback according to mySoundState.
|
friend |
|
friend |
|
protected |
The distributed environment this component belongs to.
|
protected |
Unique identifier of the owning entity.
|
protected |
Current configuration and state for this audio source.
|
protected |
Reference to the singleton sound component system that drives this component each frame.
|
protected |
Owning pointer to the underlying audio object. Null until createAndInitializeSound() runs.
|
protected |
Non-owning pointer to the procedural sound, set by DtSoundComponentSystem when mySoundDescriptor.mySoundFilename begins with kProceduralSoundPrefix. Null for regular file-based sounds.
|
protected |
True once this component has been registered with DtSoundComponentSystem.