예제 #1
0
        private void UpdateTimePlot()
        {
            var millis = Utils.Linspace(0, preset.ImpulseLengthTransformed / (double)preset.SamplerateTransformed * 1000, preset.ImpulseLengthTransformed).ToArray();

            // left and right
            var pm = new PlotModel();

            var line = pm.AddLine(millis, millis.Select(x => 0.0));

            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(millis, outputIr[0].Select(x => (double)x));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromAColor(127, OxyColors.Blue);

            line = pm.AddLine(millis, outputIr[1].Select(x => (double)x));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromAColor(127, OxyColors.Red);

            if (switchGraphs)
            {
                plotImpulseOutputBottom = pm;
            }
            else
            {
                plotImpulseOutputTop = pm;
            }

            NotifyPropertyChanged(nameof(PlotTop));
            NotifyPropertyChanged(nameof(PlotBottom));
        }
예제 #2
0
        private void UpdateEqPlot()
        {
            var pm = new PlotModel();

            pm.Axes.Add(new LogarithmicAxis {
                Position = AxisPosition.Bottom, Minimum = 20
            });
            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Key = "LeftAxis", Minimum = -20, Maximum = 20
            });

            var eqProc = new EqProcessor(mixingConfig, Samplerate);
            var resp   = eqProc.GetFrequencyResponse();

            var line = pm.AddLine(resp, x => 0.0, x => x.Key);

            line.Color           = OxyColor.FromAColor(64, OxyColors.Black);
            line.StrokeThickness = 1.0;

            line                 = pm.AddLine(resp, x => AudioLib.Utils.Gain2DB(x.Value), x => x.Key);
            line.Color           = OxyColors.Blue;
            line.StrokeThickness = 1.0;

            plot1 = pm;
        }
예제 #3
0
 public static void AddLine <T>(
     this PlotModel model,
     IEnumerable <T> data,
     Func <T, double> ySelector,
     Func <T, DateTime> xSelector,
     LineStyle lineStyle = null)
 {
     model.AddLine(data, ySelector, x => OxyPlot.Axes.DateTimeAxis.ToDouble(xSelector(x)), lineStyle);
 }
예제 #4
0
        public void TestMethodSlop()
        {
            var data   = new double[48000];
            var dataF  = new double[48000];
            var random = new Random(0);

            double sum    = 0.0;
            double filter = 0.0;
            var    fs     = 4800;
            Func <double, double> fcToAlpha = fc => (2 * Math.PI * fc / fs) / (2 * Math.PI * fc / fs + 1);
            var freq            = 1.0;
            var samplesPerPoint = (int)(fs / (freq * 10));

            var aHp = fcToAlpha(freq * 0.5);
            var aLp = fcToAlpha(freq * 0.2);

            var scale  = 1.0 / samplesPerPoint;
            var sample = 0.0;
            var n      = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (n <= 0)
                {
                    sample = (2 * random.NextDouble() - 1) * scale;
                    n      = samplesPerPoint;
                }

                sum     += sample;
                filter   = filter * (1 - aLp) + aLp * sum;
                data[i]  = sum;
                dataF[i] = filter;
                sum     *= (1 - aHp);

                n--;
            }

            var pm = new PlotModel();

            pm.AddLine(data);
            pm.AddLine(dataF);
            pm.Show();
        }
예제 #5
0
        public void TestMethod1()
        {
            var t    = new PolyhedrusNative(48000, 12003, 12004);
            var data = t.GetWavetable(0);

            var pm = new PlotModel();

            pm.AddLine(data.WavetableData.Take(20000));
            pm.Show();
        }
예제 #6
0
        private void UpdateFftPlot()
        {
            var magDataLeft  = fftLeft.Take(fftLeft.Length / 2).Select(x => x.Abs).Select(x => Utils.Gain2DB(x)).ToArray();
            var magDataRight = fftRight.Take(fftRight.Length / 2).Select(x => x.Abs).Select(x => Utils.Gain2DB(x)).ToArray();
            var hz           = Utils.Linspace(0, 0.5, magDataLeft.Length).Select(x => x * (double)preset.SamplerateTransformed).ToArray();

            var pm = new PlotModel();

            pm.Axes.Add(new LogarithmicAxis {
                Position = AxisPosition.Bottom, Minimum = 20
            });
            var leftAxis = new LinearAxis {
                Position = AxisPosition.Left, Key = "LeftAxis", Minimum = -80
            };

            //var rightAxis = new LinearAxis { Position = AxisPosition.Right, Key = "RightAxis", Minimum = -Math.PI - 0.1, Maximum = Math.PI + 0.1 };
            pm.Axes.Add(leftAxis);
            //pm.Axes.Add(rightAxis);

            var line = pm.AddLine(hz, hz.Select(x => 0.0));

            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 20.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 40.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 60.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, magDataLeft);
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromAColor(127, OxyColors.Blue);
            line.YAxisKey        = "LeftAxis";

            line = pm.AddLine(hz, magDataRight);
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromAColor(127, OxyColors.Red);
            line.YAxisKey        = "LeftAxis";

            if (switchGraphs)
            {
                plotImpulseOutputTop = pm;
            }
            else
            {
                plotImpulseOutputBottom = pm;
            }

            NotifyPropertyChanged(nameof(PlotTop));
            NotifyPropertyChanged(nameof(PlotBottom));
        }
        private PlotModel PlotFft()
        {
            var data      = PlottedFftSignal;
            var magData   = data.Take(data.Length / 2).Select(x => x.Abs).Select(x => Utils.Gain2DB(x)).ToArray();
            var phaseData = data.Take(data.Length / 2).Select(x => x.Arg).ToArray();
            //phaseData = AudioLib.Utils.UnrollPhase(phaseData);
            var hz = Utils.Linspace(0, 0.5, magData.Length).Select(x => x * (double)Samplerate).ToArray();

            var pm = new PlotModel();

            pm.Axes.Add(new LogarithmicAxis {
                Position = AxisPosition.Bottom, Minimum = 20
            });
            var leftAxis = new LinearAxis {
                Position = AxisPosition.Left, Key = "LeftAxis", Minimum = -80, Maximum = magData.Max() + 6
            };
            var rightAxis = new LinearAxis {
                Position = AxisPosition.Right, Key = "RightAxis", Minimum = -Math.PI - 0.1, Maximum = Math.PI + 0.1
            };

            pm.Axes.Add(leftAxis);
            pm.Axes.Add(rightAxis);

            var line = pm.AddLine(hz, hz.Select(x => 0.0));

            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 20.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 40.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, hz.Select(x => - 60.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            line = pm.AddLine(hz, phaseData);
            line.StrokeThickness = 1.0;
            line.Color           = OxyColors.LightGreen;
            line.YAxisKey        = "RightAxis";

            line = pm.AddLine(hz, magData);
            line.StrokeThickness = 1.0;
            line.Color           = OxyColors.DarkBlue;
            line.YAxisKey        = "LeftAxis";

            return(pm);
        }
예제 #8
0
        public void Run()
        {
            /*var pm = new PlotModel();
             * var xs = Enumerable.Range(0, 1000).Select(x => x / 1000.0).Select(x => -100 + x * 100).ToArray();
             * var ys1 = xs.Select(x => Compress(x, ThresholdDb, UpperSlope, 3, true)).ToArray();
             * var ys2 = xs.Select(x => Compress(x, ThresholdDb + 6, LowerSlope, 3, true)).ToArray();
             *
             * pm.AddLine(xs, ys1);
             * pm.AddLine(xs, ys2);
             * pm.Show();
             */
            var pm = new PlotModel();

            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Key = "L"
            });
            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Right, Key = "R"
            });

            var follower    = new EnvelopeFollower(48000, 20);
            var expander    = new Expander();
            var slewLimiter = new SlewLimiter(48000);

            follower.SetRelease(ReleaseMs);
            slewLimiter.UpdateDb60(2.0, ReleaseMs);
            expander.Update(ThresholdDb, ReductionDb, UpperSlope);
            var signalValues   = new List <double>();
            var followerValues = new List <double>();
            var gainValues     = new List <double>();

            var           rand   = new Random();
            Func <double> random = () => 2 * rand.NextDouble() - 1;
            double        decay  = 1.0;

            for (int i = 0; i < 20000; i++)
            {
                var x = (Math.Sin(i / fs * 2 * Math.PI * 300) + random() * 0.4) * decay;
                decay *= 0.9998;
                if (i < 1000)
                {
                    x = random() * 0.001;
                }
                else if (i > 12000)
                {
                    x = random() * 0.001;
                }

                signalValues.Add(x);
                follower.ProcessEnvelope(x);
                var env = follower.GetOutput();
                followerValues.Add(env);

                expander.Expand(Utils.Gain2Db(env));
                var gainDb = expander.GetOutput();
                gainDb = slewLimiter.Process(gainDb);
                var gain = Utils.Db2Gain(gainDb);
                gainValues.Add(gain);
            }

            var signalLine = pm.AddLine(signalValues);

            signalLine.Title    = "Signal";
            signalLine.YAxisKey = "R";
            //pm.AddLine(followerValues.Select(Utils.Gain2Db)).Title = "followerValues";
            pm.AddLine(gainValues.Select(Utils.Gain2Db)).Title = "gainValues";

            pm.Show();
        }
        private PlotModel PlotReal()
        {
            var sampleCount  = 8192;
            var time         = sampleCount / (double)Samplerate * 1000;
            var plottedIr    = PlottedImpulseSignal.Take(sampleCount).ToArray();
            var plottedLeft  = ImpulseLeft.Take(sampleCount).ToArray();
            var plottedRight = ImpulseRight.Take(sampleCount).ToArray();
            var millis       = Utils.Linspace(0, time, plottedIr.Length).ToArray();
            var pm           = new PlotModel();

            // end of sample marker
            var millisLine = ImpulseLength / (double)Samplerate * 1000;
            var line       = pm.AddLine(new[] { millisLine - 0.0001, millisLine + 0.0001 }, new[] { -1000.0, 1000.0 });

            line.StrokeThickness = 2.0;
            line.Color           = OxyColor.FromArgb(50, 255, 0, 0);

            // zero line
            line = pm.AddLine(millis, millis.Select(x => 0.0));
            line.StrokeThickness = 1.0;
            line.Color           = OxyColor.FromArgb(50, 0, 0, 0);

            // sample data
            if (plotImpulseBase)
            {
                line = pm.AddLine(millis, plottedIr);
                line.StrokeThickness = 1.0;
                line.Color           = OxyColors.Black;
            }

            // left IR
            if (PlotImpulseLeft)
            {
                line = pm.AddLine(millis, plottedLeft);
                line.StrokeThickness = 1.0;
                line.Color           = OxyColors.Blue;
            }

            // Right IR
            if (plotImpulseRight)
            {
                line = pm.AddLine(millis, plottedRight);
                line.StrokeThickness = 1.0;
                line.Color           = OxyColors.Red;
            }

            var axis = new LinearAxis {
                Position = AxisPosition.Left
            };

            axis.Minimum = -1.05;
            axis.Maximum = 1.05;
            pm.Axes.Add(axis);

            axis = new LinearAxis {
                Position = AxisPosition.Bottom
            };
            axis.Minimum = -0.5;
            axis.Maximum = millisLine * 1.1;
            pm.Axes.Add(axis);

            return(pm);
        }
예제 #10
0
        private void UpdateStereoEnhancerPlot()
        {
            var pm = new PlotModel();

            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Left, Key = "LeftAxis", Minimum = -26, Maximum = 12
            });
            pm.Axes.Add(new LinearAxis {
                Position = AxisPosition.Right, Key = "RightAxis", Minimum = 0, Maximum = 3.0
            });

            pm.Axes.Add(new CategoryAxis
            {
                Position    = AxisPosition.Bottom,
                Key         = "HzAxis",
                ItemsSource = mixingConfig.Frequencies,
                Minimum     = -0.6,
                Maximum     = mixingConfig.StereoEq.Length - 0.4,
                GapWidth    = 0
            });

            pm.Axes.Add(new CategoryAxis
            {
                Position    = AxisPosition.Bottom,
                Key         = "BlankAxis",
                ItemsSource = mixingConfig.Frequencies.Select(_ => ""),
                Minimum     = -0.6,
                Maximum     = mixingConfig.StereoEq.Length - 0.4,
                GapWidth    = 0
            });

            var line = pm.AddLine(new[] { -1.0, 16.0 }, new[] { 0.0, 0.0 });

            line.Color           = OxyColor.FromAColor(128, OxyColors.Black);
            line.StrokeThickness = 1.0;
            line.YAxisKey        = "LeftAxis";

            var eqSeries = new ColumnSeries();

            eqSeries.Items.AddRange(mixingConfig.StereoEq.Select((x, i) => new ColumnItem
            {
                Value         = (2 * x - 1) * mixingConfig.EqDepthDbTransformed,
                CategoryIndex = i
            })
                                    .ToArray());
            eqSeries.ColumnWidth       = 1.0;
            eqSeries.LabelMargin       = 0;
            eqSeries.NegativeFillColor = OxyColor.FromAColor(127, OxyColors.Red);
            eqSeries.FillColor         = OxyColor.FromAColor(127, OxyColors.Blue);
            eqSeries.YAxisKey          = "LeftAxis";
            eqSeries.XAxisKey          = "HzAxis";
            pm.Series.Add(eqSeries);


            var phaseSeries = new ColumnSeries();

            phaseSeries.Items.AddRange(mixingConfig.StereoPhase.Select((x, i) => new ColumnItem
            {
                Value         = Math.Abs(2 * x - 1),
                Color         = x < 0.5 ? OxyColor.FromAColor(127, OxyColors.Blue) : OxyColor.FromAColor(127, OxyColors.Red),
                CategoryIndex = i
            }).ToArray());
            phaseSeries.ColumnWidth = 1.0;
            phaseSeries.LabelMargin = 0;
            phaseSeries.YAxisKey    = "RightAxis";
            eqSeries.XAxisKey       = "BlankAxis";
            pm.Series.Add(phaseSeries);



            plot1 = pm;
        }