infinity-player

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

commit
39654f695db4ab1e5bc460d6b9ece71827742da1
parent
11d632c98bc86f41a54985fd0436d04874155b16
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-03-06 10:39
refactor iter_beat_slices

Diffstat

M player.py 9 ++++-----

1 files changed, 4 insertions, 5 deletions


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

@@ -42,10 +42,9 @@ def enhance_diagonals(jumps, weight=0.2, steps=1):
   42    42     return jumps
   43    43 
   44    44 
   45    -1 def iter_beat_slices(y, beat_frames):
   -1    45 def iter_beat_slices(beat_frames):
   46    46     beat_samples = librosa.frames_to_samples(beat_frames)
   47    -1     beat_samples = [0, *beat_samples, len(y) - 1]
   48    -1     yield from zip(beat_samples[0:-1], beat_samples[1:])
   -1    47     yield from zip([0, *beat_samples], [*beat_samples, None])
   49    48 
   50    49 
   51    50 def timbre(y):
@@ -72,7 +71,7 @@ def analyze(y, sample_rate, beat_frames, bins_per_octave=12, n_octaves=7):
   72    71     # return (R_cqt + R_timbre) / 2
   73    72 
   74    73     tim = numpy.array([
   75    -1         timbre(y[start:end]) for start, end in iter_beat_slices(y, beat_frames)
   -1    74         timbre(y[start:end]) for start, end in iter_beat_slices(beat_frames)
   76    75     ]).T
   77    76     return librosa.segment.recurrence_matrix(tim, width=4, mode='affinity')
   78    77 
@@ -101,7 +100,7 @@ def compute_buffers(y, beat_frames):
  101   100     raw = (y * int_max).astype(numpy.int16).T.copy(order='C')
  102   101 
  103   102     buffers = []
  104    -1     for start, end in iter_beat_slices(raw, beat_frames):
   -1   103     for start, end in iter_beat_slices(beat_frames):
  105   104         buffers.append(y.T[start:end])
  106   105 
  107   106     return buffers