npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wonderlandengine/spatial-audio

v1.2.0

Published

Spatial audio components for Wonderland Engine

Downloads

73

Readme

build

Wonderland Spatial Audio

NPM Package

The Wonderland Audio System simplifies audio management with Wonderland Engine. These components offer efficient control over audio sources and listeners and enable seamless updates of their positions and orientations in the WebAudio context.

View Live Example

Usage Guide

Instructions on how to set up and use Wonderland Spatial Audio:

Installation

Install the components in your project:

npm install --save @wonderlandengine/spatial-audio

Wonderland Editor will automatically detect the components from this package and they will be available to attach to objects.

Audio Listener

  1. For VR audio: attach an audio-listener component to the Player > Head object. This controls position and orientation of the receiver. Updates occur each frame.

  2. For PC/mobile audio: attach the audio-listener component to the NonVrCamera. Only one listener component should be active at any given time. To achieve this, use the vr-mode-active-switch component.

⚠️ The listener is necessary for spatial panning to work correctly in the AudioManager and AudioSource!

Audio Sources

Add an audio-source component to objects that should play sound. Set the src property to a URL in the static folder of your project. (E.g., for static/sfx/sound.mp3 enter sfx/sound.mp3). If spatial is set to None, all settings below are ignored.

  • Changing the volume parameter will only take effect when calling the play() function. If the audio is already playing, use setVolumeDuringPlayback() instead.

AudioManager

The AudioManager can be used to play audio from anywhere in your project! It is a way to conveniently manage audio files. This package provides a global instance of the manager called globalAudioManager. To make use of it, create your own identifiers and then load up the manager with your audio files:

enum MySounds {
    Gunshot,
    Zombie,
}

globalAudioManager.load('sfx/gunshot.mp3', MySounds.Gunshot);
// You can even load multiple files for one ID. On play, a random file of the provided ones will be selected. 
globalAudioManager.load(['sfx/zombie_01.mp3', 'sfx/zombie_02.mp3'], MySounds.Zombie);

⚠️ Only load() and loadBatch() can be used in top-level code!

There are multiple ways of playing an audio file that has loaded:

globalAudioManager.play(MySounds.Gunshot);          // Standard way, returns an ID with which audio can be stopped.
globalAudioManager.playOneShot(MySounds.Gunshot);   // Plays the audio for one time only.
globalAudioManager.autoplay(MySounds.Gunshot);      // Plays the audio as soon as the user has interacted with the site.

Checkout the PlayConfig type, for all the configuration settings! It can be added to change the playback behaviour.

onPress() {
    this.object.getPositionWorld(posVec);
    globalAudioManager.play(MySounds.Gunshot, {
        volume: 0.8,
        loop: true,
        position: posVec,
        channel: AudioChannel.Sfx,
        priority: false
    });
}

The AudioManager has three main channels: Sfx, Music and Master. Use these to group your audio and control the volume globally. On using play(), the respective channels can be selected via the PlayConfig. Be aware though that playOneShot() will always use the Sfx channel!

Considerations

Best Practices

  • HRTF Performance: The HRTF setting demands substantial performance resources. For less critical audio effects, consider deactivating it and rely on regular (equal-power) 3D panning.

  • Stationary Audio Sources: If an audio-source in a scene will remain at the same position, activate the isStationary flag to disable position updates each frame for better performance.

Meta Quest 2 Performance

On Meta Quest 2, the maximum number of simultaneously playing audio sources is approximately 30.