infinity-player

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

commit
bf17f428b3ec1b1e81d398ab1e55b37444befcca
parent
edbc50214ea72c2869010d5c16c6b141615b72cc
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-03-06 13:40
consider number of plays in probabilities

Diffstat

M README.md 7 ++-----
M player.py 12 ++++++++----

2 files changed, 10 insertions, 9 deletions


diff --git a/README.md b/README.md

@@ -22,11 +22,8 @@ Any help would be appreciated
   22    22     *Constant-Q chromagram* is. The current implementation works ok-ish, but
   23    23     there can probably be big improvements.
   24    24 
   25    -1 -   **Improve beat selection.** Currently the selection of the next beat
   26    -1     depends only on the current beat and a set of precomputed probabilities.
   27    -1     Jumps that go back or wide are slightly privileged. I guess a lot more is
   28    -1     possible, e.g. to prevent the song from looping through the same part again
   29    -1     and again.
   -1    25 -   **Improve beat selection.** I guess a lot more is possible, e.g. to prevent
   -1    26     the song from looping through the same part again and again.
   30    27 
   31    28 ## Prior Art
   32    29 

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

@@ -103,23 +103,27 @@ def enhance(jumps, threshold):
  103   103     return jumps
  104   104 
  105   105 
  106    -1 def get_next_position(i, jumps):
  107    -1     choices, weights = zip(*enumerate(jumps[i]))
  108    -1     j = random.choices(choices, weights)
   -1   106 def get_next_position(i, jumps, counts):
   -1   107     n = len(jumps)
   -1   108     j = numpy.array(range(n))
   -1   109     w_count = (numpy.cumsum(counts[::-1] * (j + 1)) / numpy.cumsum(j + 1))[::-1]
   -1   110     j = random.choices(range(n), jumps[i] / (w_count + 1))
  109   111     return j[0] + 1
  110   112 
  111   113 
  112   114 def play(buffers, sample_rate, jumps):
  113   115     i = 0
  114   116     n = len(buffers)
   -1   117     counts = numpy.zeros(n)
  115   118 
  116   119     with soundcard.default_speaker().player(samplerate=sample_rate) as sp:
  117   120         try:
  118   121             while True:
  119   122                 sp.play(buffers[i])
   -1   123                 counts[i] += 1
  120   124                 print_progress(i, n)
  121   125 
  122    -1                 i = get_next_position(i, jumps)
   -1   126                 i = get_next_position(i, jumps, counts)
  123   127                 if i >= n:
  124   128                     i = 0
  125   129         except KeyboardInterrupt: