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)
                );
        }
Ejemplo n.º 2
0
    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 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);
        }
    }
Ejemplo n.º 4
0
        public void Update(Rect rect, Color color, System.Func <float, float> Evaluate)
        {
            waveformStartTime = EditorGUILayout.Slider("Start", waveformStartTime, 0, duration);
            waveformLength    = EditorGUILayout.Slider("Period", waveformLength, 0, duration);
            waveformStartTime = Mathf.Min(duration - waveformLength, waveformStartTime);
            Rect r = AudioCurveRendering.BeginCurveFrame(rect);

            AudioCurveRendering.DrawCurve(r, (t) => Evaluate(waveformStartTime + (t * waveformLength)), color);
            AudioCurveRendering.EndCurveFrame();
        }
    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));
    }
Ejemplo n.º 6
0
        protected override void OnDataDetailGUI()
        {
            InitAudioSource();

            DropDownField("Output Target", ref _selectedItem.LegacySound.OutputTarget, SoundOutTypeStrings, SoundOutTypeValues);
            SliderField("Volume", ref _selectedItem.LegacySound.Volume, -100, 100);
            SliderField("Balance", ref _selectedItem.LegacySound.Balance, -100, 100);
            SliderField("Fade (Rear->Front)", ref _selectedItem.LegacySound.Fade, -100, 100);

            EditorGUILayout.Space();
            var wfx = _selectedItem.LegacySound.Wfx;

            if (_selectedItem.LegacySound.AudioClip != null)
            {
                GUILayout.Label($"Length : {_selectedItem.LegacySound.AudioClip.length} s,  Channels : {wfx.Channels}, BPS : {wfx.BitsPerSample}, Freq : {wfx.SamplesPerSec}");

                if (GUILayout.Button(new GUIContent()
                {
                    image = EditorGUIUtility.IconContent("PlayButton").image
                }))
                {
                    _audioSource.transform.position = _selectedSoundPos;
                    _audioSourceComp.volume         = (_selectedItem.LegacySound.Volume + 100) / 200.0f;
                    _audioSourceComp.panStereo      = _selectedItem.LegacySound.Balance / 100.0f;
                    _audioSourceComp.clip           = _selectedItem.LegacySound.AudioClip;
                    _audioSourceComp.Play();
                }

                EditorGUILayout.Space();
                Rect curveRect = GUILayoutUtility.GetLastRect();
                curveRect.x     += 10.0f;
                curveRect.y     += curveRect.height;
                curveRect.width -= 20.0f;
                curveRect.height = 100.0f;
                Rect r = AudioCurveRendering.BeginCurveFrame(curveRect);
                AudioCurveRendering.DrawCurve(r, x => _audioSamples[(int)((_audioSamples.Length - 1) * x + 0.5f)], Color.green);
                AudioCurveRendering.EndCurveFrame();
            }
            else
            {
                _selectedItem.LegacySound.AudioClip = (AudioClip)EditorGUILayout.ObjectField(_selectedItem.LegacySound.AudioClip, typeof(AudioClip), false);
            }
        }
        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, int channel)
    {
        r = AudioCurveRendering.BeginCurveFrame(r);

        if (Event.current.type == EventType.Repaint)
        {
            float blend = plugin.IsPluginEditableAndEnabled() ? 1.0f : 0.5f;

            float window, scale, mode;
            plugin.GetFloatParameter("Window", out window);
            plugin.GetFloatParameter("Scale", out scale);
            plugin.GetFloatParameter("Mode", out mode);

            float[] buffer;
            int     numsamples = (mode >= 1.0f) ? maxspeclen : (int)(window * samplerate);
            plugin.GetFloatBuffer("Channel" + channel.ToString(), out buffer, numsamples);
            numsamples = buffer.Length;

            if (mode < 2.0f)
            {
                Color lineColor = new Color(1.0f, 0.5f, 0.2f, blend);
                if (mode >= 1.0f)
                {
                    scale *= 0.1f;
                    AudioCurveRendering.DrawFilledCurve(r, delegate(float x)
                    {
                        float f  = Mathf.Clamp(x * (numsamples - 2) * window * 0.5f, 0, numsamples - 2);
                        int i    = (int)Mathf.Floor(f);
                        float s1 = 20.0f * Mathf.Log10(buffer[i] + 0.0001f);
                        float s2 = 20.0f * Mathf.Log10(buffer[i + 1] + 0.0001f);
                        return((s1 + (s2 - s1) * (f - i)) * scale);
                    }, lineColor);
                    GUIHelpers.DrawFrequencyTickMarks(r, samplerate * window * 0.5f, false, Color.red);
                    GUIHelpers.DrawDbTickMarks(r, 1.0f / scale, scale, Color.red, new Color(1.0f, 0.0f, 0.0f, 0.25f));
                }
                else
                {
                    AudioCurveRendering.DrawCurve(r, delegate(float x) { return(scale * buffer[(int)Mathf.Floor(x * (numsamples - 2))]); }, lineColor);
                    GUIHelpers.DrawTimeTickMarks(r, window, Color.red, new Color(1.0f, 0.0f, 0.0f, 0.25f));
                }
            }
            else
            {
                scale *= 0.1f;

                for (int i = 0; i < maxspeclen; i++)
                {
                    float v = 20.0f * Mathf.Log10(buffer[i] + 0.0001f) * scale;
                    spec[i] = new Color(
                        Mathf.Clamp(v * 4.0f - 1.0f, 0.0f, 1.0f),
                        Mathf.Clamp(v * 4.0f - 2.0f, 0.0f, 1.0f),
                        1.0f - Mathf.Clamp(Mathf.Abs(v * 4.0f - 1.0f), 0.0f, 1.0f) * Mathf.Clamp(4.0f - 4.0f * v, 0.0f, 1.0f),
                        1.0f);
                }

                if (spectex[channel] == null)
                {
                    spectex[channel] = new Texture2D(maxspeclen, scopeheight);
                }

                specpos[channel] = (specpos[channel] + 1) % scopeheight;
                spectex[channel].SetPixels(0, specpos[channel], maxspeclen, 1, spec);
                spectex[channel].Apply();

                Color oldColor = GUI.color;
                GUI.color = new Color(1.0f, 1.0f, 1.0f, blend);

                Rect r2 = new Rect(r.x, r.y + specpos[channel], r.width / (window * 0.5f), scopeheight);
                GUI.DrawTexture(r2, spectex[channel], ScaleMode.StretchToFill, false, 1.0f);

                r2.y -= scopeheight;
                GUI.DrawTexture(r2, spectex[channel], ScaleMode.StretchToFill, false, 1.0f);

                GUI.color = oldColor;

                GUIHelpers.DrawFrequencyTickMarks(r, samplerate * window * 0.5f, false, Color.red);
            }
        }
        AudioCurveRendering.EndCurveFrame();
        return(false);
    }