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

            return(AudioTools.LinearToDB(linear));
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
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();
        }