Skip to content

Commit

Permalink
Merge pull request #25 from stevehjohn/temp
Browse files Browse the repository at this point in the history
Temp
  • Loading branch information
stevehjohn authored Jul 15, 2024
2 parents fd5bb53 + e6cf297 commit 46a9e89
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/Zen.Desktop.Host/Features/WaveVisualiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class WaveVisualiser

private readonly float[][] _buffers;

private readonly float[] _centreBuffer;

private readonly Texture2D _waves;

private int _bufferPosition;
Expand All @@ -40,6 +42,8 @@ public WaveVisualiser(GraphicsDeviceManager graphicsDeviceManager)
{
_buffers[i] = new float[BufferSize];
}

_centreBuffer = new float[BufferSize];
}

public void ReceiveSignals(float[] signals)
Expand Down Expand Up @@ -102,17 +106,15 @@ private void RenderChannel(int channel)

var axis = channel == 3 ? height * width * channel + height * width / 2 : height * width * (channel + 1) - width;

var buffer = _buffers[channel];

var length = buffer.Length;
CentreChannel(_buffers[channel]);

var lastOffset = 0;

var color = channel == 3 ? Color.Blue : Color.Green;

for (var x = 0; x < width; x++)
{
var dataPoint = buffer[(int) (x * ((float) length / width))];
var dataPoint = _centreBuffer[(int) (x * ((float) BufferSize / width))];

var offset = -(int) (dataPoint * height * (channel == 3 ? 1 : 4));

Expand All @@ -131,4 +133,28 @@ private void RenderChannel(int channel)
lastOffset = offset;
}
}

private void CentreChannel(float[] buffer)
{
var max = float.MinValue;

var maxPos = int.MinValue;

for (var i = 0; i < BufferSize; i++)
{
if (buffer[i] > max)
{
max = buffer[i];

maxPos = i;
}
}

var startPos = BufferSize / 2 + maxPos;

for (var i = 0; i < BufferSize; i++)
{
_centreBuffer[i] = buffer[(startPos + i) % BufferSize];
}
}
}

0 comments on commit 46a9e89

Please sign in to comment.