public void DrawFilterCurve( Rect r, float[] coeffs, bool lowGain, bool midGain, bool highGain, Color color, bool useLogScale, bool filled, double masterGain, double samplerate, double magScale) { double wm = -2.0f * 3.1415926 / samplerate; ComplexD one = new ComplexD(1.0f, 0.0f); AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { ComplexD w = ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency((double)x, samplerate, useLogScale, true)); ComplexD hl = (!lowGain) ? one : (w * (w * coeffs[0] + coeffs[1]) + coeffs[2]) / (w * (w * coeffs[3] + coeffs[4]) + 1.0f); ComplexD hp = (!midGain) ? one : (w * (w * coeffs[5] + coeffs[6]) + coeffs[7]) / (w * (w * coeffs[8] + coeffs[9]) + 1.0f); ComplexD hh = (!highGain) ? one : (w * (w * coeffs[10] + coeffs[11]) + coeffs[12]) / (w * (w * coeffs[13] + coeffs[14]) + 1.0f); ComplexD h = hh * hp * hl; double mag = masterGain + 10.0 * Math.Log10(h.Mag2()); return((float)(mag * magScale)); }; if (filled) { AudioCurveRendering.DrawFilledCurve(r, d, color); } else { AudioCurveRendering.DrawCurve(r, d, color); } }
private void DrawFilterCurve( Rect r, float[] coeffs, float lowGain, float midGain, float highGain, Color color, bool filled, double samplerate, double magScale) { double wm = -2.0 * 3.1415926 / samplerate; AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { MathHelpers.ComplexD w = MathHelpers.ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency((double)x, samplerate, useLogScale, true)); MathHelpers.ComplexD lpf = MathHelpers.ComplexD.Pow((w * (w * coeffs[0] + coeffs[1]) + coeffs[2]) / (w * (w * coeffs[3] + coeffs[4]) + 1.0f), filterOrder); MathHelpers.ComplexD bpf1 = MathHelpers.ComplexD.Pow((w * (w * coeffs[5] + coeffs[6]) + coeffs[7]) / (w * (w * coeffs[8] + coeffs[9]) + 1.0f), filterOrder); MathHelpers.ComplexD bpf2 = MathHelpers.ComplexD.Pow((w * (w * coeffs[10] + coeffs[11]) + coeffs[12]) / (w * (w * coeffs[13] + coeffs[14]) + 1.0f), filterOrder); MathHelpers.ComplexD hpf = MathHelpers.ComplexD.Pow((w * (w * coeffs[15] + coeffs[16]) + coeffs[17]) / (w * (w * coeffs[18] + coeffs[19]) + 1.0f), filterOrder); double h = (lpf * lowGain).Mag2() + (bpf1 * bpf2 * midGain).Mag2() + (hpf * highGain).Mag2(); double mag = masterGain + 10.0 * Math.Log10(h); return((float)(mag * magScale)); }; if (filled) { AudioCurveRendering.DrawFilledCurve(r, d, color); } else { AudioCurveRendering.DrawCurve(r, d, color); } }
public void DrawSpectrum(Rect r, bool useLogScale, float[] data, float dB_range, float samplerate, float col_r, float col_g, float col_b, float col_a, float gainOffset_dB) { float xscale = (float)(data.Length - 2) * 2.0f / samplerate; float yscale = 1.0f / dB_range; AudioCurveRendering.DrawCurve( r, delegate(float x) { double f = GUIHelpers.MapNormalizedFrequency((double)x, samplerate, useLogScale, true) * xscale; int i = (int)Math.Floor(f); double h = data[i] + (data[i + 1] - data[i]) * (f - i); double mag = (h > 0.0) ? (20.0f * Math.Log10(h) + gainOffset_dB) : -120.0; return((float)(yscale * mag)); }, new Color(col_r, col_g, col_b, col_a)); }
public void DrawFilterCurve( Rect r, float[] coeffs, Color color, int numModes, bool useLogScale, bool filled, double samplerate, double magScale) { double wm = -2.0f * 3.1415926 / samplerate; ComplexD zero = new ComplexD(0.0f, 0.0f); ComplexD one = new ComplexD(1.0f, 0.0f); AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { ComplexD w = ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency((double)x, samplerate, useLogScale, true)); ComplexD h = zero; int num = numModes * 3; for (int n = 0; n < num; n += 3) { h += coeffs[n] * (one - w * w) / (w * (w * coeffs[n + 2] + coeffs[n + 1]) + 1.0); } double mag = 10.0 * Math.Log10(h.Mag2()); return((float)(mag * magScale)); }; if (filled) { AudioCurveRendering.DrawFilledCurve(r, d, color); } else { AudioCurveRendering.DrawCurve(r, d, color); } }
public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate) { Event evt = Event.current; int controlID = GUIUtility.GetControlID(FocusType.Passive); EventType evtType = evt.GetTypeForControl(controlID); r = AudioCurveRendering.BeginCurveFrame(r); float thr = 4.0f; bool changed = false; float x = evt.mousePosition.x - r.x; if (evtType == EventType.MouseDown && r.Contains(evt.mousePosition) && evt.button == 0) { float lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width; float mf = (float)GUIHelpers.MapNormalizedFrequency(midFreq, samplerate, useLogScale, false) * r.width; float hf = (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width; float ld = Mathf.Abs(x - lf); float md = Mathf.Abs(x - mf); float hd = Mathf.Abs(x - hf); float d = ld; dragOperation = DragOperation.Low; if (md < d) { d = md; dragOperation = DragOperation.Mid; } if (hd < d) { d = hd; dragOperation = DragOperation.High; } GUIUtility.hotControl = controlID; EditorGUIUtility.SetWantsMouseJumping(1); evt.Use(); } else if (evtType == EventType.MouseDrag && GUIUtility.hotControl == controlID) { switch (dragOperation) { case DragOperation.Low: lowFreq = Mathf.Clamp((float)GUIHelpers.MapNormalizedFrequency(GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) + evt.delta.x / r.width, samplerate, useLogScale, true), 10.0f, samplerate * 0.5f); if (evt.shift) { lowQ = Mathf.Clamp(lowQ - evt.delta.y * 0.05f, 0.01f, 10.0f); } else { lowGain = Mathf.Clamp(lowGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } break; case DragOperation.Mid: midFreq = Mathf.Clamp((float)GUIHelpers.MapNormalizedFrequency(GUIHelpers.MapNormalizedFrequency(midFreq, samplerate, useLogScale, false) + evt.delta.x / r.width, samplerate, useLogScale, true), 10.0f, samplerate * 0.5f); if (evt.shift) { midQ = Mathf.Clamp(midQ - evt.delta.y * 0.05f, 0.01f, 10.0f); } else { midGain = Mathf.Clamp(midGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } break; case DragOperation.High: highFreq = Mathf.Clamp((float)GUIHelpers.MapNormalizedFrequency(GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) + evt.delta.x / r.width, samplerate, useLogScale, true), 10.0f, samplerate * 0.5f); if (evt.shift) { highQ = Mathf.Clamp(highQ - evt.delta.y * 0.05f, 0.01f, 10.0f); } else { highGain = Mathf.Clamp(highGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } break; } changed = true; evt.Use(); } else if (evtType == EventType.MouseUp && evt.button == 0 && GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; EditorGUIUtility.SetWantsMouseJumping(0); evt.Use(); } if (Event.current.type == EventType.Repaint) { float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f; // Mark bands (low, medium and high bands) DrawBandSplitMarker(plugin, r, (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width, thr, GUIUtility.hotControl == controlID && dragOperation == DragOperation.Low, new Color(0, 0, 0, blend)); DrawBandSplitMarker(plugin, r, (float)GUIHelpers.MapNormalizedFrequency(midFreq, samplerate, useLogScale, false) * r.width, thr, GUIUtility.hotControl == controlID && dragOperation == DragOperation.Mid, new Color(0.5f, 0.5f, 0.5f, blend)); DrawBandSplitMarker(plugin, r, (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width, thr, GUIUtility.hotControl == controlID && dragOperation == DragOperation.High, new Color(1.0f, 1.0f, 1.0f, blend)); const float dbRange = 40.0f; const float magScale = 1.0f / dbRange; float[] coeffs; plugin.GetFloatBuffer("Coeffs", out coeffs, 15); // Draw filled curve DrawFilterCurve( r, coeffs, true, true, true, ScaleAlpha(AudioCurveRendering.kAudioOrange, blend), useLogScale, false, masterGain, samplerate, magScale); if (GUIUtility.hotControl == controlID) { DrawFilterCurve( r, coeffs, dragOperation == DragOperation.Low, dragOperation == DragOperation.Mid, dragOperation == DragOperation.High, new Color(1.0f, 1.0f, 1.0f, 0.2f * blend), useLogScale, true, masterGain, samplerate, magScale); } if (showSpectrum) { int specLen = (int)r.width; float[] spec; plugin.GetFloatBuffer("InputSpec", out spec, specLen); DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 0.3f, 1.0f, 0.3f, 0.5f * blend, 0.0f); plugin.GetFloatBuffer("OutputSpec", out spec, specLen); DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 1.0f, 0.3f, 0.3f, 0.5f * blend, 0.0f); } GUIHelpers.DrawFrequencyTickMarks(r, samplerate, useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend)); } AudioCurveRendering.EndCurveFrame(); return(changed); }
public bool DrawControl(IAudioEffectPlugin plugin, Rect r, float samplerate) { Event evt = Event.current; int controlID = GUIUtility.GetControlID(FocusType.Passive); EventType evtType = evt.GetTypeForControl(controlID); r = AudioCurveRendering.BeginCurveFrame(r); float thr = 4.0f; bool changed = false; float x = evt.mousePosition.x - r.x; if (evtType == EventType.MouseDown && r.Contains(evt.mousePosition) && evt.button == 0) { float lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width; float hf = (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width; dragOperation = DragOperation.Mid; if (x < lf + thr) { dragOperation = DragOperation.Low; } else if (x > hf - thr) { dragOperation = DragOperation.High; } GUIUtility.hotControl = controlID; EditorGUIUtility.SetWantsMouseJumping(1); evt.Use(); } else if (evtType == EventType.MouseDrag && GUIUtility.hotControl == controlID) { if (dragOperation == DragOperation.Low || dragOperation == DragOperation.Mid) { lowFreq = Mathf.Clamp((float)GUIHelpers.MapNormalizedFrequency(GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) + evt.delta.x / r.width, samplerate, useLogScale, true), 10.0f, highFreq); } if (dragOperation == DragOperation.Low) { lowGain = Mathf.Clamp(lowGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } if (dragOperation == DragOperation.Mid) { midGain = Mathf.Clamp(midGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } if (dragOperation == DragOperation.Mid || dragOperation == DragOperation.High) { highFreq = Mathf.Clamp((float)GUIHelpers.MapNormalizedFrequency(GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) + evt.delta.x / r.width, samplerate, useLogScale, true), lowFreq, samplerate * 0.5f); } if (dragOperation == DragOperation.High) { highGain = Mathf.Clamp(highGain - evt.delta.y * 0.5f, -100.0f, 100.0f); } changed = true; evt.Use(); } else if (evtType == EventType.MouseUp && evt.button == 0 && GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; EditorGUIUtility.SetWantsMouseJumping(0); evt.Use(); } if (Event.current.type == EventType.Repaint) { float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f; // Mark bands (low, medium and high bands) Color lowColor = new Color(0.0f, 0.0f, 0.0f, blend); Color midColor = new Color(0.5f, 0.5f, 0.5f, blend); Color highColor = new Color(1.0f, 1.0f, 1.0f, blend); DrawBandSplitMarker(plugin, r, (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width, thr, GUIUtility.hotControl == controlID && (dragOperation == DragOperation.Low || dragOperation == DragOperation.Mid), lowColor); DrawBandSplitMarker(plugin, r, (float)GUIHelpers.MapNormalizedFrequency(highFreq, samplerate, useLogScale, false) * r.width, thr, GUIUtility.hotControl == controlID && (dragOperation == DragOperation.High || dragOperation == DragOperation.Mid), highColor); const float dbRange = 40.0f; const float magScale = 1.0f / dbRange; float[] liveData; plugin.GetFloatBuffer("LiveData", out liveData, 6); float[] coeffs; plugin.GetFloatBuffer("Coeffs", out coeffs, 20); if (GUIUtility.hotControl == controlID) { DrawFilterCurve( r, coeffs, (dragOperation == DragOperation.Low) ? Mathf.Pow(10.0f, 0.05f * lowGain) : 0.0f, (dragOperation == DragOperation.Mid) ? Mathf.Pow(10.0f, 0.05f * midGain) : 0.0f, (dragOperation == DragOperation.High) ? Mathf.Pow(10.0f, 0.05f * highGain) : 0.0f, new Color(1.0f, 1.0f, 1.0f, 0.2f * blend), true, samplerate, magScale); } DrawFilterCurve(r, coeffs, Mathf.Pow(10.0f, 0.05f * lowGain) * liveData[0], 0.0f, 0.0f, lowColor, false, samplerate, magScale); DrawFilterCurve(r, coeffs, 0.0f, Mathf.Pow(10.0f, 0.05f * midGain) * liveData[1], 0.0f, midColor, false, samplerate, magScale); DrawFilterCurve(r, coeffs, 0.0f, 0.0f, Mathf.Pow(10.0f, 0.05f * highGain) * liveData[2], highColor, false, samplerate, magScale); DrawFilterCurve( r, coeffs, Mathf.Pow(10.0f, 0.05f * lowGain) * liveData[0], Mathf.Pow(10.0f, 0.05f * midGain) * liveData[1], Mathf.Pow(10.0f, 0.05f * highGain) * liveData[2], ScaleAlpha(AudioCurveRendering.kAudioOrange, 0.5f), false, samplerate, magScale); DrawFilterCurve( r, coeffs, Mathf.Pow(10.0f, 0.05f * lowGain), Mathf.Pow(10.0f, 0.05f * midGain), Mathf.Pow(10.0f, 0.05f * highGain), AudioCurveRendering.kAudioOrange, false, samplerate, magScale); if (showSpectrum) { int specLen = (int)r.width; float[] spec; plugin.GetFloatBuffer("InputSpec", out spec, specLen); DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 0.3f, 1.0f, 0.3f, 0.5f * blend, 0.0f); plugin.GetFloatBuffer("OutputSpec", out spec, specLen); DrawSpectrum(r, useLogScale, spec, dbRange, samplerate, 1.0f, 0.3f, 0.3f, 0.5f * blend, 0.0f); } GUIHelpers.DrawFrequencyTickMarks(r, samplerate, useLogScale, new Color(1.0f, 1.0f, 1.0f, 0.3f * blend)); } AudioCurveRendering.EndCurveFrame(); return(changed); }