public void DrawSpectrum( Rect r, bool useLogScale, float[] data, float dBRange, float samplerate, float colR, float colG, float colB, float colA, float gainOffsetDB) { var xscale = ((data.Length - 2) * 2.0f) / samplerate; var yscale = 1.0f / dBRange; AudioCurveRendering.DrawCurve( r, delegate(float x) { var f = GUIHelpers.MapNormalizedFrequency(x, samplerate, useLogScale, true) * xscale; var i = (int)Math.Floor(f); var h = data[i] + ((data[i + 1] - data[i]) * (f - i)); var mag = h > 0.0 ? (20.0f * Math.Log10(h)) + gainOffsetDB : -120.0; return((float)(yscale * mag)); }, new Color(colR, colG, colB, colA) ); }
private void DrawFilterCurve( Rect r, float[] coeffs, float lowGain, float midGain, float highGain, Color color, bool filled, double samplerate, double magScale) { var wm = (-2.0 * 3.1415926) / samplerate; AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { var w = ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency(x, samplerate, useLogScale, true)); var lpf = ComplexD.Pow( ((w * ((w * coeffs[0]) + coeffs[1])) + coeffs[2]) / ((w * ((w * coeffs[3]) + coeffs[4])) + 1.0f), filterOrder ); var bpf1 = ComplexD.Pow( ((w * ((w * coeffs[5]) + coeffs[6])) + coeffs[7]) / ((w * ((w * coeffs[8]) + coeffs[9])) + 1.0f), filterOrder ); var bpf2 = ComplexD.Pow( ((w * ((w * coeffs[10]) + coeffs[11])) + coeffs[12]) / ((w * ((w * coeffs[13]) + coeffs[14])) + 1.0f), filterOrder ); var hpf = ComplexD.Pow( ((w * ((w * coeffs[15]) + coeffs[16])) + coeffs[17]) / ((w * ((w * coeffs[18]) + coeffs[19])) + 1.0f), filterOrder ); var h = (lpf * lowGain).Mag2() + (bpf1 * bpf2 * midGain).Mag2() + (hpf * highGain).Mag2(); var 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 DrawFilterCurve( Rect r, float[] coeffs, bool lowGain, bool midGain, bool highGain, Color color, bool useLogScale, bool filled, double masterGain, double samplerate, double magScale) { var wm = (-2.0f * 3.1415926) / samplerate; var one = new ComplexD(1.0f, 0.0f); AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { var w = ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency(x, samplerate, useLogScale, true)); var hl = !lowGain ? one : ((w * ((w * coeffs[0]) + coeffs[1])) + coeffs[2]) / ((w * ((w * coeffs[3]) + coeffs[4])) + 1.0f); var hp = !midGain ? one : ((w * ((w * coeffs[5]) + coeffs[6])) + coeffs[7]) / ((w * ((w * coeffs[8]) + coeffs[9])) + 1.0f); var hh = !highGain ? one : ((w * ((w * coeffs[10]) + coeffs[11])) + coeffs[12]) / ((w * ((w * coeffs[13]) + coeffs[14])) + 1.0f); var h = hh * hp * hl; var 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); } }
public void DrawFilterCurve( Rect r, float[] coeffs, Color color, int numModes, bool useLogScale, bool filled, double samplerate, double magScale) { var wm = (-2.0f * 3.1415926) / samplerate; var zero = new ComplexD(0.0f, 0.0f); var one = new ComplexD(1.0f, 0.0f); AudioCurveRendering.AudioCurveEvaluator d = delegate(float x) { var w = ComplexD.Exp(wm * GUIHelpers.MapNormalizedFrequency(x, samplerate, useLogScale, true)); var h = zero; var num = numModes * 3; for (var n = 0; n < num; n += 3) { h += (coeffs[n] * (one - (w * w))) / ((w * ((w * coeffs[n + 2]) + coeffs[n + 1])) + 1.0); } var 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) { var evt = Event.current; var controlID = GUIUtility.GetControlID(FocusType.Passive); var evtType = evt.GetTypeForControl(controlID); r = AudioCurveRendering.BeginCurveFrame(r); var thr = 4.0f; var changed = false; var x = evt.mousePosition.x - r.x; if ((evtType == EventType.MouseDown) && r.Contains(evt.mousePosition) && (evt.button == 0)) { var lf = (float)GUIHelpers.MapNormalizedFrequency(_lowFreq, samplerate, _useLogScale, false) * r.width; var mf = (float)GUIHelpers.MapNormalizedFrequency(_midFreq, samplerate, _useLogScale, false) * r.width; var hf = (float)GUIHelpers.MapNormalizedFrequency(_highFreq, samplerate, _useLogScale, false) * r.width; var ld = Mathf.Abs(x - lf); var md = Mathf.Abs(x - mf); var hd = Mathf.Abs(x - hf); var 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) { var 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) { var 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) { var evt = Event.current; var controlID = GUIUtility.GetControlID(FocusType.Passive); var evtType = evt.GetTypeForControl(controlID); r = AudioCurveRendering.BeginCurveFrame(r); var thr = 4.0f; var changed = false; var x = evt.mousePosition.x - r.x; if ((evtType == EventType.MouseDown) && r.Contains(evt.mousePosition) && (evt.button == 0)) { var lf = (float)GUIHelpers.MapNormalizedFrequency(lowFreq, samplerate, useLogScale, false) * r.width; var 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) { var blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f; // Mark bands (low, medium and high bands) var lowColor = new Color(0.0f, 0.0f, 0.0f, blend); var midColor = new Color(0.5f, 0.5f, 0.5f, blend); var 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) { var 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); }