Skip to content

Commit

Permalink
Merge pull request #25 from AltspaceVR/feature/native-sound-rolloff
Browse files Browse the repository at this point in the history
Feature/native sound rolloff
  • Loading branch information
brianpeiris committed Dec 22, 2016
2 parents 9ee3314 + 6e8eeb1 commit 26b6630
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 121 deletions.
30 changes: 29 additions & 1 deletion examples/native-sound/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</script>
</head>
<body>
<a-scene debug altspace sync-system="author: altspacevr; app: sound-sync-test">
<a-scene debug altspace="fullspace: true" sync-system="author: altspacevr; app: sound-sync-test">
<a-entity id="loop"
geometry="primitive: box" material="color: green" position="-3 1 -2"
n-sound="res: ui/error; volume: 0.5; loop: true; on: click"
Expand Down Expand Up @@ -53,6 +53,34 @@
<a-entity n-text="fontSize: 2; text: spatialBlend & pitch" position="0 1 0" rotation="0 -90 0"></a-entity>
</a-entity>

<a-entity
geometry="primitive: box" material="color: lightblue" position="-3 1 -4"
n-sound="src: big-buck-bunny-intro.wav; on: click; rolloff: linear; minDistance: 2; maxDistance: 5"
altspace-cursor-collider="enabled: true">
<a-entity n-text="fontSize: 2; text: linear" position="0 1 0"></a-entity>
</a-entity>

<a-entity
geometry="primitive: box" material="color: lightblue" position="0 1 -4"
n-sound="src: big-buck-bunny-intro.wav; autoplay: true; on: click; rolloff: logarithmic; minDistance: 2; maxDistance: 5"
altspace-cursor-collider="enabled: true">
<a-entity n-text="fontSize: 2; text: log" position="0 1 0"></a-entity>
</a-entity>

<a-entity
geometry="primitive: box" material="color: lightblue" position="0 1 -40"
n-sound="src: big-buck-bunny-intro.wav; on: click; rolloff: logarithmic; minDistance: 2; maxDistance: 5"
altspace-cursor-collider="enabled: true">
<a-entity n-text="fontSize: 2; text: log" position="0 1 0"></a-entity>
</a-entity>

<a-entity
geometry="primitive: box" material="color: lightblue" position="3 1 -4"
n-sound="src: big-buck-bunny-intro.wav; on: click; rolloff: cosine; minDistance: 2; maxDistance: 5"
altspace-cursor-collider="enabled: true">
<a-entity n-text="fontSize: 2; text: cosine" position="0 1 0"></a-entity>
</a-entity>

<a-entity id="wav"
geometry="primitive: box" material="color: lightblue" position="-3 1 0"
sync="own-on: mousedown" sync-n-sound
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "budo",
"dist": "gulp dist",
"doc": "jsdoc -c .jsdoc.json src"
"doc": "npm run dist && jsdoc -c .jsdoc.json src"
},
"repository": {
"type": "git",
Expand Down
12 changes: 9 additions & 3 deletions src/native-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,15 @@
* octave down, and 2 is one octave up.
* @prop {number} minDistance=1 - Inside this distance in meters,
* the sound volume is at full volume.
* @prop {number} maxDistance=12 - Beyond this distance in meters, the sound
* will rapidly fall off to silence.
* @prop {number} maxDistance=12 - If rolloff is 'logarithmic', the sound will stop attenuating at this distance.
* If rolloff is 'linear' or 'cosine', the sound will be silent at this distance.
* @prop {string} rolloff='logarithmic' - Set this to 'linear' or 'cosine' if you want to cut sounds off at a
* maxDistance.
*/
/**
* Fired when a sound has loaded and is ready to be played
* @event native.n-sound#n-sound-loaded
*/
AFRAME.registerComponent('n-sound', {
init: function () {
var src = this.data.src;
Expand Down Expand Up @@ -364,6 +369,7 @@
pitch: { type: 'float', default: 1 },
minDistance: { type: 'float', default: 1 },
maxDistance: { type: 'float', default: 12 },
rolloff: { type: 'string', default: 'logarithmic' },
}
});

Expand Down
232 changes: 116 additions & 116 deletions src/native-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,64 @@
* @enum architecture
* @memberof resources
*
* @prop ceiling-2w-2l
* @prop ceiling-4w-4l
* @prop ceiling-4w-4l
* @prop ceiling-skylight-4w-4l
* @prop ceiling-skylight-corner-2w-2l
* @prop ceiling-skylight-edge-2w
* @prop ceiling-skylight-edge-4w
* @prop ceiling-skylight-filler-4w-4l-2
* @prop ceiling-skylight-filler-4w-4l
* @prop ceiling-slice-concave-2r
* @prop ceiling-slice-concave-4r
* @prop ceiling-slice-convex-2r
* @prop ceiling-slice-convex-4r
* @prop door-4w-4h
* @prop floor-2w-2l
* @prop floor-2w-4l
* @prop floor-4w-2l
* @prop floor-4w-4l
* @prop floor-slice-concave-2r
* @prop floor-slice-concave-4r
* @prop floor-slice-convex-2r
* @prop floor-slice-convex-4r
* @prop railing-2l
* @prop railing-4l
* @prop railing-curve-concave-2r
* @prop wall-2w-4h
* @prop wall-4w-4h
* @prop wall-base-2w
* @prop wall-base-4w
* @prop wall-base-curve-concave-2r
* @prop wall-base-curve-concave-4r
* @prop wall-base-curve-convex-2r
* @prop wall-base-curve-convex-4r
* @prop wall-bulkhead-2w
* @prop wall-bulkhead-4w
* @prop wall-bulkhead-curve-concave-2r
* @prop wall-bulkhead-curve-concave-4r
* @prop wall-bulkhead-curve-convex-2r
* @prop wall-bulkhead-curve-convex-4r
* @prop wall-curve-concave-2r-4h
* @prop wall-curve-concave-4r-4h
* @prop wall-curve-convex-2r-4h
* @prop wall-curve-convex-4r-4h
* @prop wall-curve-window-concave-4r-4h
* @prop wall-curve-window-concave-filler-4r-4h
* @prop wall-curve-window-gap-concave-4r-4h
* @prop wall-curve-window-gap-end-l-concave-4r-4h
* @prop wall-curve-window-gap-end-r-concave-4r-4h
* @prop wall-filler-corner-inner-4h
* @prop wall-filler-corner-outer-4h
* @prop wall-window-4w-4h
* @prop wall-window-filler-2
* @prop wall-window-gap-2w-4h
* @prop wall-window-gap-4w-4h
* @prop wall-window-gap-end-l-2w-4h
* @prop wall-window-gap-end-l-4w-4h
* @prop wall-window-gap-end-r-2w-4h
* @prop wall-window-gap-end-r-4w-4h
* @prop architecture/ceiling-2w-2l
* @prop architecture/ceiling-4w-4l
* @prop architecture/ceiling-4w-4l
* @prop architecture/ceiling-skylight-4w-4l
* @prop architecture/ceiling-skylight-corner-2w-2l
* @prop architecture/ceiling-skylight-edge-2w
* @prop architecture/ceiling-skylight-edge-4w
* @prop architecture/ceiling-skylight-filler-4w-4l-2
* @prop architecture/ceiling-skylight-filler-4w-4l
* @prop architecture/ceiling-slice-concave-2r
* @prop architecture/ceiling-slice-concave-4r
* @prop architecture/ceiling-slice-convex-2r
* @prop architecture/ceiling-slice-convex-4r
* @prop architecture/door-4w-4h
* @prop architecture/floor-2w-2l
* @prop architecture/floor-2w-4l
* @prop architecture/floor-4w-2l
* @prop architecture/floor-4w-4l
* @prop architecture/floor-slice-concave-2r
* @prop architecture/floor-slice-concave-4r
* @prop architecture/floor-slice-convex-2r
* @prop architecture/floor-slice-convex-4r
* @prop architecture/railing-2l
* @prop architecture/railing-4l
* @prop architecture/railing-curve-concave-2r
* @prop architecture/wall-2w-4h
* @prop architecture/wall-4w-4h
* @prop architecture/wall-base-2w
* @prop architecture/wall-base-4w
* @prop architecture/wall-base-curve-concave-2r
* @prop architecture/wall-base-curve-concave-4r
* @prop architecture/wall-base-curve-convex-2r
* @prop architecture/wall-base-curve-convex-4r
* @prop architecture/wall-bulkhead-2w
* @prop architecture/wall-bulkhead-4w
* @prop architecture/wall-bulkhead-curve-concave-2r
* @prop architecture/wall-bulkhead-curve-concave-4r
* @prop architecture/wall-bulkhead-curve-convex-2r
* @prop architecture/wall-bulkhead-curve-convex-4r
* @prop architecture/wall-curve-concave-2r-4h
* @prop architecture/wall-curve-concave-4r-4h
* @prop architecture/wall-curve-convex-2r-4h
* @prop architecture/wall-curve-convex-4r-4h
* @prop architecture/wall-curve-window-concave-4r-4h
* @prop architecture/wall-curve-window-concave-filler-4r-4h
* @prop architecture/wall-curve-window-gap-concave-4r-4h
* @prop architecture/wall-curve-window-gap-end-l-concave-4r-4h
* @prop architecture/wall-curve-window-gap-end-r-concave-4r-4h
* @prop architecture/wall-filler-corner-inner-4h
* @prop architecture/wall-filler-corner-outer-4h
* @prop architecture/wall-window-4w-4h
* @prop architecture/wall-window-filler-2
* @prop architecture/wall-window-gap-2w-4h
* @prop architecture/wall-window-gap-4w-4h
* @prop architecture/wall-window-gap-end-l-2w-4h
* @prop architecture/wall-window-gap-end-l-4w-4h
* @prop architecture/wall-window-gap-end-r-2w-4h
* @prop architecture/wall-window-gap-end-r-4w-4h
*/

/**
Expand All @@ -81,15 +81,15 @@
* @enum effects
* @memberof resources
*
* @prop explosion - A particle system with a central flash, then debris flying outward.
* @prop effects/explosion - A particle system with a central flash, then debris flying outward.
* This is a non-looping effect.
* @prop fire - An animated fire particle, suitable for a torch.
* @prop fire-trail - Fire that trails the entity through space as it moves. Only is visible while an object is in motion
* @prop fireworks - A compound particle system that shoots up from the entity,
* @prop effects/fire - An animated fire particle, suitable for a torch.
* @prop effects/fire-trail - Fire that trails the entity through space as it moves. Only is visible while an object is in motion
* @prop effects/fireworks - A compound particle system that shoots up from the entity,
* explodes into colored sparks, then transitions to gold streamers.
* @prop smoke - Billowing smoke particle system.
* @prop sparkler - Emits sparks in all directions
* @prop steam - Small white steam rising upwards
* @prop effects/smoke - Billowing smoke particle system.
* @prop effects/sparkler - Emits sparks in all directions
* @prop effects/steam - Small white steam rising upwards
*/

/**
Expand All @@ -98,14 +98,14 @@
* @enum interactables
* @memberof resources
*
* @prop basketball
* @prop bowlingball
* @prop bowling-pin
* @prop box
* @prop coin
* @prop gem
* @prop ring
* @prop soccerball
* @prop interactables/basketball
* @prop interactables/bowlingball
* @prop interactables/bowling-pin
* @prop interactables/box
* @prop interactables/coin
* @prop interactables/gem
* @prop interactables/ring
* @prop interactables/soccerball
*/

/**
Expand All @@ -114,13 +114,13 @@
* @enum objects
* @memberof resources
*
* @prop basketball-hoop
* @prop coin
* @prop cup
* @prop gem
* @prop hoop
* @prop ring
* @prop target-archery
* @prop objects/basketball-hoop
* @prop objects/coin
* @prop objects/cup
* @prop objects/gem
* @prop objects/hoop
* @prop objects/ring
* @prop objects/target-archery
*/

/**
Expand All @@ -129,22 +129,22 @@
* @enum pipes
* @memberof resources
*
* @prop pipe-full-cap-1d
* @prop pipe-full-cross-1d
* @prop pipe-full-elbow-1d
* @prop pipe-full-fork-1d
* @prop pipe-full-straight-1d-1l
* @prop pipe-full-straight-1d-2l
* @prop pipe-full-straight-1d-4l
* @prop pipe-full-tee-1d
* @prop pipe-half-cap-1d
* @prop pipe-half-cross-1d
* @prop pipe-half-elbow-1d
* @prop pipe-half-fork-1d
* @prop pipe-half-straight-1d-1l
* @prop pipe-half-straight-1d-2l
* @prop pipe-half-straight-1d-4l
* @prop pipe-half-tee-1d
* @prop pipes/pipe-full-cap-1d
* @prop pipes/pipe-full-cross-1d
* @prop pipes/pipe-full-elbow-1d
* @prop pipes/pipe-full-fork-1d
* @prop pipes/pipe-full-straight-1d-1l
* @prop pipes/pipe-full-straight-1d-2l
* @prop pipes/pipe-full-straight-1d-4l
* @prop pipes/pipe-full-tee-1d
* @prop pipes/pipe-half-cap-1d
* @prop pipes/pipe-half-cross-1d
* @prop pipes/pipe-half-elbow-1d
* @prop pipes/pipe-half-fork-1d
* @prop pipes/pipe-half-straight-1d-1l
* @prop pipes/pipe-half-straight-1d-2l
* @prop pipes/pipe-half-straight-1d-4l
* @prop pipes/pipe-half-tee-1d
*/

/**
Expand All @@ -153,15 +153,15 @@
* @enum sounds-ui
* @memberof resources
*
* @prop select
* @prop toggle
* @prop notify
* @prop error
* @prop complete
* @prop succeed
* @prop over
* @prop join
* @prop click
* @prop ui/select
* @prop ui/toggle
* @prop ui/notify
* @prop ui/error
* @prop ui/complete
* @prop ui/succeed
* @prop ui/over
* @prop ui/join
* @prop ui/click
*/

/**
Expand All @@ -170,12 +170,12 @@
* @enum sounds-foley
* @memberof resources
*
* @prop metal-scrape
* @prop metal-clack
* @prop metal-rattle
* @prop coin-jingle
* @prop paper-shuffle
* @prop explode
* @prop foley/metal-scrape
* @prop foley/metal-clack
* @prop foley/metal-rattle
* @prop foley/coin-jingle
* @prop foley/paper-shuffle
* @prop foley/explode
*/

/**
Expand All @@ -184,10 +184,10 @@
* @enum sounds-effects
* @memberof resources
*
* @prop fanfare-succeed - The "success!" sound from Holograms Against Humanity.
* @prop fanfare-start - The "Game has started!" sound from HaH.
* @prop fanfare-fail
* @prop timer-10s - a 10 second timer that triggers a bell at exactly 10 seconds.
* @prop effects/fanfare-succeed - The "success!" sound from Holograms Against Humanity.
* @prop effects/fanfare-start - The "Game has started!" sound from HaH.
* @prop effects/fanfare-fail
* @prop effects/timer-10s - a 10 second timer that triggers a bell at exactly 10 seconds.
* The bell lasts for 2 seconds. This allows for timer length changes.
* @prop gain-coin
* @prop effects/gain-coin
*/

0 comments on commit 26b6630

Please sign in to comment.