UnityEditor.ComplexD.Exp C# (CSharp) Method

Exp() public static method

public static Exp ( double omega ) : ComplexD
omega double
return ComplexD
        public static ComplexD Exp(double omega)
        {
            return new ComplexD(Math.Cos(omega), Math.Sin(omega));
        }

Usage Example

示例#1
0
        static bool ParamEqualizerCurveEditor(IAudioEffectPlugin plugin, Rect r, ref float centerFreq, ref float bandwidth, ref float gain, float blend)
        {
            Event evt       = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);

            r = AudioCurveRendering.BeginCurveFrame(r);

            float minCenterFreq, maxCenterFreq, defCenterFreq; plugin.GetFloatParameterInfo(kCenterFreqName, out minCenterFreq, out maxCenterFreq, out defCenterFreq);
            float minOctaveRange, maxOctaveRange, defOctaveRange; plugin.GetFloatParameterInfo(kOctaveRangeName, out minOctaveRange, out maxOctaveRange, out defOctaveRange);
            float minGain, maxGain, defGain; plugin.GetFloatParameterInfo(kFrequencyGainName, out minGain, out maxGain, out defGain);

            bool modifiedValue = false;

            switch (evt.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (r.Contains(Event.current.mousePosition) && evt.button == 0)
                {
                    GUIUtility.hotControl = controlID;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    float dragAcceleration = Event.current.alt ? .25f : 1f;
                    centerFreq = Mathf.Clamp((float)MapNormalizedFrequency(MapNormalizedFrequency(centerFreq, plugin.GetSampleRate(), useLogScale, false) + evt.delta.x / r.width, plugin.GetSampleRate(), useLogScale, true), minCenterFreq, maxCenterFreq);
                    if (Event.current.shift)
                    {
                        bandwidth = Mathf.Clamp(bandwidth - evt.delta.y * 0.02f * dragAcceleration, minOctaveRange, maxOctaveRange);
                    }
                    else
                    {
                        gain = Mathf.Clamp(gain - evt.delta.y * 0.01f * dragAcceleration, minGain, maxGain);
                    }
                    modifiedValue = true;
                    evt.Use();
                }
                break;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Mark CenterFreq with a vertical line
                float c = (float)MapNormalizedFrequency(centerFreq, plugin.GetSampleRate(), useLogScale, false);
                EditorGUI.DrawRect(new Rect(c * r.width + r.x, r.y, 1f, r.height), GUIUtility.hotControl == controlID ? new Color(0.6f, 0.6f, 0.6f) : new Color(0.4f, 0.4f, 0.4f));

                // Curve
                HandleUtility.ApplyWireMaterial();
                double kPI   = 3.1415926;
                double wm    = -2.0f * kPI / plugin.GetSampleRate();
                double w0    = 2.0 * kPI * centerFreq / plugin.GetSampleRate();
                double Q     = 1.0 / bandwidth;
                double A     = gain;
                double alpha = Math.Sin(w0) / (2.0 * Q);
                double b0    = 1.0 + alpha * A;
                double b1    = -2.0 * Math.Cos(w0);
                double b2    = 1.0 - alpha * A;
                double a0    = 1.0 + alpha / A;
                double a1    = -2.0 * Math.Cos(w0);
                double a2    = 1.0 - alpha / A;
                AudioCurveRendering.DrawCurve(
                    r,
                    delegate(float x)
                {
                    double f   = MapNormalizedFrequency((double)x, plugin.GetSampleRate(), useLogScale, true);
                    ComplexD w = ComplexD.Exp(wm * f);
                    ComplexD n = w * (w * b2 + b1) + b0;
                    ComplexD d = w * (w * a2 + a1) + a0;
                    ComplexD h = n / d;
                    double mag = Math.Log10(h.Mag2());
                    return((float)(0.5 * mag));    // 20 dB range
                },
                    ScaleAlpha(AudioCurveRendering.kAudioOrange, blend)
                    );
            }

            DrawFrequencyTickMarks(r, plugin.GetSampleRate(), useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend));

            AudioCurveRendering.EndCurveFrame();

            return(modifiedValue);
        }
All Usage Examples Of UnityEditor.ComplexD::Exp