/// /// <summary> * Draw a linear spectrum graph. /// * </summary> /// * <param name="data"> An array of floats defining the signal power /// * at each frequency in the spectrum. </param> /// * <param name="graphics"> Canvas to draw into. </param> /// * <param name="pen"> Graphics to draw with. </param> /// private void logGraph(float[] data, Graphics graphics, Pen pen) { //pen.Style = Graphics.Style.FILL; paintColor[1] = 1f; paintColor[2] = 1f; int len = data.Length; float bw = (float)(spectGraphWidth - 2) / (float)len; float bh = spectGraphHeight - 2; float be = spectGraphY + spectGraphHeight - 1; // Determine the first and last frequencies we have. float leftFrequency = nyquistFreq / len; float rightFrequency = nyquistFreq; // Now, how many octaves is that. Round down. Calculate pixels/oct. int octaves = (int)Math.Floor(log2(rightFrequency / leftFrequency)) - 2; float octWidth = (float)(spectGraphWidth - 2) / (float)octaves; // Calculate the base frequency for the graph, which isn't leftFrequency. float baseFrequency = rightFrequency / (float)Math.Pow(2, octaves); // TODO: Old Java: Element 0 isn't a frequency bucket; skip it. for (int i = 1; i < len; ++i) { // Cycle the hue angle from 0° to 300°; i.e. red to purple. paintColor[0] = (float)i / (float)len * 300f; pen.Color = AColor.HSVToColor(paintColor); // What frequency bucket are we in. float f = leftFrequency * i; // For freq f, calculate x. float x = spectGraphX + (float)(log2(f) - log2(baseFrequency)) * octWidth; // Draw the bar. float y = be - (float)(Math.Log10(data[i]) / RANGE_BELS + 1f) * bh; if (y > be) { y = be; } else if (y < spectGraphY) { y = spectGraphY; } if (bw <= 1.0f) { graphics.DrawLine(pen, x, y, x, be); } else { //graphics.DrawRectangle(pen, x, y, bw, be-y); graphics.FillRectangle(new SolidBrush(pen.Color), x, y, bw, be - y); } } }
/// /// <summary> * Draw a linear spectrum graph. /// * </summary> /// * <param name="data"> An array of floats defining the signal power /// * at each frequency in the spectrum. </param> /// * <param name="graphics"> Canvas to draw into. </param> /// * <param name="pen"> Graphics to draw with. </param> /// private void linearGraph(float[] data, Graphics graphics, Pen pen) { paintColor[1] = 1f; paintColor[2] = 1f; int len = data.Length; float bw = (float)(spectGraphWidth - 2) / (float)len; float bh = spectGraphHeight - 2; float be = spectGraphY + spectGraphHeight - 1; // TODO: Java: Element 0 isn't a frequency bucket; skip it. for (int i = 1; i < len; ++i) { // Cycle the hue angle from 0° to 300°; i.e. red to purple. paintColor[0] = (float)i / (float)len * 300f; pen.Color = AColor.HSVToColor(paintColor); // Draw the bar. float x = spectGraphX + (i * bw + 1); // + (i * bw + 1) float y = be - (float)(Math.Log10(data[i]) / RANGE_BELS + 1f) * bh; if (y > be) { y = be; } else if (y < spectGraphY) { y = spectGraphY; } if (bw <= 1.0f) { graphics.DrawLine(pen, x, y, x, be); } else { // canvas.drawRect(x, y, x + bw, be, paint); // graphics.DrawRectangle(pen, x, y, bw, be-y); graphics.FillRectangle(new SolidBrush(pen.Color), x, y, bw, be - y); } } }