#include <Magnum/Audio/Playable.h>
template<UnsignedInt dimensions>
Playable class
Playable.
Feature which manages the position, orientation and gain of a Source for an SceneGraph::
Usage
Attach the instance to an existing object and set a filled buffer to it. In order to reflect transformation changes from the scene in the spatial audio, the playable should be added to some PlayableGroup, which is periodically updated from a currently active Listener using Listener::
Scene3D scene; Object3D object{&scene}; Audio::Buffer buffer; // ... Audio::Listener3D listener{scene}; Audio::PlayableGroup3D group; /* Attach the playable to an object and configure its source */ Audio::Playable3D playable{object, &group}; playable.source() .setBuffer(&buffer) .setLooping(true) .play(); // ... // every frame, adapt the listener and all playables to changes in scene // transformation listener.update({group, someOtherGroup});
Note that Source::
- Transformation of the source is inherited from the scene. If you want to transform it, transform the SceneGraph::
Object the playable is attached to. It's also possible to affect the global listener and group transformation using Listener:: setSoundTransformation() and PlayableGroup:: setSoundTransformation() - The source is by default omnidirectional (i.e., passing a zero vector to Source::
setDirection()). You can set the initial direction using the Playable(SceneGraph:: AbstractObject<dimensions, Float>&, const VectorTypeFor<dimensions, Float>&, PlayableGroup<dimensions>*) constructor, the direction will be automatically rotated based on playable transformation. - Source gain is set as a combination of PlayableGroup gain and Playable gain and updated on every call to setGain() or PlayableGroup::
setGain().
Base classes
-
template<UnsignedInt dimensions, class Derived, class T>class Magnum::SceneGraph::AbstractGroupedFeature<dimensions, Playable<dimensions>, Float>
- Base for grouped features.
Constructors, destructors, conversion operators
-
Playable(SceneGraph::
AbstractObject<dimensions, Float>& object, PlayableGroup<dimensions>* group = nullptr) explicit - Construct a playable with omnidirectional source.
-
Playable(SceneGraph::
AbstractObject<dimensions, Float>& object, const VectorTypeFor<dimensions, Float>& direction, PlayableGroup<dimensions>* group = nullptr) explicit - Construct a playable with directional source.
Public functions
- auto source() -> Source&
- Source which is managed by this feature.
- auto gain() const -> Float
- Gain.
- auto setGain(const Float gain) -> Playable&
- Set gain of the playable and source respecting the PlayableGroups gain.
- auto playables() -> PlayableGroup<dimensions>*
- Group containing this playable.
- auto playables() const -> const PlayableGroup<dimensions>*
Function documentation
template<UnsignedInt dimensions>
Magnum:: Audio:: Playable<dimensions>:: Playable(SceneGraph:: AbstractObject<dimensions, Float>& object,
PlayableGroup<dimensions>* group = nullptr) explicit
Construct a playable with omnidirectional source.
Parameters | |
---|---|
object | Object this playable belongs to |
group | Group this playable belongs to |
Creates a source with a zero direction vector. See Playable(SceneGraph::
template<UnsignedInt dimensions>
Magnum:: Audio:: Playable<dimensions>:: Playable(SceneGraph:: AbstractObject<dimensions, Float>& object,
const VectorTypeFor<dimensions, Float>& direction,
PlayableGroup<dimensions>* group = nullptr) explicit
Construct a playable with directional source.
Parameters | |
---|---|
object | Object this playable belongs to |
direction | Source direction |
group | Group this playable belongs to |
Uses direction
as a base for Source::
template<UnsignedInt dimensions>
Playable& Magnum:: Audio:: Playable<dimensions>:: setGain(const Float gain)
Set gain of the playable and source respecting the PlayableGroups gain.
Returns | Reference to self (for method chaining) |
---|
The source gain is calculated as sourceGain = playableGain*groupGain
. Default is 1.0f
.
template<UnsignedInt dimensions>
PlayableGroup<dimensions>* Magnum:: Audio:: Playable<dimensions>:: playables()
Group containing this playable.
If the playable doesn't belong to any group, returns nullptr
.
template<UnsignedInt dimensions>
const PlayableGroup<dimensions>* Magnum:: Audio:: Playable<dimensions>:: playables() const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.