Mark Heath avatar Mark Heath committed 4be4bfa

choice of bezier or linear

Comments (0)

Files changed (2)

WpfWaveform/MainWindow.xaml.cs

         {
             var generator = new WaveFormPointsGenerator();
             var peaks = generator.GetPeaks(@"E:\Audio\Music\Coldplay\X&Y\04-Fix You.mp3", 200);
-            var points = generator.GetPoints(peaks.Select(p => p.LeftMax), 0, 2, 150, -150).ToArray();
-            var geometry = generator.GetBezierPathGeometry(points);
-            Path path = new Path() { Stroke = Brushes.Red, StrokeThickness = 1, Data = geometry, Fill=Brushes.Beige };
-            canvas.Children.Add(path);
+
+            canvas.Children.Add(generator.GetBezierPath(peaks.Select(p => p.LeftMax), 0, 2, 110, -100, Brushes.Brown, Brushes.Beige));
+            canvas.Children.Add(generator.GetBezierPath(peaks.Select(p => p.LeftMin), 0, 2, 110, -100, Brushes.Brown, Brushes.Beige));
         }
 
-        /*
-         * canvas.Children.Clear();
-
-            Point[] points = curve();
-            if (points.Length < 2)
-                return;
-
-            // Get Bezier Spline Control Points.
-            Point[] cp1, cp2;
-            ovp.BezierSpline.GetCurveControlPoints(points, out cp1, out cp2);
-
-            // Draw curve by Bezier.
-            PathSegmentCollection lines = new PathSegmentCollection();
-            for (int i = 0; i < cp1.Length; ++i)
-            {
-                lines.Add(new BezierSegment(cp1[i], cp2[i], points[i + 1], true));
-            }
-            PathFigure f = new PathFigure(points[0], lines, false);
-            PathGeometry g = new PathGeometry(new PathFigure[] { f });
-            Path path = new Path() { Stroke = Brushes.Red, StrokeThickness = 1, Data = g, Fill=Brushes.Beige };
-            canvas.Children.Add(path);
-         */
     }
 }

WpfWaveform/WaveFormPointsGenerator.cs

 using NAudio.Wave;
 using System.Windows;
 using System.Windows.Media;
+using System.Windows.Shapes;
 
 namespace WpfWaveform
 {
             return peaks;
         }
 
-        public IEnumerable<Point> GetPoints(IEnumerable<double> magnitude, double xOffset, double xStep, double yOffset, double yMult)
+        public Path GetBezierPath(IEnumerable<double> magnitude, double xOffset, double xStep, double yOffset, double yMult, Brush stroke, Brush fill)
+        {
+            var points = GetPoints(magnitude, 0, 2, 110, -100).ToArray();
+            var geometry = GetBezierPathGeometry(points);
+            var path = new Path() { Stroke = stroke, StrokeThickness = 1, Data = geometry, Fill = fill };
+            return path;
+        }
+
+        public Path GetLinearPath(IEnumerable<double> magnitude, double xOffset, double xStep, double yOffset, double yMult, Brush stroke, Brush fill)
+        {
+            var points = GetPoints(magnitude, 0, 2, 110, -100).ToArray();
+            var geometry = GetLinearPathGeometry(points);
+            var path = new Path() { Stroke = stroke, StrokeThickness = 1, Data = geometry, Fill = fill };
+            return path;
+        }
+
+        private IEnumerable<Point> GetPoints(IEnumerable<double> magnitude, double xOffset, double xStep, double yOffset, double yMult)
         {
             List<Point> points = new List<Point>();
             foreach (var m in magnitude)
             return points;
         }
 
-        public PathGeometry GetBezierPathGeometry(Point[] points)
+        private PathGeometry GetBezierPathGeometry(Point[] points)
         {
             // Get Bezier Spline Control Points.
             Point[] cp1, cp2;
             PathGeometry g = new PathGeometry(new PathFigure[] { f });
             return g;
         }
+
+        private PathGeometry GetLinearPathGeometry(Point[] points)
+        {
+            // Draw curve by Bezier.
+            PathSegmentCollection lines = new PathSegmentCollection();
+            lines.Add(new PolyLineSegment(points, true));
+            PathFigure f = new PathFigure(points[0], lines, false);
+            PathGeometry g = new PathGeometry(new PathFigure[] { f });
+            return g;
+        }
     }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.