|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Drawing; |
4 | 4 | using System.Drawing.Imaging; |
| 5 | +using System.Linq; |
5 | 6 | using System.Numerics; |
6 | 7 | using System.Runtime.InteropServices; |
7 | 8 | using System.Threading.Tasks; |
@@ -47,11 +48,14 @@ public override string ToString() |
47 | 48 |
|
48 | 49 | public void SetWindow(double[] newWindow) |
49 | 50 | { |
50 | | - if (newWindow.Length != settings.FftSize) |
51 | | - throw new ArgumentException("window length must equal FFT size"); |
| 51 | + if (newWindow.Length > settings.FftSize) |
| 52 | + throw new ArgumentException("window length cannot exceed FFT size"); |
52 | 53 |
|
53 | 54 | for (int i = 0; i < settings.FftSize; i++) |
54 | | - settings.Window[i] = newWindow[i]; |
| 55 | + settings.Window[i] = 0; |
| 56 | + |
| 57 | + int offset = (settings.FftSize - newWindow.Length) / 2; |
| 58 | + Array.Copy(newWindow, 0, settings.Window, offset, newWindow.Length); |
55 | 59 | } |
56 | 60 |
|
57 | 61 | public void Add(double[] audio) |
@@ -96,8 +100,28 @@ public double[][] Process() |
96 | 100 |
|
97 | 101 | public Bitmap GetBitmap(double multiplier = 1, bool dB = false, bool roll = false) |
98 | 102 | { |
99 | | - if (Width == 0) |
100 | | - return null; |
| 103 | + return _GetBitmap(ffts, multiplier, dB, roll, FftsProcessed); |
| 104 | + } |
| 105 | + |
| 106 | + public Bitmap GetBitmapMax(double multiplier = 1, bool dB = false, bool roll = false, int reduction = 4) |
| 107 | + { |
| 108 | + List<double[]> ffts2 = new List<double[]>(); |
| 109 | + for (int i = 0; i < ffts.Count; i++) |
| 110 | + { |
| 111 | + double[] d1 = ffts[i]; |
| 112 | + double[] d2 = new double[d1.Length / reduction]; |
| 113 | + for (int j = 0; j < d2.Length; j++) |
| 114 | + for (int k = 0; k < reduction; k++) |
| 115 | + d2[j] = Math.Max(d2[j], d1[j * reduction + k]); |
| 116 | + ffts2.Add(d2); |
| 117 | + } |
| 118 | + return _GetBitmap(ffts2, multiplier, dB, roll, FftsProcessed); |
| 119 | + } |
| 120 | + |
| 121 | + private static Bitmap _GetBitmap(List<double[]> ffts, double multiplier = 1, bool dB = false, bool roll = false, int FftsProcessed = 0) |
| 122 | + { |
| 123 | + int Width = ffts.Count; |
| 124 | + int Height = ffts[0].Length; |
101 | 125 |
|
102 | 126 | Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); |
103 | 127 | new Colormaps.Viridis().Apply(bmp); |
|
0 commit comments