Example #1
0
 public static async Task<WaveFile> Create(StorageFile file)
 {
     WaveFile w = new WaveFile();
     await w.Initialize(file);
     w.SmoothSamples(200);
     return w;
 }
Example #2
0
        public async Task<bool> DrawWaveform(Canvas canvas)
        {
            if (this.WaveFile == null)
            {
                this.WaveFile = await WaveFile.Create(AudioFile);
            }

            double W = canvas.ActualWidth;
            double H = canvas.ActualHeight;

            double y_c = H / 2.0;

            canvas.Children.Clear();
            double dseconds = (1.0 / 16000.0);
            double dpixels = PixelsPerSecond * dseconds;
            canvas.Width = this.WaveFile.SmoothedSamples.Count * dpixels;


            Path path = new Path();
            path.Stroke = new SolidColorBrush(Windows.UI.Colors.DeepSkyBlue);
            path.StrokeThickness = 2.0;
            GeometryGroup geomGroup = new GeometryGroup();

            for (int i = 0; i < Samples.Count; ++i)
            {
                double f = Samples[i];

                Point a = new Point((i * dpixels) + 0.5, y_c - f * y_c);
                Point b = new Point((i * dpixels) + 0.5, y_c + f * y_c);

                LineGeometry line = new LineGeometry();
                line.StartPoint = a;
                line.EndPoint = b;
                geomGroup.Children.Add(line);
            }

            path.Data = geomGroup;
            canvas.Children.Add(path);

            return true;
        }