mirror of
https://github.com/kennethreitz/interpretations.git
synced 2026-06-05 14:50:20 +00:00
play.py: spectrum peak hold with slow decay
Peaks hold and decay by 1 level per frame (~40fps = smooth falloff). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -263,6 +263,7 @@ def play_audio(buf, sample_rate, title="", info_lines=None, offset_sec=0.0):
|
||||
big_seek = int(30 * sample_rate)
|
||||
|
||||
state = {"pos": 0, "playing": True, "quit": False, "action": None}
|
||||
prev_heights = [0] * 48 # peak hold for spectrum
|
||||
lock = threading.Lock()
|
||||
|
||||
def callback(outdata, frames, time_info, status):
|
||||
@@ -357,7 +358,13 @@ def play_audio(buf, sample_rate, title="", info_lines=None, offset_sec=0.0):
|
||||
peak = max(bands) if max(bands) > 0 else 1
|
||||
# Multi-row spectrum: map each band to 0..n_rows*4 height
|
||||
max_h = n_rows * 4
|
||||
heights = [min(max_h, int(b / peak * max_h)) for b in bands]
|
||||
raw_heights = [min(max_h, int(b / peak * max_h)) for b in bands]
|
||||
# Peak hold with decay
|
||||
heights = []
|
||||
for j, h in enumerate(raw_heights):
|
||||
held = max(h, prev_heights[j] - 1) # decay by 1 per frame
|
||||
heights.append(held)
|
||||
prev_heights[j] = held
|
||||
|
||||
# Build rows top to bottom
|
||||
rows = []
|
||||
|
||||
Reference in New Issue
Block a user