HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spatialAudio.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDMEDIA_GENERATED_SPATIALAUDIO_H
8 #define USDMEDIA_GENERATED_SPATIALAUDIO_H
9 
10 /// \file usdMedia/spatialAudio.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdMedia/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
18 
19 #include "pxr/base/vt/value.h"
20 
21 #include "pxr/base/gf/vec3d.h"
22 #include "pxr/base/gf/vec3f.h"
23 #include "pxr/base/gf/matrix4d.h"
24 
25 #include "pxr/base/tf/token.h"
26 #include "pxr/base/tf/type.h"
27 
29 
30 class SdfAssetPath;
31 
32 // -------------------------------------------------------------------------- //
33 // SPATIALAUDIO //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdMediaSpatialAudio
37 ///
38 /// The SpatialAudio primitive defines basic properties for encoding
39 /// playback of an audio file or stream within a USD Stage. The SpatialAudio
40 /// schema derives from UsdGeomXformable since it can support full spatial
41 /// audio while also supporting non-spatial mono and stereo sounds. One or
42 /// more SpatialAudio prims can be placed anywhere in the namespace, though it
43 /// is advantageous to place truly spatial audio prims under/inside the models
44 /// from which the sound emanates, so that the audio prim need only be
45 /// transformed relative to the model, rather than copying its animation.
46 ///
47 /// \section Usd_SpatialAudio_TimeScaling Timecode Attributes and Time Scaling
48 /// \a startTime and \a endTime are \ref SdfTimeCode "timecode" valued
49 /// attributes which gives them the special behavior that
50 /// \ref SdfLayerOffset "layer offsets" affecting the layer in
51 /// which one of these values is authored are applied to the attribute's value
52 /// itself during value resolution. This allows audio playback to be kept in
53 /// sync with time sampled animation as the animation is affected by
54 /// \ref SdfLayerOffset "layer offsets" in the composition. But this behavior
55 /// brings with it some interesting edge cases and caveats when it comes to
56 /// \ref SdfLayerOffset "layer offsets" that include scale.
57 ///
58 /// #### Layer Offsets do not affect Media Dilation
59 /// Although authored layer offsets may have a time scale which can scale the
60 /// duration between an authored \a startTime and \a endTime, we make no
61 /// attempt to infer any playback dilation of the actual audio media itself.
62 /// Given that \a startTime and \a endTime can be independently authored in
63 /// different layers with differing time scales, it is not possible, in general,
64 /// to define an "original timeframe" from which we can compute a dilation to
65 /// composed stage-time. Even if we could compute a composed dilation this way,
66 /// it would still be impossible to flatten a stage or layer stack into a single
67 /// layer and still retain the composed audio dilation using this schema.
68 ///
69 ///
70 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
71 /// that are text/tokens, the actual token is published and defined in \ref UsdMediaTokens.
72 /// So to set an attribute to the value "rightHanded", use UsdMediaTokens->rightHanded
73 /// as the value.
74 ///
76 {
77 public:
78  /// Compile time constant representing what kind of schema this class is.
79  ///
80  /// \sa UsdSchemaKind
82 
83  /// Construct a UsdMediaSpatialAudio on UsdPrim \p prim .
84  /// Equivalent to UsdMediaSpatialAudio::Get(prim.GetStage(), prim.GetPath())
85  /// for a \em valid \p prim, but will not immediately throw an error for
86  /// an invalid \p prim
87  explicit UsdMediaSpatialAudio(const UsdPrim& prim=UsdPrim())
88  : UsdGeomXformable(prim)
89  {
90  }
91 
92  /// Construct a UsdMediaSpatialAudio on the prim held by \p schemaObj .
93  /// Should be preferred over UsdMediaSpatialAudio(schemaObj.GetPrim()),
94  /// as it preserves SchemaBase state.
95  explicit UsdMediaSpatialAudio(const UsdSchemaBase& schemaObj)
96  : UsdGeomXformable(schemaObj)
97  {
98  }
99 
100  /// Destructor.
102  virtual ~UsdMediaSpatialAudio();
103 
104  /// Return a vector of names of all pre-declared attributes for this schema
105  /// class and all its ancestor classes. Does not include attributes that
106  /// may be authored by custom/extended methods of the schemas involved.
108  static const TfTokenVector &
109  GetSchemaAttributeNames(bool includeInherited=true);
110 
111  /// Return a UsdMediaSpatialAudio holding the prim adhering to this
112  /// schema at \p path on \p stage. If no prim exists at \p path on
113  /// \p stage, or if the prim at that path does not adhere to this schema,
114  /// return an invalid schema object. This is shorthand for the following:
115  ///
116  /// \code
117  /// UsdMediaSpatialAudio(stage->GetPrimAtPath(path));
118  /// \endcode
119  ///
121  static UsdMediaSpatialAudio
122  Get(const UsdStagePtr &stage, const SdfPath &path);
123 
124  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
125  /// is defined (according to UsdPrim::IsDefined()) on this stage.
126  ///
127  /// If a prim adhering to this schema at \p path is already defined on this
128  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
129  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
130  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
131  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
132  /// current EditTarget for any nonexistent, or existing but not \a Defined
133  /// ancestors.
134  ///
135  /// The given \a path must be an absolute prim path that does not contain
136  /// any variant selections.
137  ///
138  /// If it is impossible to author any of the necessary PrimSpecs, (for
139  /// example, in case \a path cannot map to the current UsdEditTarget's
140  /// namespace) issue an error and return an invalid \a UsdPrim.
141  ///
142  /// Note that this method may return a defined prim whose typeName does not
143  /// specify this schema class, in case a stronger typeName opinion overrides
144  /// the opinion at the current EditTarget.
145  ///
147  static UsdMediaSpatialAudio
148  Define(const UsdStagePtr &stage, const SdfPath &path);
149 
150 protected:
151  /// Returns the kind of schema this class belongs to.
152  ///
153  /// \sa UsdSchemaKind
155  UsdSchemaKind _GetSchemaKind() const override;
156 
157 private:
158  // needs to invoke _GetStaticTfType.
159  friend class UsdSchemaRegistry;
161  static const TfType &_GetStaticTfType();
162 
163  static bool _IsTypedSchema();
164 
165  // override SchemaBase virtuals.
167  const TfType &_GetTfType() const override;
168 
169 public:
170  // --------------------------------------------------------------------- //
171  // FILEPATH
172  // --------------------------------------------------------------------- //
173  /// Path to the audio file.
174  /// In general, the formats allowed for audio files is no more constrained
175  /// by USD than is image-type. As with images, however, usdz has stricter
176  /// requirements based on DMA and format support in browsers and consumer
177  /// devices. The allowed audio filetypes for usdz are M4A, MP3, WAV
178  /// (in order of preference).
179  /// \sa <a href="https://openusd.org/release/spec_usdz.html">Usdz Specification</a>
180  ///
181  ///
182  /// | ||
183  /// | -- | -- |
184  /// | Declaration | `uniform asset filePath = @@` |
185  /// | C++ Type | SdfAssetPath |
186  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Asset |
187  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
190 
191  /// See GetFilePathAttr(), and also
192  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
193  /// If specified, author \p defaultValue as the attribute's default,
194  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
195  /// the default for \p writeSparsely is \c false.
197  UsdAttribute CreateFilePathAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
198 
199 public:
200  // --------------------------------------------------------------------- //
201  // AURALMODE
202  // --------------------------------------------------------------------- //
203  /// Determines how audio should be played.
204  /// Valid values are:
205  /// - spatial: Play the audio in 3D space if the device can support spatial
206  /// audio. if not, fall back to mono.
207  /// - nonSpatial: Play the audio without regard to the SpatialAudio prim's
208  /// position. If the audio media contains any form of stereo or other
209  /// multi-channel sound, it is left to the application to determine
210  /// whether the listener's position should be taken into account. We
211  /// expect nonSpatial to be the choice for ambient sounds and music
212  /// sound-tracks.
213  ///
214  ///
215  /// | ||
216  /// | -- | -- |
217  /// | Declaration | `uniform token auralMode = "spatial"` |
218  /// | C++ Type | TfToken |
219  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
220  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
221  /// | \ref UsdMediaTokens "Allowed Values" | spatial, nonSpatial |
224 
225  /// See GetAuralModeAttr(), and also
226  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
227  /// If specified, author \p defaultValue as the attribute's default,
228  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
229  /// the default for \p writeSparsely is \c false.
231  UsdAttribute CreateAuralModeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
232 
233 public:
234  // --------------------------------------------------------------------- //
235  // PLAYBACKMODE
236  // --------------------------------------------------------------------- //
237  /// Along with \a startTime and \a endTime, determines when the
238  /// audio playback should start and stop during the stage's animation
239  /// playback and whether the audio should loop during its duration.
240  /// Valid values are:
241  /// - onceFromStart: Play the audio once, starting at \a startTime,
242  /// continuing until the audio completes.
243  /// - onceFromStartToEnd: Play the audio once beginning at \a startTime,
244  /// continuing until \a endTime or until the audio completes, whichever
245  /// comes first.
246  /// - loopFromStart: Start playing the audio at \a startTime and continue
247  /// looping through to the stage's authored \a endTimeCode.
248  /// - loopFromStartToEnd: Start playing the audio at \a startTime and
249  /// continue looping through, stopping the audio at \a endTime.
250  /// - loopFromStage: Start playing the audio at the stage's authored
251  /// \a startTimeCode and continue looping through to the stage's authored
252  /// \a endTimeCode. This can be useful for ambient sounds that should always
253  /// be active.
254  ///
255  ///
256  /// | ||
257  /// | -- | -- |
258  /// | Declaration | `uniform token playbackMode = "onceFromStart"` |
259  /// | C++ Type | TfToken |
260  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
261  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
262  /// | \ref UsdMediaTokens "Allowed Values" | onceFromStart, onceFromStartToEnd, loopFromStart, loopFromStartToEnd, loopFromStage |
265 
266  /// See GetPlaybackModeAttr(), and also
267  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
268  /// If specified, author \p defaultValue as the attribute's default,
269  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
270  /// the default for \p writeSparsely is \c false.
272  UsdAttribute CreatePlaybackModeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
273 
274 public:
275  // --------------------------------------------------------------------- //
276  // STARTTIME
277  // --------------------------------------------------------------------- //
278  /// Expressed in the timeCodesPerSecond of the containing stage,
279  /// \a startTime specifies when the audio stream will start playing during
280  /// animation playback. This value is ignored when \a playbackMode is set
281  /// to loopFromStage as, in this mode, the audio will always start at the
282  /// stage's authored \a startTimeCode.
283  /// Note that \a startTime is expressed as a timecode so that the stage can
284  /// properly apply layer offsets when resolving its value. See
285  /// \ref Usd_SpatialAudio_TimeScaling for more details and caveats.
286  ///
287  ///
288  /// | ||
289  /// | -- | -- |
290  /// | Declaration | `uniform timecode startTime = 0` |
291  /// | C++ Type | SdfTimeCode |
292  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TimeCode |
293  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
296 
297  /// See GetStartTimeAttr(), and also
298  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
299  /// If specified, author \p defaultValue as the attribute's default,
300  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
301  /// the default for \p writeSparsely is \c false.
303  UsdAttribute CreateStartTimeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
304 
305 public:
306  // --------------------------------------------------------------------- //
307  // ENDTIME
308  // --------------------------------------------------------------------- //
309  /// Expressed in the timeCodesPerSecond of the containing stage,
310  /// \a endTime specifies when the audio stream will cease playing during
311  /// animation playback if the length of the referenced audio clip is
312  /// longer than desired. This only applies if \a playbackMode is set to
313  /// onceFromStartToEnd or loopFromStartToEnd, otherwise the \a endTimeCode
314  /// of the stage is used instead of \a endTime.
315  /// If \a endTime is less than \a startTime, it is expected that the audio
316  /// will instead be played from \a endTime to \a startTime.
317  /// Note that \a endTime is expressed as a timecode so that the stage can
318  /// properly apply layer offsets when resolving its value.
319  /// See \ref Usd_SpatialAudio_TimeScaling for more details and caveats.
320  ///
321  ///
322  /// | ||
323  /// | -- | -- |
324  /// | Declaration | `uniform timecode endTime = 0` |
325  /// | C++ Type | SdfTimeCode |
326  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TimeCode |
327  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
330 
331  /// See GetEndTimeAttr(), and also
332  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
333  /// If specified, author \p defaultValue as the attribute's default,
334  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
335  /// the default for \p writeSparsely is \c false.
337  UsdAttribute CreateEndTimeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
338 
339 public:
340  // --------------------------------------------------------------------- //
341  // MEDIAOFFSET
342  // --------------------------------------------------------------------- //
343  /// Expressed in seconds, \a mediaOffset specifies the offset from
344  /// the referenced audio file's beginning at which we should begin playback
345  /// when stage playback reaches the time that prim's audio should start.
346  /// If the prim's \a playbackMode is a looping mode, \a mediaOffset is
347  /// applied only to the first run-through of the audio clip; the second and
348  /// all other loops begin from the start of the audio clip.
349  ///
350  ///
351  /// | ||
352  /// | -- | -- |
353  /// | Declaration | `uniform double mediaOffset = 0` |
354  /// | C++ Type | double |
355  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
356  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
359 
360  /// See GetMediaOffsetAttr(), and also
361  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
362  /// If specified, author \p defaultValue as the attribute's default,
363  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
364  /// the default for \p writeSparsely is \c false.
366  UsdAttribute CreateMediaOffsetAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
367 
368 public:
369  // --------------------------------------------------------------------- //
370  // GAIN
371  // --------------------------------------------------------------------- //
372  /// Multiplier on the incoming audio signal. A value of 0 "mutes"
373  /// the signal. Negative values will be clamped to 0.
374  ///
375  ///
376  /// | ||
377  /// | -- | -- |
378  /// | Declaration | `double gain = 1` |
379  /// | C++ Type | double |
380  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
382  UsdAttribute GetGainAttr() const;
383 
384  /// See GetGainAttr(), and also
385  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
386  /// If specified, author \p defaultValue as the attribute's default,
387  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
388  /// the default for \p writeSparsely is \c false.
390  UsdAttribute CreateGainAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
391 
392 public:
393  // ===================================================================== //
394  // Feel free to add custom code below this line, it will be preserved by
395  // the code generator.
396  //
397  // Just remember to:
398  // - Close the class declaration with };
399  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
400  // - Close the include guard with #endif
401  // ===================================================================== //
402  // --(BEGIN CUSTOM CODE)--
403 };
404 
406 
407 #endif
static USDMEDIA_API UsdMediaSpatialAudio Get(const UsdStagePtr &stage, const SdfPath &path)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDMEDIA_API UsdAttribute CreateMediaOffsetAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDMEDIA_API UsdAttribute CreatePlaybackModeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDMEDIA_API UsdAttribute CreateAuralModeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static USDMEDIA_API UsdMediaSpatialAudio Define(const UsdStagePtr &stage, const SdfPath &path)
static const UsdSchemaKind schemaKind
Definition: spatialAudio.h:81
Represents a concrete typed schema.
USDMEDIA_API UsdAttribute GetGainAttr() const
USDMEDIA_API UsdAttribute GetFilePathAttr() const
USDMEDIA_API UsdAttribute GetStartTimeAttr() const
static USDMEDIA_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
#define USDMEDIA_API
Definition: api.h:23
Definition: path.h:280
USDMEDIA_API UsdAttribute CreateFilePathAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdSchemaKind
Definition: common.h:112
USDMEDIA_API UsdAttribute CreateGainAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdMediaSpatialAudio(const UsdPrim &prim=UsdPrim())
Definition: spatialAudio.h:87
USDMEDIA_API UsdSchemaKind _GetSchemaKind() const override
USDMEDIA_API UsdAttribute GetAuralModeAttr() const
USDMEDIA_API UsdAttribute GetPlaybackModeAttr() const
USDMEDIA_API UsdAttribute GetEndTimeAttr() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDMEDIA_API UsdAttribute CreateEndTimeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: type.h:47
UsdMediaSpatialAudio(const UsdSchemaBase &schemaObj)
Definition: spatialAudio.h:95
USDMEDIA_API UsdAttribute GetMediaOffsetAttr() const
USDMEDIA_API UsdAttribute CreateStartTimeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:89
virtual USDMEDIA_API ~UsdMediaSpatialAudio()
Destructor.