WebAudio / web-audio-api

The Web Audio API v1.0, developed by the W3C Audio WG
https://webaudio.github.io/web-audio-api/
Other
1.04k stars 166 forks source link

PannerNode: Opting-out of distance-based attenuation #2387

Closed pmlt closed 1 year ago

pmlt commented 3 years ago

Describe the feature When using the PannerNode, the volume of the source is attenuated based on distance from the listener. However, some game engines will already have implemented and applied some distance-based attenuation on the input PCM data prior to it being fed to a PannerNode.

The point of this feature is to allow taking advantage of the high-quality HRTFs of PannerNode without having to juggle two distance-based attenuation systems.

Is there a prototype? Basically, adding the "none" value to the accepted values for DistanceModelType:

enum DistanceModelType {
  "none",
  "linear",
  "inverse",
  "exponential"
};

Describe the feature in more detail When "none" is specified as the distanceModel of the node, the node should perform no volume attenuation based on distance whatsoever.

rtoy commented 3 years ago

Thanks for filing this. As discussed in theF2F meeting, this isn't a problem and we'd do this.

jdspugh commented 2 years ago

Checking the docs it appears you can already do this by choosing DistanceModelType "linear" and setting the rolloffFactor to 0. Thus you will be left with a constant gain of 1. If this use case was added to the documentation then no change to the specification would be needed.

linear: A linear distance model calculating the gain induced by the distance according to: 1 - rolloffFactor * (distance - refDistance) / (maxDistance - refDistance)

See https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel

hoch commented 2 years ago

TPAC 2021:

  1. Verify if the proposed fix above (https://github.com/WebAudio/web-audio-api/issues/2387#issuecomment-931891155) is effective.
  2. Otherwise, WG can make a small fix on the PannerNote.
jdspugh commented 2 years ago

This tool is really excellent if you want to visualise the falloff models and how the parameters affect them: https://www.desmos.com/calculator/lzxfqvwoqq

padenot commented 1 year ago

We've verified that 1. in https://github.com/WebAudio/web-audio-api/issues/2387#issuecomment-953056392 is correct, so we don't have to change anything here. The default is 1, but setting it to 0 removes attenuation altogether (keeping the panning).

https://github.com/mdn/content/edit/main/files/en-us/web/api/pannernode/distancemodel/index.md allows editing the MDN documentation (anybody can edit, there are reviewers to help if need be).