PannerNode behaves differently on the web
cybersoulK opened this issue ยท 9 comments
The sound is higher in the web when the position is farther away, in a factor of 3-5 times.
This is the setup code:
Web:
let panner_node = context.create_panner().unwrap();
panner_node.set_distance_model(DistanceModelType::Inverse);
panner_node.set_panning_model(PanningModelType::Hrtf);
panner_node.set_ref_distance(8.0);
panner_node.set_max_distance(80.0);
panner_node.set_rolloff_factor(0.2);
web-audio-api:
let mut options = PannerOptions::default();
options.distance_model = DistanceModelType::Inverse;
options.panning_model = PanningModelType::HRTF;
options.ref_distance = 8.0;
options.max_distance = 80.0;
options.rolloff_factor = 0.2;
let panner_node = PannerNode::new(context, options);
might be related to the following issue when he noticed some differences as well:
#373
Thanks for the report. What value do you mean with farther away?
The expected behaviour is 100% volume for distance <= 8 and then rolling off when moving further away.
For your information, max_distance
is unused in the "inverse" distance model
I might have exaggerated with 5x volume, but i also changed the rolloff_factor for this testing.
I am going to provide audio samples for the following:
panner_node.set_distance_model(DistanceModelType::Inverse);
panner_node.set_panning_model(PanningModelType::Hrtf);
panner_node.set_ref_distance(8.0);
panner_node.set_rolloff_factor(1.0);
options.distance_model = DistanceModelType::Inverse;
options.panning_model = PanningModelType::HRTF;
options.ref_distance = 8.0;
options.rolloff_factor = 1.0;
(gain is 0.8 on both, and added previous to panner, distance to source is around 40.0)
the first section of the video shows the web-audio-api, second part shows web.
Pawn is at exact position, the bullet does not have a PannerNode (it's the only difference), so the sound is the reference point.
A looped sound is running to show the PannerNode differences, the sound notices around 50% higher volume in the web? or i am not sure what the difference is.
right now, it seems that if i divide gain by 2.0 in the web-sys version, before the PannerNode, the sounds match intensity
Thanks for the additional information, this is very helpful!
We will have to investigate if the change is due to the HRTF panning (in which case we will need to tune it to match the browser's behaviour), or also occurs with EqualPower panning (in which case our implementation does not follow the specification). I can do that at the end of the week, but if you are able to, could you run your experiment with PanningModelType::EqualPower
?
My current suspicion is that this is due to the fact we only support mono-to-stereo panning, not stereo-to-stereo. See also #44 .
stereo-to-stereo is by definition louder, cf spec https://webaudio.github.io/web-audio-api/#stereopanner-algorithm
For mono input, the stereo output is calculated as:
outputL = input * gainL;
outputR = input * gainR;
Else for stereo input, the output is calculated as:
if (pan <= 0) {
outputL = inputL + inputR * gainL;
outputR = inputR * gainR;
} else {
outputL = inputL * gainL;
outputR = inputR + inputL * gainR;
}
I will try to see if I can implement this without too much effort.
To validate my theory, you could try to set the PannerNode.channelCount equal to 1 to force mono-to-stereo on the web and then the volume should be equal to our lib.
Wow great job!