XMLSound bugfixes

- using expressions for pitch and volume didn't work
- multiple volume elements not computed properly

Discussion here: https://web.archive.org/web/20200730232940/http://fguk.me/forum/development-hangar/8360-supersonic-audio?start=40#46287

          <volume>
                <property>/a/v1</property>
                <factor>0.1</factor>
            </volume>
            <volume>
                <property>/a/v2</property>
                <offset>1</offset>
                <factor>-3</factor>
            </volume>
            <volume>
                <property>/a/v3</property>
                <offset>1</offset>
                <factor>-1</factor>
            </volume>

evaluates as follows:

update(): Have 3 volume entries
 --> 0:prop /a[0]/v1[0] => 0.110000 factor = 0.100000 v=0.011000 offset 0.000000, now 0.000000, v=0.011000 vol=0.011000 ==> 0.011000
 --> 1:prop /a[0]/v2[0] => 0.120000 factor = 3.000000 v=0.360000 -ve offset 1.000000 1.360000 = 0.014960  ==> 0.014960
 --> 2:prop /a[0]/v3[0] => 0.130000 factor = 1.000000 v=0.130000 -ve offset 1.000000 1.130000 = 0.016905  ==> 0.016905
This commit is contained in:
Richard Harrison 2020-07-31 01:31:27 +02:00 committed by Automatic Release Builder
parent 5b3274e688
commit 24b58cbe21

View File

@ -414,9 +414,11 @@ SGXmlSound::update (double dt)
double v = 1.0;
if (_volume[i].expr) {
v = _volume[i].expr->getValue(nullptr);
expr = true;
continue;
double expression_value = _volume[i].expr->getValue(nullptr);
if (expression_value >= 0)
volume *= expression_value;
expr = true;
continue;
}
if (_volume[i].prop) {
@ -437,19 +439,23 @@ SGXmlSound::update (double dt)
if (_volume[i].max && (v > _volume[i].max))
v = _volume[i].max;
else if (v < _volume[i].min)
v = _volume[i].min;
if (_volume[i].subtract) // Hack!
volume = _volume[i].offset - v;
if (_volume[i].subtract){ // Hack!
v = v + _volume[i].offset;
if (v >= 0)
volume = volume * v;
}
else {
volume_offset += _volume[i].offset;
volume *= v;
if (v >= 0) {
volume_offset += _volume[i].offset;
volume = volume * v;
}
}
}
//
// Update the pitch
//
@ -462,9 +468,9 @@ SGXmlSound::update (double dt)
double p = 1.0;
if (_pitch[i].expr) {
p = _pitch[i].expr->getValue(nullptr);
expr = true;
continue;
pitch *= _pitch[i].expr->getValue(nullptr);
expr = true;
continue;
}
if (_pitch[i].prop) {