VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtProceduralSound.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvAudio/vrvAudio.h>
13 #include <vrvAudio/DtAudioLevel.h>
15 
16 #include <vrvCore/DtUniqueID.h>
17 
18 #include <matrix/vlVector.h>
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 namespace makAudio
26 {
27  class DtSound;
28  class DtStreamSource;
29 }
30 
31 namespace makVrv
32 {
33  class DtDe;
34  class DtProceduralSoundBehavior;
35 
62  {
63  public:
69  virtual ~DtProceduralSound();
70 
71  DtProceduralSound(const DtProceduralSound&) = delete;
72  DtProceduralSound& operator=(const DtProceduralSound&) = delete;
73 
74  // -----------------------------------------------------------------------
75  // Layer management
76  // -----------------------------------------------------------------------
77 
80  virtual DtProceduralSoundLayer& addLayer(const std::string& name);
81 
83  virtual DtProceduralSoundLayer* getLayer(const std::string& name);
84 
86  virtual const std::map<std::string, DtProceduralSoundLayer>& layers() const;
87 
89  virtual void setBehaviorOnAllLayers(DtProceduralSoundBehavior* behavior);
90 
92  virtual void setProximityFactorOnAllLayers(float factor);
93 
97  virtual int queuedChunks() const;
98 
99  // -----------------------------------------------------------------------
100  // Playback control
101  // -----------------------------------------------------------------------
102 
107  virtual bool play();
108 
110  virtual void pause();
111 
122  virtual void stop();
123 
125  virtual bool isPlaying() const;
126 
127  // -----------------------------------------------------------------------
128  // Per-frame update
129  // -----------------------------------------------------------------------
130 
141  virtual void setDecibel(float relativeDb);
142 
151  virtual void setMinAudibleDistance(float minDistM);
152 
161  virtual void setMaxAudibleDistance(float maxDistM);
162 
163  // -----------------------------------------------------------------------
164  // 3D positional audio (may be configured before the first play() call
165  // or toggled at any time on the live source - the existing DtSound is
166  // updated in place via setIs3d())
167  // -----------------------------------------------------------------------
168 
176  virtual void setIs3d(bool is3d);
177 
179  virtual bool is3d() const;
180 
186  virtual void setPosition(const DtVector& position);
187 
191  virtual void setVelocity(const DtVector& velocity);
192 
203  virtual void tick(double dt, float densityScale);
204 
205  // -----------------------------------------------------------------------
206  // Configuration (must be set before the first play() call)
207  // -----------------------------------------------------------------------
208 
211  virtual void setSampleRate(unsigned int rate);
212  virtual unsigned int sampleRate() const;
213 
216  virtual void setChunkDuration(float seconds);
217  virtual float chunkDuration() const;
218 
239  virtual void setSoftStartDuration(float seconds);
240  virtual float softStartDuration() const;
241 
242  protected:
246  virtual void initializeSound();
247 
254  virtual void produceChunk(int numSamples, float densityScale);
255 
262  virtual makAudio::DtStreamSource* resolveStream() const;
263 
266 
267  std::map<std::string, DtProceduralSoundLayer> myLayers;
268 
270  std::unique_ptr<makAudio::DtSound> mySound;
271 
272  unsigned int myOutputSampleRate = 44100;
273  float myChunkDuration = 0.1f;
274  bool myIsPlaying = false;
275 
277  float myPendingDecibel = 0.0f;
278 
283  float myMinAudibleDistanceM = DtAudioLevel::kUseDefaultDistance;
284 
289  float myMaxAudibleDistanceM = DtAudioLevel::kUseDefaultDistance;
290 
292  bool myIs3d = false;
294  DtVector myPosition;
296  DtVector myVelocity;
297 
299  std::vector<float> myScratch;
300 
301  static constexpr int kMaxQueuedChunks = 4;
302 
303  private:
307  void armSoftStart();
308 
310  float mySoftStartDurationSec = 1.0f;
312  int mySoftStartSamplesRemaining = 0;
314  int mySoftStartTotalSamples = 0;
318  float mySoftStartCurrentGain = 1.0f;
322  float mySoftStartGainStep = 1.0f;
323 
324  };
325 
326 } // namespace makVrv
Contains makVrv::DtProceduralSoundLayer class.
std::map< std::string, DtProceduralSoundLayer > myLayers
Definition: DtProceduralSound.h:267
std::unique_ptr< makAudio::DtSound > mySound
Underlying streaming sound. Null until play() succeeds.
Definition: DtProceduralSound.h:270
Contains the DLL export macro for vrvAudio classes.
Composes multiple DtProceduralSoundLayer pools into one streaming ambient sound.
Definition: DtProceduralSound.h:61
DtDe & myDe
Definition: DtProceduralSound.h:264
DtUniqueID myId
Definition: DtProceduralSound.h:265
static constexpr float kUseDefaultDistance
Sentinel value meaning &quot;leave this distance at the underlying audio engine&#39;s default&quot;...
Definition: DtAudioLevel.h:107
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
std::vector< float > myScratch
Reused scratch buffer (float32) - avoids per-chunk heap allocation.
Definition: DtProceduralSound.h:299
DtVector myVelocity
World-space source velocity for Doppler, applied when myIs3d is true.
Definition: DtProceduralSound.h:296
Optional per-channel behavior hook for DtProceduralSoundPlayer.
Definition: DtProceduralSoundBehavior.h:40
DtVector myPosition
World-space source position, applied when myIs3d is true.
Definition: DtProceduralSound.h:294
Contains makVrv::DtUniqueID type.
#define DT_DLL_VRVAUDIO
Definition: vrvAudio.h:20
One pool of randomly-triggered WAV clips that can be mixed into a DtProceduralSound.
Definition: DtProceduralSoundLayer.h:37
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
Contains the DtAudioLevel utility class.

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)