initial commit
This commit is contained in:
20
public/scripts/howler/LICENSE.md
Normal file
20
public/scripts/howler/LICENSE.md
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013-2020 James Simpson and GoldFire Studios, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
564
public/scripts/howler/README.md
Normal file
564
public/scripts/howler/README.md
Normal file
@ -0,0 +1,564 @@
|
||||
[](https://howlerjs.com)
|
||||
|
||||
# Description
|
||||
[howler.js](https://howlerjs.com) is an audio library for the modern web. It defaults to [Web Audio API](http://webaudio.github.io/web-audio-api/) and falls back to [HTML5 Audio](https://html.spec.whatwg.org/multipage/embedded-content.html#the-audio-element). This makes working with audio in JavaScript easy and reliable across all platforms.
|
||||
|
||||
Additional information, live demos and a user showcase are available at [howlerjs.com](https://howlerjs.com).
|
||||
|
||||
Follow on Twitter for howler.js and development-related discussion: [@GoldFireStudios](https://twitter.com/goldfirestudios).
|
||||
|
||||
### Features
|
||||
* Single API for all audio needs
|
||||
* Defaults to Web Audio API and falls back to HTML5 Audio
|
||||
* Handles edge cases and bugs across environments
|
||||
* Supports all codecs for full cross-browser support
|
||||
* Automatic caching for improved performance
|
||||
* Control sounds individually, in groups or globally
|
||||
* Playback of multiple sounds at once
|
||||
* Easy sound sprite definition and playback
|
||||
* Full control for fading, rate, seek, volume, etc.
|
||||
* Easily add 3D spatial sound or stereo panning
|
||||
* Modular - use what you want and easy to extend
|
||||
* No outside dependencies, just pure JavaScript
|
||||
* As light as 7kb gzipped
|
||||
|
||||
### Browser Compatibility
|
||||
Tested in the following browsers/versions:
|
||||
* Google Chrome 7.0+
|
||||
* Internet Explorer 9.0+
|
||||
* Firefox 4.0+
|
||||
* Safari 5.1.4+
|
||||
* Mobile Safari 6.0+ (after user input)
|
||||
* Opera 12.0+
|
||||
* Microsoft Edge
|
||||
|
||||
### Live Demos
|
||||
* [Audio Player](https://howlerjs.com/#player)
|
||||
* [Radio](https://howlerjs.com/#radio)
|
||||
* [Spatial Audio](https://howlerjs.com/#spatial)
|
||||
* [Audio Sprites](https://howlerjs.com/#sprite)
|
||||
|
||||
# Documentation
|
||||
|
||||
### Contents
|
||||
* [Quick Start](#quick-start)
|
||||
* [Examples](#examples)
|
||||
* [Core](#core)
|
||||
* [Options](#options)
|
||||
* [Methods](#methods)
|
||||
* [Global Options](#global-options)
|
||||
* [Global Methods](#global-methods)
|
||||
* [Plugin: Spatial](#plugin-spatial)
|
||||
* [Options](#options-1)
|
||||
* [Methods](#methods-1)
|
||||
* [Global Methods](#global-methods-1)
|
||||
* [Group Playback](#group-playback)
|
||||
* [Mobile Playback](#mobilechrome-playback)
|
||||
* [Dolby Audio Playback](#dolby-audio-playback)
|
||||
* [Facebook Instant Games](#facebook-instant-games)
|
||||
* [Format Recommendations](#format-recommendations)
|
||||
* [License](#license)
|
||||
|
||||
### Quick Start
|
||||
|
||||
Several options to get up and running:
|
||||
|
||||
* Clone the repo: `git clone https://github.com/goldfire/howler.js.git`
|
||||
* Install with [npm](https://www.npmjs.com/package/howler): `npm install howler`
|
||||
* Install with [Yarn](https://yarnpkg.com/en/package/howler): `yarn add howler`
|
||||
* Install with [Bower](http://bower.io/): `bower install howler`
|
||||
* Hosted CDN: [`cdnjs`](https://cdnjs.com/libraries/howler) [`jsDelivr`](https://www.jsdelivr.com/projects/howler.js)
|
||||
|
||||
In the browser:
|
||||
|
||||
```html
|
||||
<script src="/path/to/howler.js"></script>
|
||||
<script>
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3']
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
As a dependency:
|
||||
|
||||
```javascript
|
||||
import {Howl, Howler} from 'howler';
|
||||
```
|
||||
|
||||
```javascript
|
||||
const {Howl, Howler} = require('howler');
|
||||
```
|
||||
|
||||
Included distribution files:
|
||||
|
||||
* **howler**: This is the default and fully bundled source that includes `howler.core` and `howler.spatial`. It includes all functionality that howler comes with.
|
||||
* **howler.core**: This includes only the core functionality that aims to create parity between Web Audio and HTML5 Audio. It doesn't include any of the spatial/stereo audio functionality.
|
||||
* **howler.spatial**: This is a plugin that adds spatial/stereo audio functionality. It requires `howler.core` to operate as it is simply an add-on to the core.
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
##### Most basic, play an MP3:
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.mp3']
|
||||
});
|
||||
|
||||
sound.play();
|
||||
```
|
||||
|
||||
##### Streaming audio (for live audio or large files):
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['stream.mp3'],
|
||||
html5: true
|
||||
});
|
||||
|
||||
sound.play();
|
||||
```
|
||||
|
||||
##### More playback options:
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3', 'sound.wav'],
|
||||
autoplay: true,
|
||||
loop: true,
|
||||
volume: 0.5,
|
||||
onend: function() {
|
||||
console.log('Finished!');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
##### Define and play a sound sprite:
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sounds.webm', 'sounds.mp3'],
|
||||
sprite: {
|
||||
blast: [0, 3000],
|
||||
laser: [4000, 1000],
|
||||
winner: [6000, 5000]
|
||||
}
|
||||
});
|
||||
|
||||
// Shoot the laser!
|
||||
sound.play('laser');
|
||||
```
|
||||
|
||||
##### Listen for events:
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3']
|
||||
});
|
||||
|
||||
// Clear listener after first call.
|
||||
sound.once('load', function(){
|
||||
sound.play();
|
||||
});
|
||||
|
||||
// Fires when the sound finishes playing.
|
||||
sound.on('end', function(){
|
||||
console.log('Finished!');
|
||||
});
|
||||
```
|
||||
|
||||
##### Control multiple sounds:
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3']
|
||||
});
|
||||
|
||||
// Play returns a unique Sound ID that can be passed
|
||||
// into any method on Howl to control that specific sound.
|
||||
var id1 = sound.play();
|
||||
var id2 = sound.play();
|
||||
|
||||
// Fade out the first sound and speed up the second.
|
||||
sound.fade(1, 0, 1000, id1);
|
||||
sound.rate(1.5, id2);
|
||||
```
|
||||
|
||||
##### ES6:
|
||||
```javascript
|
||||
import {Howl, Howler} from 'howler';
|
||||
|
||||
// Setup the new Howl.
|
||||
const sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3']
|
||||
});
|
||||
|
||||
// Play the sound.
|
||||
sound.play();
|
||||
|
||||
// Change global volume.
|
||||
Howler.volume(0.5);
|
||||
```
|
||||
|
||||
|
||||
More in-depth examples (with accompanying live demos) can be found in the [examples directory](https://github.com/goldfire/howler.js/tree/master/examples).
|
||||
|
||||
|
||||
## Core
|
||||
|
||||
### Options
|
||||
#### src `Array/String` `[]` *`required`*
|
||||
The sources to the track(s) to be loaded for the sound (URLs or base64 data URIs). These should be in order of preference, howler.js will automatically load the first one that is compatible with the current browser. If your files have no extensions, you will need to explicitly specify the extension using the `format` property.
|
||||
#### volume `Number` `1.0`
|
||||
The volume of the specific track, from `0.0` to `1.0`.
|
||||
#### html5 `Boolean` `false`
|
||||
Set to `true` to force HTML5 Audio. This should be used for large audio files so that you don't have to wait for the full file to be downloaded and decoded before playing.
|
||||
#### loop `Boolean` `false`
|
||||
Set to `true` to automatically loop the sound forever.
|
||||
#### preload `Boolean|String` `true`
|
||||
Automatically begin downloading the audio file when the `Howl` is defined. If using HTML5 Audio, you can set this to `'metadata'` to only preload the file's metadata (to get its duration without download the entire file, for example).
|
||||
#### autoplay `Boolean` `false`
|
||||
Set to `true` to automatically start playback when sound is loaded.
|
||||
#### mute `Boolean` `false`
|
||||
Set to `true` to load the audio muted.
|
||||
#### sprite `Object` `{}`
|
||||
Define a sound sprite for the sound. The offset and duration are defined in milliseconds. A third (optional) parameter is available to set a sprite as looping. An easy way to generate compatible sound sprites is with [audiosprite](https://github.com/tonistiigi/audiosprite).
|
||||
```javascript
|
||||
new Howl({
|
||||
sprite: {
|
||||
key1: [offset, duration, (loop)]
|
||||
},
|
||||
});
|
||||
```
|
||||
#### rate `Number` `1.0`
|
||||
The rate of playback. 0.5 to 4.0, with 1.0 being normal speed.
|
||||
#### pool `Number` `5`
|
||||
The size of the inactive sounds pool. Once sounds are stopped or finish playing, they are marked as ended and ready for cleanup. We keep a pool of these to recycle for improved performance. Generally this doesn't need to be changed. It is important to keep in mind that when a sound is paused, it won't be removed from the pool and will still be considered active so that it can be resumed later.
|
||||
#### format `Array` `[]`
|
||||
howler.js automatically detects your file format from the extension, but you may also specify a format in situations where extraction won't work (such as with a SoundCloud stream).
|
||||
#### xhr `Object` `null`
|
||||
When using Web Audio, howler.js uses an XHR request to load the audio files. If you need to send custom headers, set the HTTP method or enable `withCredentials` ([see reference](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)), include them with this parameter. Each is optional (method defaults to `GET`, headers default to `null` and withCredentials defaults to `false`). For example:
|
||||
```javascript
|
||||
// Using each of the properties.
|
||||
new Howl({
|
||||
xhr: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Bearer:' + token,
|
||||
},
|
||||
withCredentials: true,
|
||||
}
|
||||
});
|
||||
|
||||
// Only changing the method.
|
||||
new Howl({
|
||||
xhr: {
|
||||
method: 'POST',
|
||||
}
|
||||
});
|
||||
```
|
||||
#### onload `Function`
|
||||
Fires when the sound is loaded.
|
||||
#### onloaderror `Function`
|
||||
Fires when the sound is unable to load. The first parameter is the ID of the sound (if it exists) and the second is the error message/code.
|
||||
|
||||
The load error codes are [defined in the spec](http://dev.w3.org/html5/spec-author-view/spec.html#mediaerror):
|
||||
* **1** - The fetching process for the media resource was aborted by the user agent at the user's request.
|
||||
* **2** - A network error of some description caused the user agent to stop fetching the media resource, after the resource was established to be usable.
|
||||
* **3** - An error of some description occurred while decoding the media resource, after the resource was established to be usable.
|
||||
* **4** - The media resource indicated by the src attribute or assigned media provider object was not suitable.
|
||||
#### onplayerror `Function`
|
||||
Fires when the sound is unable to play. The first parameter is the ID of the sound and the second is the error message/code.
|
||||
#### onplay `Function`
|
||||
Fires when the sound begins playing. The first parameter is the ID of the sound.
|
||||
#### onend `Function`
|
||||
Fires when the sound finishes playing (if it is looping, it'll fire at the end of each loop). The first parameter is the ID of the sound.
|
||||
#### onpause `Function`
|
||||
Fires when the sound has been paused. The first parameter is the ID of the sound.
|
||||
#### onstop `Function`
|
||||
Fires when the sound has been stopped. The first parameter is the ID of the sound.
|
||||
#### onmute `Function`
|
||||
Fires when the sound has been muted/unmuted. The first parameter is the ID of the sound.
|
||||
#### onvolume `Function`
|
||||
Fires when the sound's volume has changed. The first parameter is the ID of the sound.
|
||||
#### onrate `Function`
|
||||
Fires when the sound's playback rate has changed. The first parameter is the ID of the sound.
|
||||
#### onseek `Function`
|
||||
Fires when the sound has been seeked. The first parameter is the ID of the sound.
|
||||
#### onfade `Function`
|
||||
Fires when the current sound finishes fading in/out. The first parameter is the ID of the sound.
|
||||
#### onunlock `Function`
|
||||
Fires when audio has been automatically unlocked through a touch/click event.
|
||||
|
||||
|
||||
### Methods
|
||||
#### play([sprite/id])
|
||||
Begins playback of a sound. Returns the sound id to be used with other methods. Only method that can't be chained.
|
||||
* **sprite/id**: `String/Number` `optional` Takes one parameter that can either be a sprite or sound ID. If a sprite is passed, a new sound will play based on the sprite's definition. If a sound ID is passed, the previously played sound will be played (for example, after pausing it). However, if an ID of a sound that has been drained from the pool is passed, nothing will play.
|
||||
|
||||
#### pause([id])
|
||||
Pauses playback of sound or group, saving the `seek` of playback.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group are paused.
|
||||
|
||||
#### stop([id])
|
||||
Stops playback of sound, resetting `seek` to `0`.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group are stopped.
|
||||
|
||||
#### mute([muted], [id])
|
||||
Mutes the sound, but doesn't pause the playback.
|
||||
* **muted**: `Boolean` `optional` True to mute and false to unmute.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group are stopped.
|
||||
|
||||
#### volume([volume], [id])
|
||||
Get/set volume of this sound or the group. This method optionally takes 0, 1 or 2 arguments.
|
||||
* **volume**: `Number` `optional` Volume from `0.0` to `1.0`.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group have volume altered relative to their own volume.
|
||||
|
||||
#### fade(from, to, duration, [id])
|
||||
Fade a currently playing sound between two volumes. Fires the `fade` event when complete.
|
||||
* **from**: `Number` Volume to fade from (`0.0` to `1.0`).
|
||||
* **to**: `Number` Volume to fade to (`0.0` to `1.0`).
|
||||
* **duration**: `Number` Time in milliseconds to fade.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group will fade.
|
||||
|
||||
#### rate([rate], [id])
|
||||
Get/set the rate of playback for a sound. This method optionally takes 0, 1 or 2 arguments.
|
||||
* **rate**: `Number` `optional` The rate of playback. 0.5 to 4.0, with 1.0 being normal speed.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, playback rate of all sounds in group will change.
|
||||
|
||||
#### seek([seek], [id])
|
||||
Get/set the position of playback for a sound. This method optionally takes 0, 1 or 2 arguments.
|
||||
* **seek**: `Number` `optional` The position to move current playback to (in seconds).
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, the first sound will seek.
|
||||
|
||||
#### loop([loop], [id])
|
||||
Get/set whether to loop the sound or group. This method can optionally take 0, 1 or 2 arguments.
|
||||
* **loop**: `Boolean` `optional` To loop or not to loop, that is the question.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all sounds in group will have their `loop` property updated.
|
||||
|
||||
#### state()
|
||||
Check the load status of the `Howl`, returns a `unloaded`, `loading` or `loaded`.
|
||||
|
||||
#### playing([id])
|
||||
Check if a sound is currently playing or not, returns a `Boolean`. If no sound ID is passed, check if any sound in the `Howl` group is playing.
|
||||
* **id**: `Number` `optional` The sound ID to check.
|
||||
|
||||
#### duration([id])
|
||||
Get the duration of the audio source (in seconds). Will return 0 until after the `load` event fires.
|
||||
* **id**: `Number` `optional` The sound ID to check. Passing an ID will return the duration of the sprite being played on this instance; otherwise, the full source duration is returned.
|
||||
|
||||
#### on(event, function, [id])
|
||||
Listen for events. Multiple events can be added by calling this multiple times.
|
||||
* **event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
|
||||
* **function**: `Function` Define function to fire on event.
|
||||
* **id**: `Number` `optional` Only listen to events for this sound id.
|
||||
|
||||
#### once(event, function, [id])
|
||||
Same as `on`, but it removes itself after the callback is fired.
|
||||
* **event**: `String` Name of event to fire/set (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
|
||||
* **function**: `Function` Define function to fire on event.
|
||||
* **id**: `Number` `optional` Only listen to events for this sound id.
|
||||
|
||||
#### off(event, [function], [id])
|
||||
Remove event listener that you've set. Call without parameters to remove all events.
|
||||
* **event**: `String` Name of event (`load`, `loaderror`, `playerror`, `play`, `end`, `pause`, `stop`, `mute`, `volume`, `rate`, `seek`, `fade`, `unlock`).
|
||||
* **function**: `Function` `optional` The listener to remove. Omit this to remove all events of type.
|
||||
* **id**: `Number` `optional` Only remove events for this sound id.
|
||||
|
||||
#### load()
|
||||
This is called by default, but if you set `preload` to false, you must call `load` before you can play any sounds.
|
||||
|
||||
#### unload()
|
||||
Unload and destroy a Howl object. This will immediately stop all sounds attached to this sound and remove it from the cache.
|
||||
|
||||
|
||||
### Global Options
|
||||
#### usingWebAudio `Boolean`
|
||||
`true` if the Web Audio API is available.
|
||||
#### noAudio `Boolean`
|
||||
`true` if no audio is available.
|
||||
#### autoUnlock `Boolean` `true`
|
||||
Automatically attempts to enable audio on mobile (iOS, Android, etc) devices and desktop Chrome/Safari.
|
||||
#### html5PoolSize `Number` `10`
|
||||
Each HTML5 Audio object must be unlocked individually, so we keep a global pool of unlocked nodes to share between all `Howl` instances. This pool gets created on the first user interaction and is set to the size of this property.
|
||||
#### autoSuspend `Boolean` `true`
|
||||
Automatically suspends the Web Audio AudioContext after 30 seconds of inactivity to decrease processing and energy usage. Automatically resumes upon new playback. Set this property to `false` to disable this behavior.
|
||||
#### ctx `Boolean` *`Web Audio Only`*
|
||||
Exposes the `AudioContext` with Web Audio API.
|
||||
#### masterGain `Boolean` *`Web Audio Only`*
|
||||
Exposes the master `GainNode` with Web Audio API. This can be useful for writing plugins or advanced usage.
|
||||
|
||||
|
||||
### Global Methods
|
||||
The following methods are used to modify all sounds globally, and are called from the `Howler` object.
|
||||
#### mute(muted)
|
||||
Mute or unmute all sounds.
|
||||
* **muted**: `Boolean` True to mute and false to unmute.
|
||||
|
||||
#### volume([volume])
|
||||
Get/set the global volume for all sounds, relative to their own volume.
|
||||
* **volume**: `Number` `optional` Volume from `0.0` to `1.0`.
|
||||
|
||||
#### stop()
|
||||
Stop all sounds and reset their seek position to the beginning.
|
||||
|
||||
#### codecs(ext)
|
||||
Check supported audio codecs. Returns `true` if the codec is supported in the current browser.
|
||||
* **ext**: `String` File extension. One of: "mp3", "mpeg", "opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac".
|
||||
|
||||
#### unload()
|
||||
Unload and destroy all currently loaded Howl objects. This will immediately stop all sounds and remove them from cache.
|
||||
|
||||
|
||||
## Plugin: Spatial
|
||||
|
||||
### Options
|
||||
#### orientation `Array` `[1, 0, 0]`
|
||||
Sets the direction the audio source is pointing in the 3D cartesian coordinate space. Depending on how directional the sound is, based on the `cone` attributes, a sound pointing away from the listener can be quiet or silent.
|
||||
#### stereo `Number` `null`
|
||||
Sets the stereo panning value of the audio source for this sound or group. This makes it easy to setup left/right panning with a value of `-1.0` being far left and a value of `1.0` being far right.
|
||||
#### pos `Array` `null`
|
||||
Sets the 3D spatial position of the audio source for this sound or group relative to the global listener.
|
||||
#### pannerAttr `Object`
|
||||
Sets the panner node's attributes for a sound or group of sounds. See the `pannerAttr` method for all available options.
|
||||
#### onstereo `Function`
|
||||
Fires when the current sound has the stereo panning changed. The first parameter is the ID of the sound.
|
||||
#### onpos `Function`
|
||||
Fires when the current sound has the listener position changed. The first parameter is the ID of the sound.
|
||||
#### onorientation `Function`
|
||||
Fires when the current sound has the direction of the listener changed. The first parameter is the ID of the sound.
|
||||
|
||||
|
||||
### Methods
|
||||
#### stereo(pan, [id])
|
||||
Get/set the stereo panning of the audio source for this sound or all in the group.
|
||||
* **pan**: `Number` A value of `-1.0` is all the way left and `1.0` is all the way right.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all in group will be updated.
|
||||
|
||||
#### pos(x, y, z, [id])
|
||||
Get/set the 3D spatial position of the audio source for this sound or group relative to the global listener.
|
||||
* **x**: `Number` The x-position of the audio source.
|
||||
* **y**: `Number` The y-position of the audio source.
|
||||
* **z**: `Number` The z-position of the audio source.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all in group will be updated.
|
||||
|
||||
#### orientation(x, y, z, [id])
|
||||
Get/set the direction the audio source is pointing in the 3D cartesian coordinate space. Depending on how directional the sound is, based on the `cone` attributes, a sound pointing away from the listener can be quiet or silent.
|
||||
* **x**: `Number` The x-orientation of the source.
|
||||
* **y**: `Number` The y-orientation of the source.
|
||||
* **z**: `Number` The z-orientation of the source.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all in group will be updated.
|
||||
|
||||
#### pannerAttr(o, [id])
|
||||
Get/set the panner node's attributes for a sound or group of sounds.
|
||||
* **o**: `Object` All values to update.
|
||||
* **coneInnerAngle** `360` A parameter for directional audio sources, this is an angle, in degrees, inside of which there will be no volume reduction.
|
||||
* **coneOuterAngle** `360` A parameter for directional audio sources, this is an angle, in degrees, outside of which the volume will be reduced to a constant value of `coneOuterGain`.
|
||||
* **coneOuterGain** `0` A parameter for directional audio sources, this is the gain outside of the `coneOuterAngle`. It is a linear value in the range `[0, 1]`.
|
||||
* **distanceModel** `inverse` Determines algorithm used to reduce volume as audio moves away from listener. Can be `linear`, `inverse` or `exponential`. You can find the implementations of each in the [spec](https://webaudio.github.io/web-audio-api/#idl-def-DistanceModelType).
|
||||
* **maxDistance** `10000` The maximum distance between source and listener, after which the volume will not be reduced any further.
|
||||
* **refDistance** `1` A reference distance for reducing volume as source moves further from the listener. This is simply a variable of the distance model and has a different effect depending on which model is used and the scale of your coordinates. Generally, volume will be equal to 1 at this distance.
|
||||
* **rolloffFactor** `1` How quickly the volume reduces as source moves from listener. This is simply a variable of the distance model and can be in the range of `[0, 1]` with `linear` and `[0, ∞]` with `inverse` and `exponential`.
|
||||
* **panningModel** `HRTF` Determines which spatialization algorithm is used to position audio. Can be `HRTF` or `equalpower`.
|
||||
* **id**: `Number` `optional` The sound ID. If none is passed, all in group will be updated.
|
||||
|
||||
|
||||
### Global Methods
|
||||
#### stereo(pan)
|
||||
Helper method to update the stereo panning position of all current `Howls`. Future `Howls` will not use this value unless explicitly set.
|
||||
* **pan**: `Number` A value of -1.0 is all the way left and 1.0 is all the way right.
|
||||
|
||||
#### pos(x, y, z)
|
||||
Get/set the position of the listener in 3D cartesian space. Sounds using 3D position will be relative to the listener's position.
|
||||
* **x**: `Number` The x-position of the listener.
|
||||
* **y**: `Number` The y-position of the listener.
|
||||
* **z**: `Number` The z-position of the listener.
|
||||
|
||||
#### orientation(x, y, z, xUp, yUp, zUp)
|
||||
Get/set the direction the listener is pointing in the 3D cartesian space. A front and up vector must be provided. The front is the direction the face of the listener is pointing, and up is the direction the top of the listener is pointing. Thus, these values are expected to be at right angles from each other.
|
||||
* **x**: `Number` The x-orientation of listener.
|
||||
* **y**: `Number` The y-orientation of listener.
|
||||
* **z**: `Number` The z-orientation of listener.
|
||||
* **xUp**: `Number` The x-orientation of the top of the listener.
|
||||
* **yUp**: `Number` The y-orientation of the top of the listener.
|
||||
* **zUp**: `Number` The z-orientation of the top of the listener.
|
||||
|
||||
|
||||
### Group Playback
|
||||
Each `new Howl()` instance is also a group. You can play multiple sound instances from the `Howl` and control them individually or as a group (note: each `Howl` can only contain a single audio file). For example, the following plays two sounds from a sprite, changes their volume together and then pauses both of them at the same time.
|
||||
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3'],
|
||||
sprite: {
|
||||
track01: [0, 20000],
|
||||
track02: [21000, 41000]
|
||||
}
|
||||
});
|
||||
|
||||
// Play each of the track.s
|
||||
sound.play('track01');
|
||||
sound.play('track02');
|
||||
|
||||
// Change the volume of both tracks.
|
||||
sound.volume(0.5);
|
||||
|
||||
// After a second, pause both sounds in the group.
|
||||
setTimeout(function() {
|
||||
sound.pause();
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
|
||||
### Mobile/Chrome Playback
|
||||
By default, audio on mobile browsers and Chrome/Safari is locked until a sound is played within a user interaction, and then it plays normally the rest of the page session ([Apple documentation](https://developer.apple.com/library/safari/documentation/audiovideo/conceptual/using_html5_audio_video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html)). The default behavior of howler.js is to attempt to silently unlock audio playback by playing an empty buffer on the first `touchend` event. This behavior can be disabled by calling:
|
||||
|
||||
```javascript
|
||||
Howler.autoUnlock = false;
|
||||
```
|
||||
|
||||
If you try to play audio automatically on page load, you can listen to a `playerror` event and then wait for the `unlock` event to try and play the audio again:
|
||||
|
||||
```javascript
|
||||
var sound = new Howl({
|
||||
src: ['sound.webm', 'sound.mp3'],
|
||||
onplayerror: function() {
|
||||
sound.once('unlock', function() {
|
||||
sound.play();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
sound.play();
|
||||
```
|
||||
|
||||
|
||||
### Dolby Audio Playback
|
||||
Full support for playback of the Dolby Audio format (currently support in Edge and Safari) is included. However, you must specify that the file you are loading is `dolby` since it is in a `mp4` container.
|
||||
|
||||
```javascript
|
||||
var dolbySound = new Howl({
|
||||
src: ['sound.mp4', 'sound.webm', 'sound.mp3'],
|
||||
format: ['dolby', 'webm', 'mp3']
|
||||
});
|
||||
```
|
||||
|
||||
### Facebook Instant Games
|
||||
Howler.js provides audio support for the new [Facebook Instant Games](https://developers.facebook.com/docs/games/instant-games/engine-recommendations) platform. If you encounter any issues while developing for Instant Games, open an issue with the tag `[IG]`.
|
||||
|
||||
### Format Recommendations
|
||||
Howler.js supports a wide array of audio codecs that have varying browser support ("mp3", "opus", "ogg", "wav", "aac", "m4a", "m4b", "mp4", "webm", ...), but if you want full browser coverage you still need to use at least two of them. If your goal is to have the best balance of small filesize and high quality, based on extensive production testing, your best bet is to default to `webm` and fallback to `mp3`. `webm` has nearly full browser coverage with a great combination of compression and quality. You'll need the `mp3` fallback for Internet Explorer.
|
||||
|
||||
It is important to remember that howler.js selects the first compatible sound from your array of sources. So if you want `webm` to be used before `mp3`, you need to put the sources in that order.
|
||||
|
||||
If you want your `webm` files to be seekable in Firefox, be sure to encode them with the cues element. One way to do this is by using the `dash` flag in [ffmpeg](https://www.ffmpeg.org/):
|
||||
|
||||
```
|
||||
ffmpeg -i sound1.wav -dash 1 sound1.webm
|
||||
```
|
||||
|
||||
### Sponsors
|
||||
Support the ongoing development of howler.js and get your logo on our README with a link to your site [[become a sponsor](https://github.com/sponsors/goldfire)]. You can also become a backer at a lower tier and get your name in the [BACKERS](https://github.com/goldfire/howler.js/blob/master/BACKERS.md) list. All support is greatly appreciated!
|
||||
|
||||
[](https://goldfirestudios.com)
|
||||
|
||||
### License
|
||||
|
||||
Copyright (c) 2013-2021 [James Simpson](https://twitter.com/GoldFireStudios) and [GoldFire Studios, Inc.](http://goldfirestudios.com)
|
||||
|
||||
Released under the [MIT License](https://github.com/goldfire/howler.js/blob/master/LICENSE.md).
|
2
public/scripts/howler/dist/howler.core.min.js
vendored
Normal file
2
public/scripts/howler/dist/howler.core.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
3248
public/scripts/howler/dist/howler.js
vendored
Normal file
3248
public/scripts/howler/dist/howler.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
public/scripts/howler/dist/howler.min.js
vendored
Normal file
4
public/scripts/howler/dist/howler.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
public/scripts/howler/dist/howler.spatial.min.js
vendored
Normal file
2
public/scripts/howler/dist/howler.spatial.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
41
public/scripts/howler/package.json
Normal file
41
public/scripts/howler/package.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "howler",
|
||||
"version": "2.2.4",
|
||||
"description": "Javascript audio library for the modern web.",
|
||||
"homepage": "https://howlerjs.com",
|
||||
"keywords": [
|
||||
"howler",
|
||||
"howler.js",
|
||||
"audio",
|
||||
"sound",
|
||||
"web audio",
|
||||
"webaudio",
|
||||
"browser",
|
||||
"html5",
|
||||
"html5 audio",
|
||||
"audio sprite",
|
||||
"audiosprite"
|
||||
],
|
||||
"author": "James Simpson <james@goldfirestudios.com> (http://goldfirestudios.com)",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/goldfire/howler.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "VERSION=`printf 'v' && node -e 'console.log(require(\"./package.json\").version)'` && sed -i '' '2s/.*/ * howler.js '\"$VERSION\"'/' src/howler.core.js && sed -i '' '4s/.*/ * howler.js '\"$VERSION\"'/' src/plugins/howler.spatial.js && uglifyjs --preamble \"/*! howler.js $VERSION | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */\" src/howler.core.js -c -m --screw-ie8 -o dist/howler.core.min.js && uglifyjs --preamble \"/*! howler.js $VERSION | Spatial Plugin | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */\" src/plugins/howler.spatial.js -c -m --screw-ie8 -o dist/howler.spatial.min.js && awk 'FNR==1{echo \"\"}1' dist/howler.core.min.js dist/howler.spatial.min.js | sed '3s~.*~/*! Spatial Plugin */~' | perl -pe 'chomp if eof' > dist/howler.min.js && awk '(NR>1 && FNR==1){printf (\"\\n\\n\")};1' src/howler.core.js src/plugins/howler.spatial.js > dist/howler.js",
|
||||
"release": "VERSION=`printf 'v' && node -e 'console.log(require(\"./package.json\").version)'` && git tag $VERSION && git push && git push origin $VERSION && npm publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"uglify-js": "2.x"
|
||||
},
|
||||
"main": "dist/howler.js",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"src",
|
||||
"dist/howler.js",
|
||||
"dist/howler.min.js",
|
||||
"dist/howler.core.min.js",
|
||||
"dist/howler.spatial.min.js",
|
||||
"LICENSE.md"
|
||||
]
|
||||
}
|
2587
public/scripts/howler/src/howler.core.js
Normal file
2587
public/scripts/howler/src/howler.core.js
Normal file
File diff suppressed because it is too large
Load Diff
659
public/scripts/howler/src/plugins/howler.spatial.js
Normal file
659
public/scripts/howler/src/plugins/howler.spatial.js
Normal file
@ -0,0 +1,659 @@
|
||||
/*!
|
||||
* Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported.
|
||||
*
|
||||
* howler.js v2.2.4
|
||||
* howlerjs.com
|
||||
*
|
||||
* (c) 2013-2020, James Simpson of GoldFire Studios
|
||||
* goldfirestudios.com
|
||||
*
|
||||
* MIT License
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Setup default properties.
|
||||
HowlerGlobal.prototype._pos = [0, 0, 0];
|
||||
HowlerGlobal.prototype._orientation = [0, 0, -1, 0, 1, 0];
|
||||
|
||||
/** Global Methods **/
|
||||
/***************************************************************************/
|
||||
|
||||
/**
|
||||
* Helper method to update the stereo panning position of all current Howls.
|
||||
* Future Howls will not use this value unless explicitly set.
|
||||
* @param {Number} pan A value of -1.0 is all the way left and 1.0 is all the way right.
|
||||
* @return {Howler/Number} Self or current stereo panning value.
|
||||
*/
|
||||
HowlerGlobal.prototype.stereo = function(pan) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self.ctx || !self.ctx.listener) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Loop through all Howls and update their stereo panning.
|
||||
for (var i=self._howls.length-1; i>=0; i--) {
|
||||
self._howls[i].stereo(pan);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the position of the listener in 3D cartesian space. Sounds using
|
||||
* 3D position will be relative to the listener's position.
|
||||
* @param {Number} x The x-position of the listener.
|
||||
* @param {Number} y The y-position of the listener.
|
||||
* @param {Number} z The z-position of the listener.
|
||||
* @return {Howler/Array} Self or current listener position.
|
||||
*/
|
||||
HowlerGlobal.prototype.pos = function(x, y, z) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self.ctx || !self.ctx.listener) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Set the defaults for optional 'y' & 'z'.
|
||||
y = (typeof y !== 'number') ? self._pos[1] : y;
|
||||
z = (typeof z !== 'number') ? self._pos[2] : z;
|
||||
|
||||
if (typeof x === 'number') {
|
||||
self._pos = [x, y, z];
|
||||
|
||||
if (typeof self.ctx.listener.positionX !== 'undefined') {
|
||||
self.ctx.listener.positionX.setTargetAtTime(self._pos[0], Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.positionY.setTargetAtTime(self._pos[1], Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.positionZ.setTargetAtTime(self._pos[2], Howler.ctx.currentTime, 0.1);
|
||||
} else {
|
||||
self.ctx.listener.setPosition(self._pos[0], self._pos[1], self._pos[2]);
|
||||
}
|
||||
} else {
|
||||
return self._pos;
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the direction the listener is pointing in the 3D cartesian space.
|
||||
* A front and up vector must be provided. The front is the direction the
|
||||
* face of the listener is pointing, and up is the direction the top of the
|
||||
* listener is pointing. Thus, these values are expected to be at right angles
|
||||
* from each other.
|
||||
* @param {Number} x The x-orientation of the listener.
|
||||
* @param {Number} y The y-orientation of the listener.
|
||||
* @param {Number} z The z-orientation of the listener.
|
||||
* @param {Number} xUp The x-orientation of the top of the listener.
|
||||
* @param {Number} yUp The y-orientation of the top of the listener.
|
||||
* @param {Number} zUp The z-orientation of the top of the listener.
|
||||
* @return {Howler/Array} Returns self or the current orientation vectors.
|
||||
*/
|
||||
HowlerGlobal.prototype.orientation = function(x, y, z, xUp, yUp, zUp) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self.ctx || !self.ctx.listener) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Set the defaults for optional 'y' & 'z'.
|
||||
var or = self._orientation;
|
||||
y = (typeof y !== 'number') ? or[1] : y;
|
||||
z = (typeof z !== 'number') ? or[2] : z;
|
||||
xUp = (typeof xUp !== 'number') ? or[3] : xUp;
|
||||
yUp = (typeof yUp !== 'number') ? or[4] : yUp;
|
||||
zUp = (typeof zUp !== 'number') ? or[5] : zUp;
|
||||
|
||||
if (typeof x === 'number') {
|
||||
self._orientation = [x, y, z, xUp, yUp, zUp];
|
||||
|
||||
if (typeof self.ctx.listener.forwardX !== 'undefined') {
|
||||
self.ctx.listener.forwardX.setTargetAtTime(x, Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.forwardY.setTargetAtTime(y, Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.forwardZ.setTargetAtTime(z, Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.upX.setTargetAtTime(xUp, Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.upY.setTargetAtTime(yUp, Howler.ctx.currentTime, 0.1);
|
||||
self.ctx.listener.upZ.setTargetAtTime(zUp, Howler.ctx.currentTime, 0.1);
|
||||
} else {
|
||||
self.ctx.listener.setOrientation(x, y, z, xUp, yUp, zUp);
|
||||
}
|
||||
} else {
|
||||
return or;
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/** Group Methods **/
|
||||
/***************************************************************************/
|
||||
|
||||
/**
|
||||
* Add new properties to the core init.
|
||||
* @param {Function} _super Core init method.
|
||||
* @return {Howl}
|
||||
*/
|
||||
Howl.prototype.init = (function(_super) {
|
||||
return function(o) {
|
||||
var self = this;
|
||||
|
||||
// Setup user-defined default properties.
|
||||
self._orientation = o.orientation || [1, 0, 0];
|
||||
self._stereo = o.stereo || null;
|
||||
self._pos = o.pos || null;
|
||||
self._pannerAttr = {
|
||||
coneInnerAngle: typeof o.coneInnerAngle !== 'undefined' ? o.coneInnerAngle : 360,
|
||||
coneOuterAngle: typeof o.coneOuterAngle !== 'undefined' ? o.coneOuterAngle : 360,
|
||||
coneOuterGain: typeof o.coneOuterGain !== 'undefined' ? o.coneOuterGain : 0,
|
||||
distanceModel: typeof o.distanceModel !== 'undefined' ? o.distanceModel : 'inverse',
|
||||
maxDistance: typeof o.maxDistance !== 'undefined' ? o.maxDistance : 10000,
|
||||
panningModel: typeof o.panningModel !== 'undefined' ? o.panningModel : 'HRTF',
|
||||
refDistance: typeof o.refDistance !== 'undefined' ? o.refDistance : 1,
|
||||
rolloffFactor: typeof o.rolloffFactor !== 'undefined' ? o.rolloffFactor : 1
|
||||
};
|
||||
|
||||
// Setup event listeners.
|
||||
self._onstereo = o.onstereo ? [{fn: o.onstereo}] : [];
|
||||
self._onpos = o.onpos ? [{fn: o.onpos}] : [];
|
||||
self._onorientation = o.onorientation ? [{fn: o.onorientation}] : [];
|
||||
|
||||
// Complete initilization with howler.js core's init function.
|
||||
return _super.call(this, o);
|
||||
};
|
||||
})(Howl.prototype.init);
|
||||
|
||||
/**
|
||||
* Get/set the stereo panning of the audio source for this sound or all in the group.
|
||||
* @param {Number} pan A value of -1.0 is all the way left and 1.0 is all the way right.
|
||||
* @param {Number} id (optional) The sound ID. If none is passed, all in group will be updated.
|
||||
* @return {Howl/Number} Returns self or the current stereo panning value.
|
||||
*/
|
||||
Howl.prototype.stereo = function(pan, id) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self._webAudio) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// If the sound hasn't loaded, add it to the load queue to change stereo pan when capable.
|
||||
if (self._state !== 'loaded') {
|
||||
self._queue.push({
|
||||
event: 'stereo',
|
||||
action: function() {
|
||||
self.stereo(pan, id);
|
||||
}
|
||||
});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Check for PannerStereoNode support and fallback to PannerNode if it doesn't exist.
|
||||
var pannerType = (typeof Howler.ctx.createStereoPanner === 'undefined') ? 'spatial' : 'stereo';
|
||||
|
||||
// Setup the group's stereo panning if no ID is passed.
|
||||
if (typeof id === 'undefined') {
|
||||
// Return the group's stereo panning if no parameters are passed.
|
||||
if (typeof pan === 'number') {
|
||||
self._stereo = pan;
|
||||
self._pos = [pan, 0, 0];
|
||||
} else {
|
||||
return self._stereo;
|
||||
}
|
||||
}
|
||||
|
||||
// Change the streo panning of one or all sounds in group.
|
||||
var ids = self._getSoundIds(id);
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
// Get the sound.
|
||||
var sound = self._soundById(ids[i]);
|
||||
|
||||
if (sound) {
|
||||
if (typeof pan === 'number') {
|
||||
sound._stereo = pan;
|
||||
sound._pos = [pan, 0, 0];
|
||||
|
||||
if (sound._node) {
|
||||
// If we are falling back, make sure the panningModel is equalpower.
|
||||
sound._pannerAttr.panningModel = 'equalpower';
|
||||
|
||||
// Check if there is a panner setup and create a new one if not.
|
||||
if (!sound._panner || !sound._panner.pan) {
|
||||
setupPanner(sound, pannerType);
|
||||
}
|
||||
|
||||
if (pannerType === 'spatial') {
|
||||
if (typeof sound._panner.positionX !== 'undefined') {
|
||||
sound._panner.positionX.setValueAtTime(pan, Howler.ctx.currentTime);
|
||||
sound._panner.positionY.setValueAtTime(0, Howler.ctx.currentTime);
|
||||
sound._panner.positionZ.setValueAtTime(0, Howler.ctx.currentTime);
|
||||
} else {
|
||||
sound._panner.setPosition(pan, 0, 0);
|
||||
}
|
||||
} else {
|
||||
sound._panner.pan.setValueAtTime(pan, Howler.ctx.currentTime);
|
||||
}
|
||||
}
|
||||
|
||||
self._emit('stereo', sound._id);
|
||||
} else {
|
||||
return sound._stereo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the 3D spatial position of the audio source for this sound or group relative to the global listener.
|
||||
* @param {Number} x The x-position of the audio source.
|
||||
* @param {Number} y The y-position of the audio source.
|
||||
* @param {Number} z The z-position of the audio source.
|
||||
* @param {Number} id (optional) The sound ID. If none is passed, all in group will be updated.
|
||||
* @return {Howl/Array} Returns self or the current 3D spatial position: [x, y, z].
|
||||
*/
|
||||
Howl.prototype.pos = function(x, y, z, id) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self._webAudio) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// If the sound hasn't loaded, add it to the load queue to change position when capable.
|
||||
if (self._state !== 'loaded') {
|
||||
self._queue.push({
|
||||
event: 'pos',
|
||||
action: function() {
|
||||
self.pos(x, y, z, id);
|
||||
}
|
||||
});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Set the defaults for optional 'y' & 'z'.
|
||||
y = (typeof y !== 'number') ? 0 : y;
|
||||
z = (typeof z !== 'number') ? -0.5 : z;
|
||||
|
||||
// Setup the group's spatial position if no ID is passed.
|
||||
if (typeof id === 'undefined') {
|
||||
// Return the group's spatial position if no parameters are passed.
|
||||
if (typeof x === 'number') {
|
||||
self._pos = [x, y, z];
|
||||
} else {
|
||||
return self._pos;
|
||||
}
|
||||
}
|
||||
|
||||
// Change the spatial position of one or all sounds in group.
|
||||
var ids = self._getSoundIds(id);
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
// Get the sound.
|
||||
var sound = self._soundById(ids[i]);
|
||||
|
||||
if (sound) {
|
||||
if (typeof x === 'number') {
|
||||
sound._pos = [x, y, z];
|
||||
|
||||
if (sound._node) {
|
||||
// Check if there is a panner setup and create a new one if not.
|
||||
if (!sound._panner || sound._panner.pan) {
|
||||
setupPanner(sound, 'spatial');
|
||||
}
|
||||
|
||||
if (typeof sound._panner.positionX !== 'undefined') {
|
||||
sound._panner.positionX.setValueAtTime(x, Howler.ctx.currentTime);
|
||||
sound._panner.positionY.setValueAtTime(y, Howler.ctx.currentTime);
|
||||
sound._panner.positionZ.setValueAtTime(z, Howler.ctx.currentTime);
|
||||
} else {
|
||||
sound._panner.setPosition(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
self._emit('pos', sound._id);
|
||||
} else {
|
||||
return sound._pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the direction the audio source is pointing in the 3D cartesian coordinate
|
||||
* space. Depending on how direction the sound is, based on the `cone` attributes,
|
||||
* a sound pointing away from the listener can be quiet or silent.
|
||||
* @param {Number} x The x-orientation of the source.
|
||||
* @param {Number} y The y-orientation of the source.
|
||||
* @param {Number} z The z-orientation of the source.
|
||||
* @param {Number} id (optional) The sound ID. If none is passed, all in group will be updated.
|
||||
* @return {Howl/Array} Returns self or the current 3D spatial orientation: [x, y, z].
|
||||
*/
|
||||
Howl.prototype.orientation = function(x, y, z, id) {
|
||||
var self = this;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self._webAudio) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// If the sound hasn't loaded, add it to the load queue to change orientation when capable.
|
||||
if (self._state !== 'loaded') {
|
||||
self._queue.push({
|
||||
event: 'orientation',
|
||||
action: function() {
|
||||
self.orientation(x, y, z, id);
|
||||
}
|
||||
});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Set the defaults for optional 'y' & 'z'.
|
||||
y = (typeof y !== 'number') ? self._orientation[1] : y;
|
||||
z = (typeof z !== 'number') ? self._orientation[2] : z;
|
||||
|
||||
// Setup the group's spatial orientation if no ID is passed.
|
||||
if (typeof id === 'undefined') {
|
||||
// Return the group's spatial orientation if no parameters are passed.
|
||||
if (typeof x === 'number') {
|
||||
self._orientation = [x, y, z];
|
||||
} else {
|
||||
return self._orientation;
|
||||
}
|
||||
}
|
||||
|
||||
// Change the spatial orientation of one or all sounds in group.
|
||||
var ids = self._getSoundIds(id);
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
// Get the sound.
|
||||
var sound = self._soundById(ids[i]);
|
||||
|
||||
if (sound) {
|
||||
if (typeof x === 'number') {
|
||||
sound._orientation = [x, y, z];
|
||||
|
||||
if (sound._node) {
|
||||
// Check if there is a panner setup and create a new one if not.
|
||||
if (!sound._panner) {
|
||||
// Make sure we have a position to setup the node with.
|
||||
if (!sound._pos) {
|
||||
sound._pos = self._pos || [0, 0, -0.5];
|
||||
}
|
||||
|
||||
setupPanner(sound, 'spatial');
|
||||
}
|
||||
|
||||
if (typeof sound._panner.orientationX !== 'undefined') {
|
||||
sound._panner.orientationX.setValueAtTime(x, Howler.ctx.currentTime);
|
||||
sound._panner.orientationY.setValueAtTime(y, Howler.ctx.currentTime);
|
||||
sound._panner.orientationZ.setValueAtTime(z, Howler.ctx.currentTime);
|
||||
} else {
|
||||
sound._panner.setOrientation(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
self._emit('orientation', sound._id);
|
||||
} else {
|
||||
return sound._orientation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get/set the panner node's attributes for a sound or group of sounds.
|
||||
* This method can optionall take 0, 1 or 2 arguments.
|
||||
* pannerAttr() -> Returns the group's values.
|
||||
* pannerAttr(id) -> Returns the sound id's values.
|
||||
* pannerAttr(o) -> Set's the values of all sounds in this Howl group.
|
||||
* pannerAttr(o, id) -> Set's the values of passed sound id.
|
||||
*
|
||||
* Attributes:
|
||||
* coneInnerAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
|
||||
* inside of which there will be no volume reduction.
|
||||
* coneOuterAngle - (360 by default) A parameter for directional audio sources, this is an angle, in degrees,
|
||||
* outside of which the volume will be reduced to a constant value of `coneOuterGain`.
|
||||
* coneOuterGain - (0 by default) A parameter for directional audio sources, this is the gain outside of the
|
||||
* `coneOuterAngle`. It is a linear value in the range `[0, 1]`.
|
||||
* distanceModel - ('inverse' by default) Determines algorithm used to reduce volume as audio moves away from
|
||||
* listener. Can be `linear`, `inverse` or `exponential.
|
||||
* maxDistance - (10000 by default) The maximum distance between source and listener, after which the volume
|
||||
* will not be reduced any further.
|
||||
* refDistance - (1 by default) A reference distance for reducing volume as source moves further from the listener.
|
||||
* This is simply a variable of the distance model and has a different effect depending on which model
|
||||
* is used and the scale of your coordinates. Generally, volume will be equal to 1 at this distance.
|
||||
* rolloffFactor - (1 by default) How quickly the volume reduces as source moves from listener. This is simply a
|
||||
* variable of the distance model and can be in the range of `[0, 1]` with `linear` and `[0, ∞]`
|
||||
* with `inverse` and `exponential`.
|
||||
* panningModel - ('HRTF' by default) Determines which spatialization algorithm is used to position audio.
|
||||
* Can be `HRTF` or `equalpower`.
|
||||
*
|
||||
* @return {Howl/Object} Returns self or current panner attributes.
|
||||
*/
|
||||
Howl.prototype.pannerAttr = function() {
|
||||
var self = this;
|
||||
var args = arguments;
|
||||
var o, id, sound;
|
||||
|
||||
// Stop right here if not using Web Audio.
|
||||
if (!self._webAudio) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Determine the values based on arguments.
|
||||
if (args.length === 0) {
|
||||
// Return the group's panner attribute values.
|
||||
return self._pannerAttr;
|
||||
} else if (args.length === 1) {
|
||||
if (typeof args[0] === 'object') {
|
||||
o = args[0];
|
||||
|
||||
// Set the grou's panner attribute values.
|
||||
if (typeof id === 'undefined') {
|
||||
if (!o.pannerAttr) {
|
||||
o.pannerAttr = {
|
||||
coneInnerAngle: o.coneInnerAngle,
|
||||
coneOuterAngle: o.coneOuterAngle,
|
||||
coneOuterGain: o.coneOuterGain,
|
||||
distanceModel: o.distanceModel,
|
||||
maxDistance: o.maxDistance,
|
||||
refDistance: o.refDistance,
|
||||
rolloffFactor: o.rolloffFactor,
|
||||
panningModel: o.panningModel
|
||||
};
|
||||
}
|
||||
|
||||
self._pannerAttr = {
|
||||
coneInnerAngle: typeof o.pannerAttr.coneInnerAngle !== 'undefined' ? o.pannerAttr.coneInnerAngle : self._coneInnerAngle,
|
||||
coneOuterAngle: typeof o.pannerAttr.coneOuterAngle !== 'undefined' ? o.pannerAttr.coneOuterAngle : self._coneOuterAngle,
|
||||
coneOuterGain: typeof o.pannerAttr.coneOuterGain !== 'undefined' ? o.pannerAttr.coneOuterGain : self._coneOuterGain,
|
||||
distanceModel: typeof o.pannerAttr.distanceModel !== 'undefined' ? o.pannerAttr.distanceModel : self._distanceModel,
|
||||
maxDistance: typeof o.pannerAttr.maxDistance !== 'undefined' ? o.pannerAttr.maxDistance : self._maxDistance,
|
||||
refDistance: typeof o.pannerAttr.refDistance !== 'undefined' ? o.pannerAttr.refDistance : self._refDistance,
|
||||
rolloffFactor: typeof o.pannerAttr.rolloffFactor !== 'undefined' ? o.pannerAttr.rolloffFactor : self._rolloffFactor,
|
||||
panningModel: typeof o.pannerAttr.panningModel !== 'undefined' ? o.pannerAttr.panningModel : self._panningModel
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Return this sound's panner attribute values.
|
||||
sound = self._soundById(parseInt(args[0], 10));
|
||||
return sound ? sound._pannerAttr : self._pannerAttr;
|
||||
}
|
||||
} else if (args.length === 2) {
|
||||
o = args[0];
|
||||
id = parseInt(args[1], 10);
|
||||
}
|
||||
|
||||
// Update the values of the specified sounds.
|
||||
var ids = self._getSoundIds(id);
|
||||
for (var i=0; i<ids.length; i++) {
|
||||
sound = self._soundById(ids[i]);
|
||||
|
||||
if (sound) {
|
||||
// Merge the new values into the sound.
|
||||
var pa = sound._pannerAttr;
|
||||
pa = {
|
||||
coneInnerAngle: typeof o.coneInnerAngle !== 'undefined' ? o.coneInnerAngle : pa.coneInnerAngle,
|
||||
coneOuterAngle: typeof o.coneOuterAngle !== 'undefined' ? o.coneOuterAngle : pa.coneOuterAngle,
|
||||
coneOuterGain: typeof o.coneOuterGain !== 'undefined' ? o.coneOuterGain : pa.coneOuterGain,
|
||||
distanceModel: typeof o.distanceModel !== 'undefined' ? o.distanceModel : pa.distanceModel,
|
||||
maxDistance: typeof o.maxDistance !== 'undefined' ? o.maxDistance : pa.maxDistance,
|
||||
refDistance: typeof o.refDistance !== 'undefined' ? o.refDistance : pa.refDistance,
|
||||
rolloffFactor: typeof o.rolloffFactor !== 'undefined' ? o.rolloffFactor : pa.rolloffFactor,
|
||||
panningModel: typeof o.panningModel !== 'undefined' ? o.panningModel : pa.panningModel
|
||||
};
|
||||
|
||||
// Create a new panner node if one doesn't already exist.
|
||||
var panner = sound._panner;
|
||||
if (!panner) {
|
||||
// Make sure we have a position to setup the node with.
|
||||
if (!sound._pos) {
|
||||
sound._pos = self._pos || [0, 0, -0.5];
|
||||
}
|
||||
|
||||
// Create a new panner node.
|
||||
setupPanner(sound, 'spatial');
|
||||
panner = sound._panner
|
||||
}
|
||||
|
||||
// Update the panner values or create a new panner if none exists.
|
||||
panner.coneInnerAngle = pa.coneInnerAngle;
|
||||
panner.coneOuterAngle = pa.coneOuterAngle;
|
||||
panner.coneOuterGain = pa.coneOuterGain;
|
||||
panner.distanceModel = pa.distanceModel;
|
||||
panner.maxDistance = pa.maxDistance;
|
||||
panner.refDistance = pa.refDistance;
|
||||
panner.rolloffFactor = pa.rolloffFactor;
|
||||
panner.panningModel = pa.panningModel;
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/** Single Sound Methods **/
|
||||
/***************************************************************************/
|
||||
|
||||
/**
|
||||
* Add new properties to the core Sound init.
|
||||
* @param {Function} _super Core Sound init method.
|
||||
* @return {Sound}
|
||||
*/
|
||||
Sound.prototype.init = (function(_super) {
|
||||
return function() {
|
||||
var self = this;
|
||||
var parent = self._parent;
|
||||
|
||||
// Setup user-defined default properties.
|
||||
self._orientation = parent._orientation;
|
||||
self._stereo = parent._stereo;
|
||||
self._pos = parent._pos;
|
||||
self._pannerAttr = parent._pannerAttr;
|
||||
|
||||
// Complete initilization with howler.js core Sound's init function.
|
||||
_super.call(this);
|
||||
|
||||
// If a stereo or position was specified, set it up.
|
||||
if (self._stereo) {
|
||||
parent.stereo(self._stereo);
|
||||
} else if (self._pos) {
|
||||
parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
|
||||
}
|
||||
};
|
||||
})(Sound.prototype.init);
|
||||
|
||||
/**
|
||||
* Override the Sound.reset method to clean up properties from the spatial plugin.
|
||||
* @param {Function} _super Sound reset method.
|
||||
* @return {Sound}
|
||||
*/
|
||||
Sound.prototype.reset = (function(_super) {
|
||||
return function() {
|
||||
var self = this;
|
||||
var parent = self._parent;
|
||||
|
||||
// Reset all spatial plugin properties on this sound.
|
||||
self._orientation = parent._orientation;
|
||||
self._stereo = parent._stereo;
|
||||
self._pos = parent._pos;
|
||||
self._pannerAttr = parent._pannerAttr;
|
||||
|
||||
// If a stereo or position was specified, set it up.
|
||||
if (self._stereo) {
|
||||
parent.stereo(self._stereo);
|
||||
} else if (self._pos) {
|
||||
parent.pos(self._pos[0], self._pos[1], self._pos[2], self._id);
|
||||
} else if (self._panner) {
|
||||
// Disconnect the panner.
|
||||
self._panner.disconnect(0);
|
||||
self._panner = undefined;
|
||||
parent._refreshBuffer(self);
|
||||
}
|
||||
|
||||
// Complete resetting of the sound.
|
||||
return _super.call(this);
|
||||
};
|
||||
})(Sound.prototype.reset);
|
||||
|
||||
/** Helper Methods **/
|
||||
/***************************************************************************/
|
||||
|
||||
/**
|
||||
* Create a new panner node and save it on the sound.
|
||||
* @param {Sound} sound Specific sound to setup panning on.
|
||||
* @param {String} type Type of panner to create: 'stereo' or 'spatial'.
|
||||
*/
|
||||
var setupPanner = function(sound, type) {
|
||||
type = type || 'spatial';
|
||||
|
||||
// Create the new panner node.
|
||||
if (type === 'spatial') {
|
||||
sound._panner = Howler.ctx.createPanner();
|
||||
sound._panner.coneInnerAngle = sound._pannerAttr.coneInnerAngle;
|
||||
sound._panner.coneOuterAngle = sound._pannerAttr.coneOuterAngle;
|
||||
sound._panner.coneOuterGain = sound._pannerAttr.coneOuterGain;
|
||||
sound._panner.distanceModel = sound._pannerAttr.distanceModel;
|
||||
sound._panner.maxDistance = sound._pannerAttr.maxDistance;
|
||||
sound._panner.refDistance = sound._pannerAttr.refDistance;
|
||||
sound._panner.rolloffFactor = sound._pannerAttr.rolloffFactor;
|
||||
sound._panner.panningModel = sound._pannerAttr.panningModel;
|
||||
|
||||
if (typeof sound._panner.positionX !== 'undefined') {
|
||||
sound._panner.positionX.setValueAtTime(sound._pos[0], Howler.ctx.currentTime);
|
||||
sound._panner.positionY.setValueAtTime(sound._pos[1], Howler.ctx.currentTime);
|
||||
sound._panner.positionZ.setValueAtTime(sound._pos[2], Howler.ctx.currentTime);
|
||||
} else {
|
||||
sound._panner.setPosition(sound._pos[0], sound._pos[1], sound._pos[2]);
|
||||
}
|
||||
|
||||
if (typeof sound._panner.orientationX !== 'undefined') {
|
||||
sound._panner.orientationX.setValueAtTime(sound._orientation[0], Howler.ctx.currentTime);
|
||||
sound._panner.orientationY.setValueAtTime(sound._orientation[1], Howler.ctx.currentTime);
|
||||
sound._panner.orientationZ.setValueAtTime(sound._orientation[2], Howler.ctx.currentTime);
|
||||
} else {
|
||||
sound._panner.setOrientation(sound._orientation[0], sound._orientation[1], sound._orientation[2]);
|
||||
}
|
||||
} else {
|
||||
sound._panner = Howler.ctx.createStereoPanner();
|
||||
sound._panner.pan.setValueAtTime(sound._stereo, Howler.ctx.currentTime);
|
||||
}
|
||||
|
||||
sound._panner.connect(sound._node);
|
||||
|
||||
// Update the connections.
|
||||
if (!sound._paused) {
|
||||
sound._parent.pause(sound._id, true).play(sound._id, true);
|
||||
}
|
||||
};
|
||||
})();
|
Reference in New Issue
Block a user