Mag2() public method

public Mag2 ( ) : double
return double
Beispiel #1
0
        public static ComplexD Pow(ComplexD a, double b)
        {
            double num  = Math.Atan2(a.imag, a.real);
            double num2 = Math.Pow(a.Mag2(), b * 0.5);

            return(new ComplexD(num2 * Math.Cos(num * b), num2 * Math.Sin(num * b)));
        }
Beispiel #2
0
        static public ComplexD Pow(ComplexD a, double b)
        {
            double p = Math.Atan2(a.imag, a.real);
            double m = Math.Pow(a.Mag2(), b * 0.5f);

            return(new ComplexD(
                       m * Math.Cos(p * b),
                       m * Math.Sin(p * b)
                       ));
        }
        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);
        }
Beispiel #4
0
        private static bool ParamEqualizerCurveEditor(IAudioEffectPlugin plugin, Rect r, ref float centerFreq, ref float bandwidth, ref float gain, float blend)
        {
            Event current   = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);

            r = AudioCurveRendering.BeginCurveFrame(r);
            float min;
            float max;
            float num;

            plugin.GetFloatParameterInfo(ParamEqGUI.kCenterFreqName, out min, out max, out num);
            float min2;
            float max2;
            float num2;

            plugin.GetFloatParameterInfo(ParamEqGUI.kOctaveRangeName, out min2, out max2, out num2);
            float min3;
            float max3;
            float num3;

            plugin.GetFloatParameterInfo(ParamEqGUI.kFrequencyGainName, out min3, out max3, out num3);
            bool result = false;

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

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    float num4 = (!Event.current.alt) ? 1f : 0.25f;
                    centerFreq = Mathf.Clamp((float)ParamEqGUI.MapNormalizedFrequency(ParamEqGUI.MapNormalizedFrequency((double)centerFreq, (double)plugin.GetSampleRate(), true, false) + (double)(current.delta.x / r.width), (double)plugin.GetSampleRate(), true, true), min, max);
                    if (Event.current.shift)
                    {
                        bandwidth = Mathf.Clamp(bandwidth - current.delta.y * 0.02f * num4, min2, max2);
                    }
                    else
                    {
                        gain = Mathf.Clamp(gain - current.delta.y * 0.01f * num4, min3, max3);
                    }
                    result = true;
                    current.Use();
                }
                break;
            }
            if (Event.current.type == EventType.Repaint)
            {
                float num5 = (float)ParamEqGUI.MapNormalizedFrequency((double)centerFreq, (double)plugin.GetSampleRate(), true, false);
                EditorGUI.DrawRect(new Rect(num5 * r.width + r.x, r.y, 1f, r.height), (GUIUtility.hotControl != controlID) ? new Color(0.4f, 0.4f, 0.4f) : new Color(0.6f, 0.6f, 0.6f));
                HandleUtility.ApplyWireMaterial();
                double num6  = 3.1415926;
                double wm    = -2.0 * num6 / (double)plugin.GetSampleRate();
                double num7  = 2.0 * num6 * (double)centerFreq / (double)plugin.GetSampleRate();
                double num8  = 1.0 / (double)bandwidth;
                double num9  = (double)gain;
                double num10 = Math.Sin(num7) / (2.0 * num8);
                double b0    = 1.0 + num10 * num9;
                double b1    = -2.0 * Math.Cos(num7);
                double b2    = 1.0 - num10 * num9;
                double a0    = 1.0 + num10 / num9;
                double a1    = -2.0 * Math.Cos(num7);
                double a2    = 1.0 - num10 / num9;
                AudioCurveRendering.DrawCurve(r, delegate(float x)
                {
                    double num11      = ParamEqGUI.MapNormalizedFrequency((double)x, (double)plugin.GetSampleRate(), true, true);
                    ComplexD a        = ComplexD.Exp(wm * num11);
                    ComplexD a2       = a * (a * b2 + b1) + b0;
                    ComplexD b        = a * (a * a2 + a1) + a0;
                    ComplexD complexD = a2 / b;
                    double num12      = Math.Log10(complexD.Mag2());
                    return((float)(0.5 * num12));
                }, ParamEqGUI.ScaleAlpha(AudioCurveRendering.kAudioOrange, blend));
            }
            ParamEqGUI.DrawFrequencyTickMarks(r, (float)plugin.GetSampleRate(), true, new Color(1f, 1f, 1f, 0.3f * blend));
            AudioCurveRendering.EndCurveFrame();
            return(result);
        }
Beispiel #5
0
 public static ComplexD Pow(ComplexD a, double b)
 {
     double num = Math.Atan2(a.imag, a.real);
     double num2 = Math.Pow(a.Mag2(), b * 0.5);
     return new ComplexD(num2 * Math.Cos(num * b), num2 * Math.Sin(num * b));
 }