Improved audio graphing

This commit is contained in:
James Ketr 2025-09-13 18:54:56 -07:00
parent eb5416c4f0
commit 1e13a75709

View File

@ -1463,12 +1463,8 @@ class WaveformVideoTrack(MediaStreamTrack):
# Copy the buffer so downstream operations (resizing/bucketing) are safe
arr_segment = arr.copy()
# Normalize segment to -1..1 safely
maxv = float(np.max(np.abs(arr_segment))) if arr_segment.size > 0 else 0.0
if maxv > 0:
norm = arr_segment / maxv
else:
norm = np.zeros_like(arr_segment)
# Assume arr_segment is already in [-1, 1]
norm = arr_segment
# Map audio samples to pixels across the width
if norm.size < self.width:
@ -1490,10 +1486,8 @@ class WaveformVideoTrack(MediaStreamTrack):
points: list[tuple[int, int]] = []
for x in range(self.width):
v = float(norm[x]) if x < norm.size and not np.isnan(norm[x]) else 0.0
y = (
int((1.0 - ((v + 1.0) / 2.0)) * (self.height - 90)) + 80
) # Offset below taller status bar
points.append((x, max(80, min(self.height - 1, y))))
y = int((1.0 - ((v + 1.0) / 2.0)) * self.height)
points.append((x, y))
if len(points) > 1:
pts_np = np.array(points, dtype=np.int32)