feat: pixel<->time geometry helpers for the waveform
This commit is contained in:
@@ -5,6 +5,20 @@ import numpy as np
|
||||
from core.paths import _bin
|
||||
|
||||
|
||||
def x_to_t(x: float, width: float, view_start: float, view_dur: float) -> float:
|
||||
"""Map a pixel x in [0,width] to a time in [view_start, view_start+view_dur]."""
|
||||
if width <= 0 or view_dur <= 0:
|
||||
return view_start
|
||||
return view_start + (x / width) * view_dur
|
||||
|
||||
|
||||
def t_to_x(t: float, width: float, view_start: float, view_dur: float) -> int:
|
||||
"""Map a time to a pixel x in [0,width] (rounded)."""
|
||||
if width <= 0 or view_dur <= 0:
|
||||
return 0
|
||||
return int(round((t - view_start) / view_dur * width))
|
||||
|
||||
|
||||
def peaks(samples, buckets: int = 128) -> list[float]:
|
||||
"""Reduce a 1-D sample array to *buckets* normalized peak magnitudes (0..1)."""
|
||||
if samples is None or len(samples) == 0:
|
||||
|
||||
Reference in New Issue
Block a user