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 /// #### Inverting startTime and endTime
70 /// Although we do not expect it to be common, it is possible to apply a
71 /// negative time scale to USD layers, which mostly has the effect of reversing
72 /// animation in the affected composition. If a negative scale is applied to a
73 /// composition that contains authored \a startTime and \a endTime, it will
74 /// reverse their relative ordering in time. Therefore, we stipulate when
75 /// \a playbackMode is "onceFromStartToEnd" or "loopFromStartToEnd", if
76 /// \a endTime is less than \a startTime, then begin playback at \a endTime,
77 /// and continue until \a startTime. When \a startTime and \a endTime are
78 /// inverted, we do not, however, stipulate that playback of the audio media
79 /// itself be inverted, since doing so "successfully" would require perfect
80 /// knowledge of when, within the audio clip, relevant audio ends (so that we
81 /// know how to offset the reversed audio to align it so that we reach the
82 /// "beginning" at \a startTime), and sounds played in reverse are not likely
83 /// to produce desirable results.
84 ///
85 ///
86 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
87 /// that are text/tokens, the actual token is published and defined in \ref UsdMediaTokens.
88 /// So to set an attribute to the value "rightHanded", use UsdMediaTokens->rightHanded
89 /// as the value.
90 ///
92 {
93 public:
94  /// Compile time constant representing what kind of schema this class is.
95  ///
96  /// \sa UsdSchemaKind
98 
99  /// Construct a UsdMediaSpatialAudio on UsdPrim \p prim .
100  /// Equivalent to UsdMediaSpatialAudio::Get(prim.GetStage(), prim.GetPath())
101  /// for a \em valid \p prim, but will not immediately throw an error for
102  /// an invalid \p prim
103  explicit UsdMediaSpatialAudio(const UsdPrim& prim=UsdPrim())
104  : UsdGeomXformable(prim)
105  {
106  }
107 
108  /// Construct a UsdMediaSpatialAudio on the prim held by \p schemaObj .
109  /// Should be preferred over UsdMediaSpatialAudio(schemaObj.GetPrim()),
110  /// as it preserves SchemaBase state.
111  explicit UsdMediaSpatialAudio(const UsdSchemaBase& schemaObj)
112  : UsdGeomXformable(schemaObj)
113  {
114  }
115 
116  /// Destructor.
118  virtual ~UsdMediaSpatialAudio();
119 
120  /// Return a vector of names of all pre-declared attributes for this schema
121  /// class and all its ancestor classes. Does not include attributes that
122  /// may be authored by custom/extended methods of the schemas involved.
124  static const TfTokenVector &
125  GetSchemaAttributeNames(bool includeInherited=true);
126 
127  /// Return a UsdMediaSpatialAudio holding the prim adhering to this
128  /// schema at \p path on \p stage. If no prim exists at \p path on
129  /// \p stage, or if the prim at that path does not adhere to this schema,
130  /// return an invalid schema object. This is shorthand for the following:
131  ///
132  /// \code
133  /// UsdMediaSpatialAudio(stage->GetPrimAtPath(path));
134  /// \endcode
135  ///
137  static UsdMediaSpatialAudio
138  Get(const UsdStagePtr &stage, const SdfPath &path);
139 
140  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
141  /// is defined (according to UsdPrim::IsDefined()) on this stage.
142  ///
143  /// If a prim adhering to this schema at \p path is already defined on this
144  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
145  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
146  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
147  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
148  /// current EditTarget for any nonexistent, or existing but not \a Defined
149  /// ancestors.
150  ///
151  /// The given \a path must be an absolute prim path that does not contain
152  /// any variant selections.
153  ///
154  /// If it is impossible to author any of the necessary PrimSpecs, (for
155  /// example, in case \a path cannot map to the current UsdEditTarget's
156  /// namespace) issue an error and return an invalid \a UsdPrim.
157  ///
158  /// Note that this method may return a defined prim whose typeName does not
159  /// specify this schema class, in case a stronger typeName opinion overrides
160  /// the opinion at the current EditTarget.
161  ///
163  static UsdMediaSpatialAudio
164  Define(const UsdStagePtr &stage, const SdfPath &path);
165 
166 protected:
167  /// Returns the kind of schema this class belongs to.
168  ///
169  /// \sa UsdSchemaKind
171  UsdSchemaKind _GetSchemaKind() const override;
172 
173 private:
174  // needs to invoke _GetStaticTfType.
175  friend class UsdSchemaRegistry;
177  static const TfType &_GetStaticTfType();
178 
179  static bool _IsTypedSchema();
180 
181  // override SchemaBase virtuals.
183  const TfType &_GetTfType() const override;
184 
185 public:
186  // --------------------------------------------------------------------- //
187  // FILEPATH
188  // --------------------------------------------------------------------- //
189  /// Path to the audio file.
190  /// In general, the formats allowed for audio files is no more constrained
191  /// by USD than is image-type. As with images, however, usdz has stricter
192  /// requirements based on DMA and format support in browsers and consumer
193  /// devices. The allowed audio filetypes for usdz are M4A, MP3, WAV
194  /// (in order of preference).
195  /// \sa <a href="https://openusd.org/release/spec_usdz.html">Usdz Specification</a>
196  ///
197  ///
198  /// | ||
199  /// | -- | -- |
200  /// | Declaration | `uniform asset filePath = @@` |
201  /// | C++ Type | SdfAssetPath |
202  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Asset |
203  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
206 
207  /// See GetFilePathAttr(), and also
208  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
209  /// If specified, author \p defaultValue as the attribute's default,
210  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
211  /// the default for \p writeSparsely is \c false.
213  UsdAttribute CreateFilePathAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
214 
215 public:
216  // --------------------------------------------------------------------- //
217  // AURALMODE
218  // --------------------------------------------------------------------- //
219  /// Determines how audio should be played.
220  /// Valid values are:
221  /// - spatial: Play the audio in 3D space if the device can support spatial
222  /// audio. if not, fall back to mono.
223  /// - nonSpatial: Play the audio without regard to the SpatialAudio prim's
224  /// position. If the audio media contains any form of stereo or other
225  /// multi-channel sound, it is left to the application to determine
226  /// whether the listener's position should be taken into account. We
227  /// expect nonSpatial to be the choice for ambient sounds and music
228  /// sound-tracks.
229  ///
230  ///
231  /// | ||
232  /// | -- | -- |
233  /// | Declaration | `uniform token auralMode = "spatial"` |
234  /// | C++ Type | TfToken |
235  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
236  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
237  /// | \ref UsdMediaTokens "Allowed Values" | spatial, nonSpatial |
240 
241  /// See GetAuralModeAttr(), and also
242  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
243  /// If specified, author \p defaultValue as the attribute's default,
244  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
245  /// the default for \p writeSparsely is \c false.
247  UsdAttribute CreateAuralModeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
248 
249 public:
250  // --------------------------------------------------------------------- //
251  // PLAYBACKMODE
252  // --------------------------------------------------------------------- //
253  /// Along with \a startTime and \a endTime, determines when the
254  /// audio playback should start and stop during the stage's animation
255  /// playback and whether the audio should loop during its duration.
256  /// Valid values are:
257  /// - onceFromStart: Play the audio once, starting at \a startTime,
258  /// continuing until the audio completes.
259  /// - onceFromStartToEnd: Play the audio once beginning at \a startTime,
260  /// continuing until \a endTime or until the audio completes, whichever
261  /// comes first.
262  /// - loopFromStart: Start playing the audio at \a startTime and continue
263  /// looping through to the stage's authored \a endTimeCode.
264  /// - loopFromStartToEnd: Start playing the audio at \a startTime and
265  /// continue looping through, stopping the audio at \a endTime.
266  /// - loopFromStage: Start playing the audio at the stage's authored
267  /// \a startTimeCode and continue looping through to the stage's authored
268  /// \a endTimeCode. This can be useful for ambient sounds that should always
269  /// be active.
270  ///
271  ///
272  /// | ||
273  /// | -- | -- |
274  /// | Declaration | `uniform token playbackMode = "onceFromStart"` |
275  /// | C++ Type | TfToken |
276  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
277  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
278  /// | \ref UsdMediaTokens "Allowed Values" | onceFromStart, onceFromStartToEnd, loopFromStart, loopFromStartToEnd, loopFromStage |
281 
282  /// See GetPlaybackModeAttr(), and also
283  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
284  /// If specified, author \p defaultValue as the attribute's default,
285  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
286  /// the default for \p writeSparsely is \c false.
288  UsdAttribute CreatePlaybackModeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
289 
290 public:
291  // --------------------------------------------------------------------- //
292  // STARTTIME
293  // --------------------------------------------------------------------- //
294  /// Expressed in the timeCodesPerSecond of the containing stage,
295  /// \a startTime specifies when the audio stream will start playing during
296  /// animation playback. This value is ignored when \a playbackMode is set
297  /// to loopFromStage as, in this mode, the audio will always start at the
298  /// stage's authored \a startTimeCode.
299  /// Note that \a startTime is expressed as a timecode so that the stage can
300  /// properly apply layer offsets when resolving its value. See
301  /// \ref Usd_SpatialAudio_TimeScaling for more details and caveats.
302  ///
303  ///
304  /// | ||
305  /// | -- | -- |
306  /// | Declaration | `uniform timecode startTime = 0` |
307  /// | C++ Type | SdfTimeCode |
308  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TimeCode |
309  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
312 
313  /// See GetStartTimeAttr(), and also
314  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
315  /// If specified, author \p defaultValue as the attribute's default,
316  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
317  /// the default for \p writeSparsely is \c false.
319  UsdAttribute CreateStartTimeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
320 
321 public:
322  // --------------------------------------------------------------------- //
323  // ENDTIME
324  // --------------------------------------------------------------------- //
325  /// Expressed in the timeCodesPerSecond of the containing stage,
326  /// \a endTime specifies when the audio stream will cease playing during
327  /// animation playback if the length of the referenced audio clip is
328  /// longer than desired. This only applies if \a playbackMode is set to
329  /// onceFromStartToEnd or loopFromStartToEnd, otherwise the \a endTimeCode
330  /// of the stage is used instead of \a endTime.
331  /// If \a endTime is less than \a startTime, it is expected that the audio
332  /// will instead be played from \a endTime to \a startTime.
333  /// Note that \a endTime is expressed as a timecode so that the stage can
334  /// properly apply layer offsets when resolving its value.
335  /// See \ref Usd_SpatialAudio_TimeScaling for more details and caveats.
336  ///
337  ///
338  /// | ||
339  /// | -- | -- |
340  /// | Declaration | `uniform timecode endTime = 0` |
341  /// | C++ Type | SdfTimeCode |
342  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TimeCode |
343  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
346 
347  /// See GetEndTimeAttr(), and also
348  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
349  /// If specified, author \p defaultValue as the attribute's default,
350  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
351  /// the default for \p writeSparsely is \c false.
353  UsdAttribute CreateEndTimeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
354 
355 public:
356  // --------------------------------------------------------------------- //
357  // MEDIAOFFSET
358  // --------------------------------------------------------------------- //
359  /// Expressed in seconds, \a mediaOffset specifies the offset from
360  /// the referenced audio file's beginning at which we should begin playback
361  /// when stage playback reaches the time that prim's audio should start.
362  /// If the prim's \a playbackMode is a looping mode, \a mediaOffset is
363  /// applied only to the first run-through of the audio clip; the second and
364  /// all other loops begin from the start of the audio clip.
365  ///
366  ///
367  /// | ||
368  /// | -- | -- |
369  /// | Declaration | `uniform double mediaOffset = 0` |
370  /// | C++ Type | double |
371  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
372  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
375 
376  /// See GetMediaOffsetAttr(), and also
377  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
378  /// If specified, author \p defaultValue as the attribute's default,
379  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
380  /// the default for \p writeSparsely is \c false.
382  UsdAttribute CreateMediaOffsetAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
383 
384 public:
385  // --------------------------------------------------------------------- //
386  // GAIN
387  // --------------------------------------------------------------------- //
388  /// Multiplier on the incoming audio signal. A value of 0 "mutes"
389  /// the signal. Negative values will be clamped to 0.
390  ///
391  ///
392  /// | ||
393  /// | -- | -- |
394  /// | Declaration | `double gain = 1` |
395  /// | C++ Type | double |
396  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
398  UsdAttribute GetGainAttr() const;
399 
400  /// See GetGainAttr(), and also
401  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
402  /// If specified, author \p defaultValue as the attribute's default,
403  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
404  /// the default for \p writeSparsely is \c false.
406  UsdAttribute CreateGainAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
407 
408 public:
409  // ===================================================================== //
410  // Feel free to add custom code below this line, it will be preserved by
411  // the code generator.
412  //
413  // Just remember to:
414  // - Close the class declaration with };
415  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
416  // - Close the include guard with #endif
417  // ===================================================================== //
418  // --(BEGIN CUSTOM CODE)--
419 };
420 
422 
423 #endif
static USDMEDIA_API UsdMediaSpatialAudio Get(const UsdStagePtr &stage, const SdfPath &path)
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:97
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:273
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:103
USDMEDIA_API UsdSchemaKind _GetSchemaKind() const override
USDMEDIA_API UsdAttribute GetAuralModeAttr() const
USDMEDIA_API UsdAttribute GetPlaybackModeAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:111
USDMEDIA_API UsdAttribute GetMediaOffsetAttr() const
USDMEDIA_API UsdAttribute CreateStartTimeAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:146
virtual USDMEDIA_API ~UsdMediaSpatialAudio()
Destructor.