![]() |
VR-Forces Developer's Guide
|
One pool of randomly-triggered WAV clips that can be mixed into a DtProceduralSound.
Each DtProceduralSoundLayer owns a collection of pre-loaded mono float32 PCM clips. On each call to mix(), the layer:
Multiple layers mix into the same scratch buffer to produce rich ambient audio from a single OpenAL voice (one per DtProceduralSound).
Classes | |
| struct | DtActiveEvent |
| struct | DtClipData |
Public Member Functions | |
| DtProceduralSoundLayer () | |
| virtual | ~DtProceduralSoundLayer () |
| DtProceduralSoundLayer (const DtProceduralSoundLayer &)=delete | |
| DtProceduralSoundLayer & | operator= (const DtProceduralSoundLayer &)=delete |
| DtProceduralSoundLayer (DtProceduralSoundLayer &&)=default | |
| DtProceduralSoundLayer & | operator= (DtProceduralSoundLayer &&)=default |
| virtual bool | addClip (const std::string &wavFile, float weight=1.0f, float decibelsDb=0.0f) |
| virtual int | addClipsFrom (const DtProceduralSoundLayer &src) |
| virtual void | setDensity (float eventsPerSecond) |
| virtual float | density () const |
| virtual void | setFixedParallelEvents (int count) |
| virtual int | fixedParallelEvents () const |
| virtual float | weightedMeanClipDurationSeconds () const |
| virtual void | setGainRange (float minGain, float maxGain) |
| virtual void | setPitchRange (float minPitch, float maxPitch) |
| virtual void | setMasterGain (float g) |
| virtual float | masterGain () const |
| virtual void | resetPlayback () |
| virtual void | triggerEvent (unsigned int outputSampleRate, float gain=1.0f, float pitchFactor=1.0f) |
| virtual void | setBehavior (DtProceduralSoundBehavior *behavior) |
| virtual DtProceduralSoundBehavior * | behavior () const |
| virtual void | setProximityFactor (float factor) |
| virtual int | clipCount () const |
| virtual int | activeEventCount () const |
| virtual std::vector< float > | activeEventProgresses () const |
| virtual float | timeUntilNextEvent () const |
| virtual float | minGain () const |
| virtual float | maxGain () const |
| virtual float | minPitch () const |
| virtual float | maxPitch () const |
| virtual int | lastPickedClipIndex () const |
| virtual std::string | clipBasename (int index) const |
| virtual float | behaviorCurrentLinearGain () const |
| virtual bool | behaviorIsActive () const |
| virtual void | mix (std::vector< float > &accumBuffer, int numSamples, float dt, unsigned int sampleRate, float densityScale) |
Protected Member Functions | |
| virtual void | rebuildWeightTable () |
| virtual void | recomputeDensityFromFixed () |
| virtual int | pickClip () |
| virtual float | randomFloat (float minVal, float maxVal) |
| virtual float | scheduleNextInterval (float effectiveDensity) |
| virtual void | fireEvent (unsigned int outputSampleRate, float startOffset=0.0f, float startFadeGain=1.0f, float fadeRate=0.0f) |
| DtProceduralSoundBehaviorContext | buildContext (float dt) const |
Protected Attributes | |
| std::vector< DtClipData > | myClips |
| std::vector< float > | myCumulativeWeights |
| std::vector< DtActiveEvent > | myActiveEvents |
| float | myDensity = 1.0f |
| int | myFixedParallelEvents = 0 |
| float | myWeightedMeanDurationSecs = 0.0f |
| float | myMinGain = 0.2f |
| float | myMaxGain = 1.0f |
| float | myMinPitch = 1.0f |
| float | myMaxPitch = 1.0f |
| float | myMasterGain = 1.0f |
| int | myLastPickedClipIndex = -1 |
| float | myEventTimer = 0.0f |
| DtProceduralSoundBehavior * | myBehavior = nullptr |
| float | myProximityFactor = 0.0f |
| std::mt19937 | myRng |
| makVrv::DtProceduralSoundLayer::DtProceduralSoundLayer | ( | ) |
Default constructor.
|
virtual |
Destructor. Releases all loaded PCM clip data.
|
delete |
Not copyable.
|
default |
Move-constructible; required so std::map can value-construct it.
|
delete |
Not assignable.
|
default |
Move-assignable.
|
virtual |
Load a WAV clip and add it to this layer's pool.
The file is decoded to mono float32 PCM (normalized to [-1.0f, 1.0f]) and held in memory. Supported source formats: 8-bit unsigned PCM, 16-bit signed PCM, and 32-bit float PCM. All clips in one layer should share the same sample rate; a warning is emitted for mismatches (the clip is still added).
| wavFile | Fully-resolved filesystem path to a .wav file. |
| weight | Relative selection probability (default 1.0). |
| decibelsDb | Absolute recorded reference level of this clip in dB; applied per-event as 10^(dB/20) linear gain at fireEvent time, stacking with the layer's per-event random gain and tier master gain. Default 0.0. |
Referenced by makVrv::DtForestSoundCreator::create().
|
virtual |
Copy all clips from src into this layer's pool.
Used when a tier source is a ProceduralSound registry key: the caller creates a temporary DtProceduralSound via the factory, then transfers its PCM data into this layer with addClipsFrom(). The PCM float arrays are copied; the source layer's settings (density, gain, pitch, behavior) are NOT transferred.
| src | Source layer to copy clips from. |
|
virtual |
Average number of sound events to trigger per second (Poisson rate). e.g. 1.5 ~ one event every 0.67 s; 40 = heavy-rain density. Calling this clears any previously set fixedParallelEvents.
|
virtual |
Current average events-per-second (Poisson rate).
|
virtual |
Set the exact number of clip instances that must be playing at all times. After each PCM chunk is advanced any finished events are immediately replaced, keeping the count fixed at count.
On first activation (cold fill) instances are staggered evenly across the clip duration so they don't start in phase.
This also derives a density used for Little's Law book-keeping: density = count / weightedMeanClipDuration.
Pass 0 to clear and revert to direct density (Poisson) mode.
Referenced by makVrv::DtForestSoundCreator::create().
|
virtual |
Current fixed parallel event count, or 0 if Poisson mode.
|
virtual |
Weighted-mean clip duration in seconds (read-only diagnostic). Equal to sum(weight_i * duration_i) / sum(weight_i) across all loaded clips. Returns 0 when no clips are loaded.
|
virtual |
Linear gain range for randomly triggered events [0.0, 1.0]. Quieter events simulate sources further from the listener.
Referenced by makVrv::DtForestSoundCreator::create().
|
virtual |
Pitch ratio range for randomly triggered events. 1.0 = original pitch. e.g. [0.92, 1.08] for natural variation. Pitch is implemented as a fractional sample-rate ratio (nearest-neighbor resampling); no FFT or high-quality resampler is used.
Referenced by makVrv::DtForestSoundCreator::create().
|
virtual |
Set the per-layer master gain multiplier.
Applied per-event in fireEvent() as a linear multiplier on top of the layer's per-event random gain and the per-clip dB->linear multiplier. Used by tiered behaviors (Rain, Wind, Visibility) to carry the tier's authored master gain into each fired event.
| g | Linear master gain (1.0 = no change; default is 1.0). |
|
virtual |
Return the per-layer master gain multiplier (default 1.0).
|
virtual |
Reset in-flight playback state so the next mix() starts from a clean cold fill. Called automatically by DtProceduralSound::stop(); you rarely need to call this directly.
|
virtual |
Immediately inject a single clip event, bypassing the Poisson scheduler.
Picks a clip at random (weighted) and starts it at the given gain and pitch. Intended for externally-triggered one-shot sounds (e.g. ballistic proximity). Does nothing if no clips are loaded.
The pitch ratio written to the event is computed as: pitchRatio = (clipSampleRate / outputSampleRate) * pitchFactor so that the nearest-neighbor resampler in mix() plays the clip at its native speed when pitchFactor == 1.0, regardless of the clip's original sample rate.
| outputSampleRate | Sample rate of the output stream in Hz (must be > 0). |
| gain | Linear amplitude scale for this event [0.0, 1.0]. |
| pitchFactor | Multiplier applied on top of the native pitch (1.0 = no shift). |
|
virtual |
Attach a behavior to this layer.
Non-owning: the layer never deletes the behavior pointer. The owner (DtProceduralSoundPlayer or the behavior itself) is responsible for lifetime management. Pass nullptr to remove any attached behavior.
| behavior | Behavior to attach, or nullptr to detach. |
|
virtual |
Return the currently attached behavior, or nullptr.
|
virtual |
Update the current proximity factor for use in the behavior context.
Called by DtProceduralSoundPlayer before each tick. The value is forwarded into the DtProceduralSoundBehaviorContext passed to all audio-thread callbacks.
| factor | Fade factor in [0.0, 1.0]; 1.0 = fully inside the feature polygon. |
|
virtual |
Number of WAV clips loaded into this layer's pool.
|
virtual |
Number of events currently playing (advancing their sample offset). Non-zero means audio is actively being mixed right now.
|
virtual |
Playback progress [0.0, 1.0] for each currently active event. Sorted by ascending progress so the display is stable. Empty when no events are active. Allocation is kept small - only called when the ImGui overlay is visible.
|
virtual |
Seconds until the next event is scheduled to fire. Counts down each mix() call; resets to a new random interval on each firing.
|
virtual |
Gain range accessors.
|
virtual |
|
virtual |
Pitch ratio range accessors (1.0 = original pitch).
|
virtual |
|
virtual |
Index of the most recently picked clip, or -1 before the first event.
|
virtual |
Basename of the clip at index as recorded at load time. Returns an empty string if index is out of range.
|
virtual |
Return the linear gain [0, 1] that the layer behavior's continuous gain curve currently applies at this moment. Returns 1.0 if no behavior is attached. Intended for debug display only; the authoritative value is computed inside mix() on the main thread.
|
virtual |
Return whether the layer behavior currently considers this layer active. Returns true if no behavior is attached.
|
virtual |
Mix this layer's active events into a float accumulation buffer.
| accumBuffer | Output buffer of numSamples float values. Caller must zero-fill before the first mix() call per chunk. |
| numSamples | Number of output samples to produce. |
| dt | Elapsed time in seconds for this chunk (used for Poisson scheduling). |
| sampleRate | Output sample rate in Hz. |
| densityScale | Runtime density multiplier from DtProceduralSoundscapeChannel. |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
| startOffset | Fractional sample position to begin playback from. 0.0 = clip start (normal). Used by fixed-parallel mode to stagger the initial fill evenly across the clip duration. |
| startFadeGain | Initial value of the crossfade envelope (default 1.0 = full volume). Pass 0.0 for a fade-in event so it starts silent and ramps up. |
| fadeRate | Per-sample additive change applied to fadeGain each output sample. Pass a positive value to fade in; 0.0 for no envelope (default). |
|
protected |
Build a behavior context from current layer state.
| dt | Elapsed time in seconds for this chunk (0.0 for non-scheduling calls). |
|
protected |
|
protected |
for O(log n) weighted selection
|
protected |
|
protected |
|
protected |
0 = Poisson mode
|
protected |
recomputed in rebuildWeightTable()
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Per-layer master gain multiplier applied per-event in fireEvent(). Default 1.0. Composes multiplicatively with the layer's per-event random gain, the per-clip dB->linear multiplier, and (per-sample) the behavior's continuous gain curve.
|
protected |
Index of the most recently picked clip (-1 before the first event).
|
protected |
Seconds remaining until the next event fires. Initialised to 0 so the first event fires on the first mix() call.
|
protected |
Optional behavior hook. Non-owning pointer; never deleted by this class.
|
protected |
Proximity factor in [0.0, 1.0] set by DtProceduralSoundPlayer each frame.
|
protected |