|
Post by Michael on Oct 1, 2021 8:45:00 GMT
Hi, I tried using your approach to fading in a sound group by code, which you proposed here - darktonic.freeforums.net/thread/228/fade-sound-code. And seemingly it worked just fine, however, what I found was that when the MA Master Mixer Volume was changed by even a bit (we treat that as sound effects volume, user has the option to change those settings via our UI in game, in runtime), the volume of the sounggroupvariation would be multiplied by whatever the value sound was played with before. So if I played the variation MasterAudio.PlaySound("Scream", 0f) it would, no matter what value Master Mixer Volume (MMV) was changed to, always get that soundgroupvariation's volume to 0. End if it was MasterAudio.PlaySound("Scream", 0.1f), it would multiplay MMV by 0.1f, and apply that to that soundgroupvariation. Hence if MMV was set to 0.5, the soundgoupvalume would end up being 0.05. I tried doing: var tempSoundGroup = MasterAudio.PlaySound("Scream", 1f); tempSoundGroup.AdjustVolume(0f); but it gives the same result. Also I tried: var tempSoundGroup = MasterAudio.PlaySound("Scream", 1f); tempSoundGroup.AdjustVolume(0f); tempSoundGroup.original_volume = 1f; and again with the same result. (By the way original_volume seems to be depricated/redundant, not that is releveant here but maybe you would like to know ). Sooo... Am I doing something wrong? Or could you direct me pls, to a place in MA code where it applies MMV value to currently played sound groups, so I can maybe work on that code a little, adjusting it to my needs? Or perhaps it's an MA bug? Let me know please, it actually might grow quite quickly to a big bug in our game . Cheers!
|
|
|
Post by DarkTonic Dev on Oct 1, 2021 18:51:00 GMT
Master Mixer Volume is always supposed to be used in all calculations of volume, whether it's after a fade or whatever. Both scenarios you described are functioning as intended.
1) Correct that if you play the sound at zero volume, regardless of what value the Master Mixer Volume is set to, the result will be zero (0 x 1 x 1 x anything = 0). That first zero which is the Variation volume will never change. 2) The following code would set the Scream sound at a volume in the Audio Source of 0.05f, if Master Mixer Volume is set to 0.5 and the Group Volume is 1 and the Bus Volume is 1 (0.1 x 1 x 1 x 0.5) = 0.05:
var tempSoundGroup = MasterAudio.PlaySound("Scream", 0.1f);
Whether MMV is adjusted to 0.5 before or after doesn't matter, the result will be 0.05 volume. I'm curious why you'd think it's a bug.
As to adjusting the volume to 0, that will always be a total volume of zero based on the calculations above, as that changes the Variation volume to zero.
original_volume isn't deprecated, it's just used by any of our code. It's a reference that your code can use if you want to know the original volume so you can fade back to it at some point.
-Brian
|
|
|
Post by Michael on Oct 4, 2021 7:40:04 GMT
Hm, it still seems strange to me as for an intended behaviour. Maybe I wasn't clear enough the last time about my problem, let me try again So, I want to fade a volume, from 0 to 1. To do so, I play "Scream" sound at volume 0 with method var tempSoundGroup = MasterAudio.PlaySound("Scream", 0f);. Then I fade it to 1, using: tempSoundGroup.FadeToVolume(1f, someDuration). After someDuration audio plays at volume 1. Now, when it plays at 1f volume, I change the MMV by whatever value, lets say by 0.5, but it happens on any change. Now, my variation doesn't play at volume 0.5f, which to me would seem as expected result, but at volume 0f. So frankly, while calculating what volume the variation should play after the MMV value change, the logic calculating that didn't used value my sound was playing at the time It used a value which I assigned when triggering the sound. So even though just a sec ago my sound was playing at volume 1f, when I changed MMV to 0.5f, my sounds plays at volume 0f, and not at 0.5f. Is this intended? And if it is, could you pls give me a reference to where I should look in MA code to change things to get it my way?. I want MA to when calculating volume after MMV change, include the volume variation plays now, not when it was triggered some long time ago
|
|
|
Post by DarkTonic Dev on Oct 4, 2021 19:32:06 GMT
Oh ok, it sounds like it's only after a fade that the calculations don't work right. I will take a look later on and report back. Thanks.
|
|
|
Post by DarkTonic Dev on Oct 4, 2021 21:50:18 GMT
Ok I found the problem and fixed it. Please replace the code in SoundGroupVariationUpdate.cs starting at line 686 with the following:
case SoundGroupVariation.FadeMode.GradualFade: if (!VarAudio.isPlaying) { break; }
_fadeToTargetFrameNumber++; if (_fadeToTargetFrameNumber >= _fadeToTargetTotalFrames) { var grpInfo = MasterAudio.GetAllVariationsOfGroup(ParentGroup.GameObjectName); for (var i = 0; i < grpInfo.Count; i++) { var aVar = grpInfo[i]; if (aVar.Variation != this.GrpVariation) { continue; }
aVar.LastPercentageVolume = _fadeToTargetVolume; break; }
VarAudio.volume = _fadeToTargetVolume; StopFading(); if (_fadeToTargetCompletionCallback != null) { _fadeToTargetCompletionCallback(); } } else { VarAudio.volume = (_fadeToTargetFrameNumber * _fadeToTargetFrameVolChange) + _fadeToTargetOrigVol; } break;
The part we didn't have was to update LastPercentageVolume with the new faded volume.
|
|
|
Post by Michael on Oct 5, 2021 12:56:09 GMT
Ok I found the problem and fixed it. Please replace the code in SoundGroupVariationUpdate.cs starting at line 686 with the following: case SoundGroupVariation.FadeMode.GradualFade: if (!VarAudio.isPlaying) { break; }
_fadeToTargetFrameNumber++; if (_fadeToTargetFrameNumber >= _fadeToTargetTotalFrames) { var grpInfo = MasterAudio.GetAllVariationsOfGroup(ParentGroup.GameObjectName); for (var i = 0; i < grpInfo.Count; i++) { var aVar = grpInfo[i]; if (aVar.Variation != this.GrpVariation) { continue; }
aVar.LastPercentageVolume = _fadeToTargetVolume; break; }
VarAudio.volume = _fadeToTargetVolume; StopFading(); if (_fadeToTargetCompletionCallback != null) { _fadeToTargetCompletionCallback(); } } else { VarAudio.volume = (_fadeToTargetFrameNumber * _fadeToTargetFrameVolChange) + _fadeToTargetOrigVol; } break;
The part we didn't have was to update LastPercentageVolume with the new faded volume. Oh, great . Thanks so much. I wouldn't have time to give it a proper try soon, but I would copy it to the code right away and let you know if anything went wrong in a week or two time, when it would hit QA . But I am sure it will work . Thank you!
|
|
|
Post by DarkTonic Dev on Oct 5, 2021 15:02:52 GMT
No problem.
|
|