Audio Objects
Audio objects represent sound sources that can be positioned in 3D space. They have properties like occlusion and reverb to
make them sound more realistic.
You can assign Web Audio API AudioNodes as the source of an audio object. The audio signals will then be spatialized according to
the object's position relative to the Audio Listener.
With Distance Models, you can also control how the volume of the audio object changes with distance.
Audio Objects are created using the
Space.createAudioObject
method.
As the number of audio objects in a space is limited , you should reuse them whenever possible. You can free an audio object
using the Space.removeAudioObject
method.Basic Usage
Create an AudioObject and assign an audio source
import { AudioFile } from "@atmokyaudio/engage-client";
const audioObject = space.createAudioObject();
const audioFile = new AudioFile(space.getAudioContext());
audioFile
.load("<path to an audiofile>", true)
.then(() => console.log("Audio file loaded"));
audioObject.setInput(audioFile);
The
AudioFile
class is a handy
AudioPlayer
for audio files you can
use as the source of an audio object.Setting some rendering properties
Every audio object has a set of properties that can be used to control how it is rendered. These properties include e.g. the position and the orientation of the
audio object, the directivity, the volume, the occlusion value, the reverb send, and the distance model (see Audio Properties
for a detailed explanation for all available parameters). Every property has a getter and a setter method, e.g.
audioObject.setGainLinear(0.4);
audioObject.setPosition(2, 1, 0);
audioObject.setDirectivity(Math.PI / 2, 3 * Math.PI / 2, 0.1, 0.7);
audioObject.setRotation(0, 0, 0);
audioObject.setReverbSendDecibels(-10);
audioObject.setOcclusion(0.1);
const gain = audioObject.getGainLinear();
const position = audioObject.getPosition();
const directivity = audioObject.getDirectivity();
const q = audioObject.getRotationQuaternion();
const reverbSend = audioObject.getReverbSendDecibels();
const occlusion = audioObject.getOcclusion();