Yo @docEdub Can you please out line what i need to do to properly setup and use spatial audio.
Am I required to update the spatial audio position each frame, or does the class that handles attaching to the mesh do that?
Can you make a small playground that properly sets up and update spatial Audio example ?
Its hard to duplicate my toolkit usage on the playground, but this how i cam currently trying to setup spatial audio, but I dont know if its right or not, because i can only hear sound at position 0,0,0 or what ever position i specify with spatialPosition option. But it does NOT move the sound around with the attached mesh
public async setAudioDataSource(source: string | ArrayBuffer): Promise<void> {
if (this._audio != null) {
this._audio.dispose();
this._audio = null;
}
console.log("### Setting Audio Data Source: " + this._name);
const spatialBlend: boolean = (this._spatialblend >= 0.1);
this._initializedReadyInstance = false;
this._lastmutedvolume = this._volume;
this._audio = await TOOLKIT.AudioSource.CreateStaticSound(this._name, source,
{
loop: this._loop,
volume: (this._mute === true) ? 0 : this._volume,
autoplay: false, // Note: Never Auto Play Here
playbackRate: this._pitch,
spatialEnabled: spatialBlend,
spatialAutoUpdate: true,
spatialDistanceModel: ((this._rolloffmode === "logarithmic") ? "exponential" : "linear"),
spatialReferenceDistance: this._mindistance,
spatialMaxDistance: this._maxdistance,
spatialRolloffFactor: TOOLKIT.AudioSource.DEFAULT_ROLLOFF
});
if (this._audio != null) {
this._initializedReadyInstance = true;
if (this.onReadyObservable && this.onReadyObservable.hasObservers()) {
this.onReadyObservable.notifyObservers(this._audio);
}
if (spatialBlend === true && this._audio.spatial != null) this._audio.spatial.attach(this.transform, false, BABYLON.SpatialAudioAttachmentType.PositionAndRotation);
if (this._playonawake === true) this.play();
}
}
And my CreateStaticSound helper function