Exemple #1
0
        public float CalculateVolume()
        {
            float num    = AudioTools.DBToLinear(_volumeParameter.Get(FabricTimer.Get()));
            float linear = 1f - (1f - _gain * num);

            return(AudioTools.LinearToDB(linear));
        }
        private static void DrawMeter(string name, float value, float length)
        {
            float db = AudioTools.LinearToDB(value);

            AudioTools.DBToNormalizedDB(db);
            GUILayout.BeginVertical("box");
            GUILayout.Label(name + ":" + db.ToString("N0") + " dB");
            GUILayout.EndVertical();
        }
 private void Update()
 {
     if (!_isInitialised)
     {
         _groupComponents = FabricManager.Instance.gameObject.GetComponentsInChildren <GroupComponent>();
         _isInitialised   = true;
     }
     if (_presetList != null)
     {
         for (int i = 0; i < _presetList.Length; i++)
         {
             Preset preset = _presetList[i];
             if (preset.HasEventNameSet() && preset.IsEventActive())
             {
                 AddPreset(preset);
             }
         }
     }
     if (_groupComponents == null)
     {
         return;
     }
     for (int j = 0; j < _groupComponents.Length; j++)
     {
         GroupComponent groupComponent = _groupComponents[j];
         float          num            = 0f;
         float          num2           = 1f;
         for (int k = 0; k < _activePresets.Count; k++)
         {
             Preset preset2 = _activePresets[k];
             if (preset2.HasEventNameSet() && !preset2.IsEventActive() && !preset2.IsDeactivating)
             {
                 preset2.Deactivate();
             }
             if (preset2.IsActive())
             {
                 GroupPreset groupComponentByID = preset2.GetGroupComponentByID(groupComponent.GetInstanceID());
                 if (groupComponentByID != null)
                 {
                     num  += groupComponentByID.CalculateVolume();
                     num2 *= groupComponentByID.CalculatePitch();
                 }
             }
             else
             {
                 _activePresets.Remove(preset2);
             }
         }
         float value = AudioTools.DBToLinear(num);
         AudioTools.Limit(ref value, 0f, 1f);
         groupComponent.MixerVolume = value;
         groupComponent.MixerPitch  = num2;
     }
 }
        public void MixerSlot(string title, GroupComponent component)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginVertical();
            DisplayCenterText("Pitch");
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            component.Pitch = GUILayout.HorizontalSlider(component.Pitch, -4f, 4f, GUILayout.MinWidth(50f));
            GUILayout.Label(component.Pitch.ToString("F"));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.BeginHorizontal(GUILayout.MaxHeight(GetActualSize(40f)));
            GUILayout.FlexibleSpace();
            component.Mute = GUILayout.Toggle(component.Mute, "Mute", "button");
            bool solo = component.Solo;

            component.Solo = GUILayout.Toggle(component.Solo, "Solo", "button");
            if (component.Solo)
            {
                for (int i = 0; i < _soloComponents.Count; i++)
                {
                    if (_soloComponents[i] != null && _soloComponents[i] != component)
                    {
                        _soloComponents[i].Mute = true;
                    }
                }
            }
            else if (solo != component.Solo)
            {
                for (int j = 0; j < _soloComponents.Count; j++)
                {
                    if (_soloComponents[j] != null && _soloComponents[j] != component)
                    {
                        _soloComponents[j].Mute = false;
                    }
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginVertical();
            DisplayCenterText("Volume");
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            component.Volume = GUILayout.VerticalSlider(component.Volume, 1f, 0f, GUILayout.MinHeight(100f));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            DisplayCenterText(AudioTools.LinearToDB(component.Volume).ToString("F") + "dB");
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
 public void Update()
 {
     profiler.Begin();
     if (samples != null && audioComponents != null)
     {
         Array.Clear(samples, 0, samples.Length);
         for (int i = 0; i < audioComponents.Length; i++)
         {
             AudioComponent audioComponent = audioComponents[i];
             if (!(audioComponent != null) || !audioComponent.IsPlaying() || !(audioComponent.AudioSource != null))
             {
                 continue;
             }
             AudioSource audioSource = audioComponent.AudioSource;
             if (!audioSource.isPlaying || !(audioComponent.ParentGameObject != null))
             {
                 continue;
             }
             float num = 0f;
             if (_is3D)
             {
                 float distance = 0f;
                 if (listener != null)
                 {
                     distance = (listener.transform.position - audioComponent.ParentGameObject.transform.position).magnitude;
                 }
                 num = distanceAttenuation(distance, audioSource.minDistance, audioSource.maxDistance, audioSource.rolloffMode) * audioSource.volume;
             }
             else
             {
                 num = audioSource.volume;
             }
             for (int j = 0; j < 2; j++)
             {
                 audioSource.GetOutputData(tempSamples, j);
                 for (int k = 0; k < 256; k++)
                 {
                     samples[j, k] += tempSamples[k] * num;
                 }
             }
         }
         VolumeMeterProcess(ref volumeMeterState);
     }
     if (_globalParameterName != null)
     {
         float db = AudioTools.LinearToDB(volumeMeterState.mRMS);
         EventManager.Instance._globalParameterManager.SetGlobalParameter(_globalParameterName, AudioTools.DBToNormalizedDB(db));
     }
     profiler.End();
 }
        private void DrawSideChain(SideChain sideChain, float length)
        {
            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("SideChain");
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            float db = AudioTools.LinearToDB(1f - sideChain._sideChainGain);

            AudioTools.DBToNormalizedDB(db);
            GUILayout.BeginVertical("box");
            GUILayout.Label("Gain:" + db.ToString("N0") + " dB");
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
Exemple #7
0
        private void Update()
        {
            profiler.Begin();
            if (_useComponentIsPlayingFlag)
            {
                if (_componentToListen != null && _componentToListen.IsComponentActive())
                {
                    _sideChainGain = gain;
                }
                else
                {
                    _sideChainGain = 1f;
                }
            }
            else
            {
                if (!(_volumeMeter != null))
                {
                    _sideChainGain = 1f;
                    profiler.End();
                    return;
                }
                float mRMS = _volumeMeter.volumeMeterState.mRMS;
                float db   = AudioTools.LinearToDB(mRMS);
                _sideChainGain = AudioTools.DBToNormalizedDB(db);
            }
            float currentTimeMS = FabricTimer.Get();

            if (_sideChainGain > _envelope.GetCurrentValue())
            {
                _envelope.SetTarget(currentTimeMS, _sideChainGain, fadeUpRate, 0.5f);
            }
            else
            {
                _envelope.SetTarget(currentTimeMS, _sideChainGain, fadeDownRate, 0.5f);
            }
            if (_useComponentIsPlayingFlag)
            {
                _sideChainGain = _envelope.Get(currentTimeMS);
            }
            else
            {
                _sideChainGain = 1f - _envelope.Get(currentTimeMS) * gain;
            }
            profiler.End();
        }
Exemple #8
0
        public void Update()
        {
            float realtimeDelta = FabricTimer.GetRealtimeDelta();

            if (_direction > 0f)
            {
                _seekTarget += _velocity * realtimeDelta;
            }
            else
            {
                _seekTarget -= _velocity * realtimeDelta;
            }
            _markers.Update(_seekTarget, _direction);
            if (_markers.IsMarkerKeyOff())
            {
                _seekTarget = _markers._keyOffMarker._value;
            }
            if (_velocity != 0f)
            {
                if (_seekTarget > MAX_NORMALISED_RANGE)
                {
                    if (_loopBehaviour == ParameterLoopBehaviour.Loop)
                    {
                        _seekTarget -= MAX_NORMALISED_RANGE - MIN_NORMALISED_RANGE;
                    }
                    else if (_loopBehaviour == ParameterLoopBehaviour.OneShot)
                    {
                        _seekTarget = MAX_NORMALISED_RANGE;
                    }
                    else if (_loopBehaviour == ParameterLoopBehaviour.PingPong)
                    {
                        _direction = -1f;
                    }
                    else
                    {
                        _seekTarget = MAX_NORMALISED_RANGE;
                    }
                    _markers.Reset();
                }
                else if (_seekTarget < MIN_NORMALISED_RANGE)
                {
                    if (_loopBehaviour == ParameterLoopBehaviour.Loop)
                    {
                        _seekTarget += MAX_NORMALISED_RANGE - MIN_NORMALISED_RANGE;
                    }
                    else if (_loopBehaviour == ParameterLoopBehaviour.OneShot)
                    {
                        _seekTarget = MIN_NORMALISED_RANGE;
                    }
                    else if (_loopBehaviour == ParameterLoopBehaviour.PingPong)
                    {
                        _direction = 1f;
                    }
                    else
                    {
                        _seekTarget = MIN_NORMALISED_RANGE;
                    }
                    _markers.Reset();
                }
                if (_seekTarget > MAX_NORMALISED_RANGE)
                {
                    _seekTarget = MAX_NORMALISED_RANGE;
                }
                else if (_seekTarget < MIN_NORMALISED_RANGE)
                {
                    _seekTarget = MIN_NORMALISED_RANGE;
                }
            }
            if (_seekSpeed != 0f)
            {
                float num = _seekSpeed * realtimeDelta;
                if (_seekTarget > _value)
                {
                    _value += num;
                    if (_value > _seekTarget)
                    {
                        _value = _seekTarget;
                    }
                }
                else if (_seekTarget < _value)
                {
                    _value -= num;
                    if (_value < _seekTarget)
                    {
                        _value = _seekTarget;
                    }
                }
            }
            else
            {
                _value = _seekTarget;
            }
            AudioTools.Limit(ref _value, 0f, 1f);
        }
Exemple #9
0
 public void SetValue(float value)
 {
     AudioTools.Limit(ref value, _min, _max);
     _seekTarget = RTPManager.CalculateNewValueRange(value, 0f, 1f, _min, _max);
 }