LabSound / LabSound

:microscope: :speaker: graph-based audio engine

Home Page:http://labsound.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panner distance gain not working?

dug9 opened this issue · comments

commented

Besides left-to-right, cone and doppler effects, Panner has a distance gain set by the difference between listener and panner positions, and with fade effects controlled by a few parameters, here's a modification to the ex_hrtf_spatialization example:
...
panner->setDistanceModel(lab::PannerNode::LINEAR_DISTANCE);
panner->setRolloffFactor(10.0f);
panner->setRefDistance(.1f);
panner->setMaxDistance(20.0f);
... and to elliminate left-right motion effects and focus on distance gain
panner->setPosition(.1f, x, 0.1f);
x but I don't hear a volume / gain change
x and
std::cout << " " << panner->param("distanceGain").get()->value();
x shows all 1 on every slice

goal, to get forward-back motion change of volume like this web audio boom-box example:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Web_audio_spatialization_basics

Any hypotheses?

more..
I work on freewrl.sf.net which renders www.web3d.org 3D standard scene files, and they updated their standard recently to include web audio equivalent nodes. freewrl is flat C, and with a .cpp module I can interface to and have a bit of the labsound working, but not the distance gain.
Rather than separate threads with Wait(), I visit the labsound nodes on each 3D scene rendering frame, and reset the parameters such as location.

Thanks for the report! At this line ~

float totalGain = distanceConeGain(r);
~ distanceConeGain is called and should be doing the computation you expect when it gets down to calling the cone effect. I'll have a look at the boom box example.

commented

Thanks for the hint. One thing I've found so far today is the DistanceEffect constructor initializes to Inverse(1) which is OK / normal /expected for OpenAL, and I can verify. Panner seems to initialize to zero so ignors a change to linear(0), but gets a change to exponential(2), or that's what I infer from a few cout/printf, so when getting started if I do this
panner->setDistanceModel(lab::PannerNode::LINEAR_DISTANCE);
std::cout << " panner Distance model just after setDistanceModel = " << panner->distanceModel() << std::endl;
I get the correct number for all 3 cases. But DistanceEffect is still on 1 if I set LINEAR_DISTANCE here.

commented

In PannerNode.cpp it gets in here when setting to EXPONENTAL or INVERSE but not with LINEAR
m_distanceModel->setValueChanged(
this {
Hypothesis: PannerNode constructor needs to also initialize this value to 1 so it can detect a change to 0. If so how initialize. Its a fancy field and doesn't take enum, I don't know how to do it.

commented

PS if I do a temp fix (initialize DistanceEffect to Linear in its constructor) that doesn't fix the distanceGain problem.

commented

BINGO. rolloffFactor was zero in DistanceEffect and I found it was being mis-initialized in PannerNode.cpp L133
m_rolloffFactor->setValueChanged(
this {
m_distanceEffect->setRolloffFactor(m_rolloffFactor->valueFloat()); //correct, works I get distance gain
//m_distanceEffect->setRolloffFactor(m_maxDistance->valueFloat()); // WRONG, was giving me rolloff 0 and no distance gain change, gain stuck on 1

    });

Oh wow! Great find, thank you!

Hi @dug9 ! Thanks again for the report. I pushed a fix to the bug you reported.

d8e845a

commented

Thanks very much for the change which is working -- and thanks for LabSound library which is doing the job.
For the other issue I mentioned above -the distance model not changing to LINEAR because it thinks its on linear when its on INVERSE- instead of LabSound
Distance.h L.52
ModelType m_model = ModelLinear; //ModelInverse;
as a fix, now in my application code I double-change during first initialization:
pannerNode->setDistanceModel(lab::PannerNode::EXPONENTIAL_DISTANCE);
pannerNode->setDistanceModel(lab::PannerNode::LINEAR_DISTANCE);
and will give that a try.
I need to try all the LabSound nodes in detail to implement the web3d sound node specs
https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-DIS/Part01/components/sound.html
in freeWRL so I'll let you know if I find other issues.