infinity-player

infinite jukebox clone using librosa
git clone https://git.ce9e.org/infinity-player.git

commit
25052ebf06da4ed8ca4b8ef17d2d06688cd29ad7
parent
587c39cf80b69da0c4d0957bf73d3b1f8ce7f842
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-07-28 11:35
refactor: use beat_samples instead of beat_frames

Diffstat

M player.py 15 ++++++++-------

1 files changed, 8 insertions, 7 deletions


diff --git a/player.py b/player.py

@@ -34,8 +34,7 @@ def print_progress(i, n):
   34    34     print(s, end='\r')
   35    35 
   36    36 
   37    -1 def compute_buffers(y, beat_frames):
   38    -1     beat_samples = librosa.frames_to_samples(beat_frames)
   -1    37 def compute_buffers(y, beat_samples):
   39    38     ranges = zip([0, *beat_samples], [*beat_samples, None])
   40    39     return [y.T[start:end] for start, end in ranges]
   41    40 
@@ -68,18 +67,20 @@ def load(filename, *, force=False):
   68    67     path_inf = Path(filename + '.inf')
   69    68     if not force and path_inf.exists():
   70    69         with gzip.open(path_inf, 'rb') as fh:
   71    -1             beat_frames, jumps = pickle.load(fh)
   -1    70             beat_samples, jumps = pickle.load(fh)
   72    71     else:
   73    72         print('Analyzing…')
   74    73         y_mono, _ = librosa.load(filename, sr=sample_rate)
   75    -1         tempo, beat_frames = librosa.beat.beat_track(y=y_mono, sr=sample_rate)
   76    -1         buffers_mono = compute_buffers(y_mono, beat_frames)
   -1    74         tempo, beat_samples = librosa.beat.beat_track(
   -1    75             y=y_mono, sr=sample_rate, units='samples'
   -1    76         )
   -1    77         buffers_mono = compute_buffers(y_mono, beat_samples)
   77    78         jumps = analyze(buffers_mono)
   78    79 
   79    80         with gzip.open(path_inf, 'wb') as fh:
   80    -1             pickle.dump((beat_frames, jumps), fh)
   -1    81             pickle.dump((beat_samples, jumps), fh)
   81    82 
   82    -1     return compute_buffers(y, beat_frames), sample_rate, jumps
   -1    83     return compute_buffers(y, beat_samples), sample_rate, jumps
   83    84 
   84    85 
   85    86 def enhance(jumps, threshold):