public static void Analyze(short[] amplitudes, int samplingRate, out double[] frequencyAmplitudes, out Frequency[] idx2Frequency) { idx2Frequency = Fourier.FrequencyScale(amplitudes.Length, samplingRate).Select(d => new Frequency(d)).ToArray(); var fft = amplitudes.Select(a => new Complex(a, 0)).ToArray(); Fourier.Forward(fft); frequencyAmplitudes = fft.Select(c => Math.Abs(c.Real)).ToArray(); }
public void UpdateSound2ColorMappingLines(List<ISound2ColorMapping> sound2ColorMappings) { ColorMappings.Children.Clear(); foreach (var mapping in sound2ColorMappings) { var pathSegments = new List<PathSegment>(); var firstPoint = new Point(); for (int x = 0; x < 200; x++) { var freq = new Frequency(x * 20); var point = new Point(Frequency2Pixel(freq), -mapping.GetIntensityFromSoundFrequency(freq) * 50); if (x == 0) firstPoint = point; else pathSegments.Add(new LineSegment(point, point.Y < 0)); } PathGeometry pg = new PathGeometry(new[] { new PathFigure(firstPoint, pathSegments, false) }); ColorMappings.Children.Add(new Path() { Data = pg, Stroke = new SolidColorBrush(mapping.Color), StrokeThickness = 2, VerticalAlignment = VerticalAlignment.Bottom }); } }
public override double GetIntensityFromSoundFrequency(Frequency freq) { var val = Math.Max(1 - Math.Abs((freq.Value - SoundFrequencyMidpoint.Value) / SoundFrequencySpanWidth.Value), 0); return val*IntensityMultiplier; }
public abstract double GetIntensityFromSoundFrequency(Frequency freq);
private double Frequency2Pixel(Frequency freq) { return Math.Log(freq.Value+1)*scaling -logAdjust; }