From 7d79f9b05f572197f7d90daf727a7808138b3c50 Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Mon, 3 Jan 2022 23:48:14 -0600 Subject: [PATCH 01/10] adds explainer formulas --- extensions/2.0/OMI_audio_emitter/README.md | 59 ++++++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 46ab409..7bfa352 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -236,15 +236,64 @@ Audio emitters of type `positional` may be added to nodes using the following sy Note that multiple global audio emitters are allowed on the scene, but only a single audio emitter may be added to a node. - +### Audio Rolloff Formula +The Audio Rolloff range is (0, +∞). The default is 1. - +The rolloff formula is dependant on the distance model defined. The available distance models are `linear`, `inverse`, and `exponential`. - +- linear formula: `1 - rolloffFactor * (distance - refDistance) / (maxDistance - refDistance)` +- inverse formula: `refDistance / (refDistance + rolloffFactor * (Math.max(distance, refDistance) - refDistance))` +- exponential formula: `pow((Math.max(distance, refDistance) / refDistance, -rolloffFactor)` ### Audio Gain Units - - +The gain unit range is (0,+∞). The default is 1. +- gain formula: `originalVolume * gain` + +### Audio Cone Vizualized +![Audio cone showing how cone parameters impact volume based on relative distance to the source.](https://webaudio.github.io/web-audio-api/images/cone-diagram.svg) + +The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. + +The gain relative to cone properties is determined as follows: +```function coneGain() { + const sourceOrientation = + new Vec3(source.orientationX, source.orientationY, source.orientationZ); + if (sourceOrientation.magnitude == 0 || + ((source.coneInnerAngle == 360) && (source.coneOuterAngle == 360))) + return 1; // no cone specified - unity gain + // Normalized source-listener vector + const sourcePosition = new Vec3(panner.positionX.value, panner.positionY.value, + panner.positionZ.value); + const listenerPosition = + new Vec3(listener.positionX.value, listener.positionY.value, + listener.positionZ.value); + const sourceToListener = sourcePosition.diff(listenerPosition).normalize(); + const normalizedSourceOrientation = sourceOrientation.normalize(); + // Angle between the source orientation vector and the source-listener vector + const angle = 180 * + Math.acos(sourceToListener.dot(normalizedSourceOrientation)) / + Math.PI; + const absAngle = Math.abs(angle); + // Divide by 2 here since API is entire angle (not half-angle) + const absInnerAngle = Math.abs(source.coneInnerAngle) / 2; + const absOuterAngle = Math.abs(source.coneOuterAngle) / 2; + let gain = 1; + if (absAngle <= absInnerAngle) { + // No attenuation + gain = 1; + } else if (absAngle >= absOuterAngle) { + // Max attenuation + gain = source.coneOuterGain; + } else { + // Between inner and outer cones + // inner -> outer, x goes from 0 -> 1 + const x = (absAngle - absInnerAngle) / (absOuterAngle - absInnerAngle); + gain = (1 - x) + source.coneOuterGain * x; + } + return gain; +} +``` +[Cone Gain Algorithm Source](https://webaudio.github.io/web-audio-api/#Spatialization-sound-cones) ### Units for Rotations From 4c0ebc60461e676d39fe40264013d123cde6a95d Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Mon, 3 Jan 2022 23:53:07 -0600 Subject: [PATCH 02/10] reformats code block --- extensions/2.0/OMI_audio_emitter/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 7bfa352..21c039d 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -255,7 +255,9 @@ The gain unit range is (0,+∞). The default is 1. The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. The gain relative to cone properties is determined as follows: -```function coneGain() { + +``` +function coneGain() { const sourceOrientation = new Vec3(source.orientationX, source.orientationY, source.orientationZ); if (sourceOrientation.magnitude == 0 || From aaafdf3fe30fc93e224ea9225510e3021431d290 Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Sun, 9 Jan 2022 22:39:06 -0600 Subject: [PATCH 03/10] adds audio cone gain algorithm example graphic and explainer docs --- extensions/2.0/OMI_audio_emitter/README.md | 45 +------- .../figures/cone-diagram.svg | 100 ++++++++++++++++++ 2 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 21c039d..fb35ba1 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -250,52 +250,11 @@ The gain unit range is (0,+∞). The default is 1. - gain formula: `originalVolume * gain` ### Audio Cone Vizualized -![Audio cone showing how cone parameters impact volume based on relative distance to the source.](https://webaudio.github.io/web-audio-api/images/cone-diagram.svg) +![Audio cone showing how cone parameters impact volume based on relative distance to the source.](../figures/cone-diagram.svg) The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. -The gain relative to cone properties is determined as follows: - -``` -function coneGain() { - const sourceOrientation = - new Vec3(source.orientationX, source.orientationY, source.orientationZ); - if (sourceOrientation.magnitude == 0 || - ((source.coneInnerAngle == 360) && (source.coneOuterAngle == 360))) - return 1; // no cone specified - unity gain - // Normalized source-listener vector - const sourcePosition = new Vec3(panner.positionX.value, panner.positionY.value, - panner.positionZ.value); - const listenerPosition = - new Vec3(listener.positionX.value, listener.positionY.value, - listener.positionZ.value); - const sourceToListener = sourcePosition.diff(listenerPosition).normalize(); - const normalizedSourceOrientation = sourceOrientation.normalize(); - // Angle between the source orientation vector and the source-listener vector - const angle = 180 * - Math.acos(sourceToListener.dot(normalizedSourceOrientation)) / - Math.PI; - const absAngle = Math.abs(angle); - // Divide by 2 here since API is entire angle (not half-angle) - const absInnerAngle = Math.abs(source.coneInnerAngle) / 2; - const absOuterAngle = Math.abs(source.coneOuterAngle) / 2; - let gain = 1; - if (absAngle <= absInnerAngle) { - // No attenuation - gain = 1; - } else if (absAngle >= absOuterAngle) { - // Max attenuation - gain = source.coneOuterGain; - } else { - // Between inner and outer cones - // inner -> outer, x goes from 0 -> 1 - const x = (absAngle - absInnerAngle) / (absOuterAngle - absInnerAngle); - gain = (1 - x) + source.coneOuterGain * x; - } - return gain; -} -``` -[Cone Gain Algorithm Source](https://webaudio.github.io/web-audio-api/#Spatialization-sound-cones) +The gain relative to cone properties is determined in a similar way as described in the web audio api with the difference that this audio emitter extension uses radians in place of degrees. [Cone Gain Algorithm Example](https://webaudio.github.io/web-audio-api/#Spatialization-sound-cones) ### Units for Rotations diff --git a/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg b/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg new file mode 100644 index 0000000..a494196 --- /dev/null +++ b/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Listener + + + + + + + + + + + + + + + + + + + + + orientation + + + + + + + forward + + + + + + + coneInnerAngle + + + + + + + coneOuterAngle + + + + + + + gain = 1 + + + + + + + gain = coneOuterGain + + + + + + + Variable gain + + + + + + From 9ca0547aea59abaae82daba51285a55e3d02d7fa Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Sun, 9 Jan 2022 22:50:07 -0600 Subject: [PATCH 04/10] fix relative path for audio cone figure --- extensions/2.0/OMI_audio_emitter/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index fb35ba1..94d5394 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -250,7 +250,8 @@ The gain unit range is (0,+∞). The default is 1. - gain formula: `originalVolume * gain` ### Audio Cone Vizualized -![Audio cone showing how cone parameters impact volume based on relative distance to the source.](../figures/cone-diagram.svg) +Audio cone showing how cone parameters impact volume based on relative distance to the source. + The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. From 0767da73b70a088983699beb2ab8d0e9e3eb99f3 Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Sun, 9 Jan 2022 22:53:52 -0600 Subject: [PATCH 05/10] adds white background to audio cone figure --- .../OMI_audio_emitter/figures/cone-diagram.svg | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg b/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg index a494196..5b74693 100644 --- a/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg +++ b/extensions/2.0/OMI_audio_emitter/figures/cone-diagram.svg @@ -2,6 +2,7 @@ + @@ -56,7 +57,12 @@ - forward + + forwar + + d + + @@ -91,7 +97,12 @@ - Variable gain + + V + + ariable gain + + From 3b30b9b827635bf80480a375af701eeb69d6d56c Mon Sep 17 00:00:00 2001 From: Anthony Burchell Date: Sun, 9 Jan 2022 22:58:18 -0600 Subject: [PATCH 06/10] adds Third Room to list of implementations --- extensions/2.0/OMI_audio_emitter/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 94d5394..ef57bb7 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -267,8 +267,7 @@ Radians are used for rotations matching glTF2. ## Known Implementations -* TODO: List of known implementations, with links to each if available. -* +* Third Room - https://github.com/thirdroom/thirdroom ## Resources From 5fada8be1fa624a01a40acac5c9eba62632cfc86 Mon Sep 17 00:00:00 2001 From: antpb Date: Thu, 13 Jan 2022 16:41:35 -0600 Subject: [PATCH 07/10] add anthony to contributor list --- extensions/2.0/OMI_audio_emitter/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index ef57bb7..45dc3af 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -3,6 +3,7 @@ ## Contributors * Robert Long, Element Inc. +* Anthony Burchell, Individual Contributor ## Status From df247208ccefa5675e69e4a2f497f3c5567e1896 Mon Sep 17 00:00:00 2001 From: antpb Date: Fri, 21 Jan 2022 00:20:14 -0600 Subject: [PATCH 08/10] adds figure source of audiio cone graphic --- extensions/2.0/OMI_audio_emitter/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 45dc3af..527d788 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -251,8 +251,10 @@ The gain unit range is (0,+∞). The default is 1. - gain formula: `originalVolume * gain` ### Audio Cone Vizualized +
Audio cone showing how cone parameters impact volume based on relative distance to the source. - +
Figure 1 is a modified graphic based on the W3C Web Audio API Audio cone Figure
+ The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. From 8d995c1d35837a013b94e8cd9a472f1c0c666a37 Mon Sep 17 00:00:00 2001 From: antpb Date: Fri, 21 Jan 2022 00:21:58 -0600 Subject: [PATCH 09/10] open cone graphic external link in new tab --- extensions/2.0/OMI_audio_emitter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 527d788..0c4d589 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -253,7 +253,7 @@ The gain unit range is (0,+∞). The default is 1. ### Audio Cone Vizualized
Audio cone showing how cone parameters impact volume based on relative distance to the source. -
Figure 1 is a modified graphic based on the W3C Web Audio API Audio cone Figure
+
Figure 1 is a modified graphic based on the W3C Web Audio API Audio cone Figure
The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area. From 88fbc600cd9815b17dab4890058d50b799f33c49 Mon Sep 17 00:00:00 2001 From: antpb Date: Fri, 21 Jan 2022 00:30:44 -0600 Subject: [PATCH 10/10] adjusts figure 1 caption markup --- extensions/2.0/OMI_audio_emitter/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/extensions/2.0/OMI_audio_emitter/README.md b/extensions/2.0/OMI_audio_emitter/README.md index 0c4d589..cf84b71 100644 --- a/extensions/2.0/OMI_audio_emitter/README.md +++ b/extensions/2.0/OMI_audio_emitter/README.md @@ -251,10 +251,9 @@ The gain unit range is (0,+∞). The default is 1. - gain formula: `originalVolume * gain` ### Audio Cone Vizualized -
Audio cone showing how cone parameters impact volume based on relative distance to the source. -
Figure 1 is a modified graphic based on the W3C Web Audio API Audio cone Figure
-
+ +Figure 1. A modified graphic based on the W3C Web Audio API Audio cone Figure The cone properties relate to the `PannerNode` interface and determine the amount of volume relative to a listeners position within the defined cone area.