private void DrawCurve( Rect r, float[] curve, float yscale, Color col, // ReSharper disable once UnusedParameter.Local float labeloffset, float wetLevel, float gain) { float xscale = curve.Length - 2; var maxval = 0.0f; for (var n = 0; n < curve.Length; n++) { maxval = Mathf.Max(maxval, Mathf.Abs(curve[n])); } yscale *= maxval > 0.0f ? gain / maxval : 0.0f; AudioCurveRendering.DrawSymmetricFilledCurve( r, delegate(float x, out Color color) { var f = Mathf.Clamp(x * xscale, 0.0f, xscale); var i = (int)Mathf.Floor(f); color = new Color(col.r, col.g, col.b, col.a * wetLevel); return((curve[i] + ((curve[i + 1] - curve[i]) * (f - i))) * yscale); } ); }
private void DrawCurve(Rect r, float[] curve, float yscale, Color c0, Color c1, Color c2, Color c3, float labeloffset, float rofs, float ofs, float wlen, float rwlen, float shape) { float xscale = curve.Length - 2; float maxval = 0.0f; for (int n = 0; n < curve.Length; n++) { maxval = Mathf.Max(maxval, Mathf.Abs(curve[n])); } yscale *= (maxval > 0.0f) ? (1.0f / maxval) : 0.0f; float transition = 0.5f * (wlen + rwlen) / shape, mix = 0.7f; float transitionScale = (transition > 0.0f) ? (1.0f / transition) : 0.0f; AudioCurveRendering.DrawSymmetricFilledCurve( r, delegate(float x, out Color color) { color = c0; float f = Mathf.Clamp(x * xscale, 0.0f, xscale); int i = (int)Mathf.Floor(f); float y = (curve[i] + (curve[i + 1] - curve[i]) * (f - i)) * yscale; x -= ofs; if (x >= -rofs) { if (x < 0.0f) { color = Color.Lerp(color, c3, mix); } if (x + rofs < transition) { y *= (x + rofs) * transitionScale; } else if (x < wlen + rwlen && x > wlen + rwlen - transition) { y *= (wlen + rwlen - x) * transitionScale; } if (x < wlen) { color = Color.Lerp(color, c1, mix); } else if (x < wlen + rwlen) { color = Color.Lerp(color, c2, mix); } else { color.a *= 0.4f; } } else { color.a *= 0.4f; } return(y); } ); }
private void DrawCurve(Rect r, float[] curve, float yscale, Color col, float labeloffset, float wetLevel, float gain) { float xscale = curve.Length - 2; float maxval = 0.0f; for (int n = 0; n < curve.Length; n++) { maxval = Mathf.Max(maxval, Mathf.Abs(curve[n])); } yscale *= (maxval > 0.0f) ? (gain / maxval) : 0.0f; AudioCurveRendering.DrawSymmetricFilledCurve( r, delegate(float x, out Color color) { float f = Mathf.Clamp(x * xscale, 0.0f, xscale); int i = (int)Mathf.Floor(f); color = new Color(col.r, col.g, col.b, col.a * wetLevel); return((curve[i] + (curve[i + 1] - curve[i]) * (f - i)) * yscale); } ); }
private void DrawCurve(Rect r, Func <float, int> toIndex) { AudioCurveRendering.DrawSymmetricFilledCurve( r, (float t, out Color col) => { col = Orange; int i = toIndex(t) / downSampleTo; return(i >= downSampledData.Length ? 0 : downSampledData[i]); } ); AudioCurveRendering.DrawSymmetricFilledCurve( r, (float t, out Color col) => { col = MidYellow; int i = toIndex(t); return(i >= sampleData.Length ? 0 : sampleData[i]); } ); }
static void DoRenderPreview(AudioClip clip, Rect rect) { var samples = new float[clip.samples]; clip.GetData(samples, 0); AudioCurveRendering.AudioCurveAndColorEvaluator dlg = delegate(float x, out Color color) { color = curveColor; if (clip.samples <= 0) { return(0); } var p = Mathf.FloorToInt(Mathf.Clamp(x * (clip.samples - 1), 0.0f, clip.samples - 1)); return(samples[p]); }; rect = AudioCurveRendering.BeginCurveFrame(rect); AudioCurveRendering.DrawSymmetricFilledCurve(rect, dlg); AudioCurveRendering.EndCurveFrame(); }
private void DrawCurve( Rect r, float[] curve, float yscale, Color c0, Color c1, Color c2, Color c3, // ReSharper disable once UnusedParameter.Local float labeloffset, float rofs, float ofs, float wlen, float rwlen, float shape) { float xscale = curve.Length - 2; var maxval = 0.0f; for (var n = 0; n < curve.Length; n++) { maxval = Mathf.Max(maxval, Mathf.Abs(curve[n])); } yscale *= maxval > 0.0f ? 1.0f / maxval : 0.0f; float transition = (0.5f * (wlen + rwlen)) / shape, mix = 0.7f; var transitionScale = transition > 0.0f ? 1.0f / transition : 0.0f; AudioCurveRendering.DrawSymmetricFilledCurve( r, delegate(float x, out Color color) { color = c0; var f = Mathf.Clamp(x * xscale, 0.0f, xscale); var i = (int)Mathf.Floor(f); var y = (curve[i] + ((curve[i + 1] - curve[i]) * (f - i))) * yscale; x -= ofs; if (x >= -rofs) { if (x < 0.0f) { color = Color.Lerp(color, c3, mix); } if ((x + rofs) < transition) { y *= (x + rofs) * transitionScale; } else if ((x < (wlen + rwlen)) && (x > ((wlen + rwlen) - transition))) { y *= ((wlen + rwlen) - x) * transitionScale; } if (x < wlen) { color = Color.Lerp(color, c1, mix); } else if (x < (wlen + rwlen)) { color = Color.Lerp(color, c2, mix); } else { color.a *= 0.4f; } } else { color.a *= 0.4f; } return(y); } ); }