Skip to content

Commit 3586b97

Browse files
author
setchi
committed
Speed up the waveform renderer
1 parent c677221 commit 3586b97

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Assets/Scripts/GLDrawing/WaveformRenderer.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void Awake()
2020
.Select(_ => new Line(Vector3.zero, Vector3.zero, color))
2121
.ToArray();
2222

23-
2423
this.LateUpdateAsObservable()
2524
.Where(_ => EditorState.WaveformDisplayEnabled.Value)
2625
.Where(_ => Audio.Source.clip != null)
@@ -32,23 +31,21 @@ void Awake()
3231
var x = (NoteCanvas.Width.Value / Audio.Source.clip.samples) / 2f;
3332
var offsetX = NoteCanvas.OffsetX.Value;
3433
var offsetY = 200;
35-
36-
var min = NoteCanvas.OffsetX.Value;
3734
var max = Screen.width / NoteCanvas.ScaleFactor.Value * 1.3f;
3835

3936
for (int li = 0, wi = skipSamples / 2, l = waveData.Length; wi < l; li++, wi += skipSamples)
4037
{
41-
lines[li].start.x = lines[li].end.x = wi * x + offsetX;
38+
var pos = wi * x + offsetX;
39+
40+
if (pos > max)
41+
break;
42+
43+
lines[li].start.x = lines[li].end.x = pos;
4244
lines[li].end.y = waveData[wi] * 45 - offsetY;
4345
lines[li].start.y = waveData[wi - skipSamples / 2] * 45 - offsetY;
4446
lines[li].start = ConvertUtils.CanvasToScreenPosition(lines[li].start);
4547
lines[li].end = ConvertUtils.CanvasToScreenPosition(lines[li].end);
46-
47-
var posX = lines[li].start.x;
48-
if (min < posX && posX < max)
49-
{
50-
GLLineDrawer.Draw(lines[li]);
51-
}
48+
GLLineDrawer.Draw(lines[li]);
5249
}
5350
});
5451
}

0 commit comments

Comments
 (0)