NScumm.Core.Audio.Mixer.GetVolumeForSoundType C# (CSharp) Method

GetVolumeForSoundType() public method

public GetVolumeForSoundType ( SoundType type ) : int
type SoundType
return int
        public int GetVolumeForSoundType(SoundType type)
        {
            Debug.Assert(0 <= type && (int)type < soundTypeSettings.Length);
            return soundTypeSettings[(int)type].Volume;
        }

Usage Example

Example #1
0
        void UpdateChannelVolumes()
        {
            // From the channel balance/volume and the global volume, we compute
            // the effective volume for the left and right channel. Note the
            // slightly odd divisor: the 255 reflects the fact that the maximal
            // value for _volume is 255, while the 127 is there because the
            // balance value ranges from -127 to 127.  The mixer (music/sound)
            // volume is in the range 0 - kMaxMixerVolume.
            // Hence, the vol_l/vol_r values will be in that range, too

            if (!_mixer.IsSoundTypeMuted(Type))
            {
                int vol = _mixer.GetVolumeForSoundType(Type) * _volume;

                if (_balance == 0)
                {
                    _volL = vol / Mixer.MaxChannelVolume;
                    _volR = vol / Mixer.MaxChannelVolume;
                }
                else if (_balance < 0)
                {
                    _volL = vol / Mixer.MaxChannelVolume;
                    _volR = ((127 + _balance) * vol) / (Mixer.MaxChannelVolume * 127);
                }
                else
                {
                    _volL = ((127 - _balance) * vol) / (Mixer.MaxChannelVolume * 127);
                    _volR = vol / Mixer.MaxChannelVolume;
                }
            }
            else
            {
                _volL = _volR = 0;
            }
        }