danilobellini / audiolazy

Expressive Digital Signal Processing (DSP) package for Python
GNU General Public License v3.0
689 stars 74 forks source link

Issue with STFT overlap_add: ValueError: need at least one array to concatenate #10

Open sevagh opened 3 years ago

sevagh commented 3 years ago

Hello,

I tried both the robotize and roll magnitude examples and experienced the same error. From robotize:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/home/sevagh/.local/lib/python3.8/site-packages/audiolazy/lazy_io.py", line 414, in run
    for chunk in chunks(self.audio,
  File "/home/sevagh/.local/lib/python3.8/site-packages/audiolazy/lazy_io.py", line 89, in chunks
    for block in blocks(seq, size, padval=padval):
  File "/home/sevagh/.local/lib/python3.8/site-packages/audiolazy/lazy_misc.py", line 99, in blocks
    for el in seq:
  File "/home/sevagh/.local/lib/python3.8/site-packages/audiolazy/lazy_analysis.py", line 790, in overlap_add
    gain = np.sum(np.abs(np.vstack(steps)), 0).max()
  File "<__array_function__ internals>", line 5, in vstack
  File "/home/sevagh/.local/lib/python3.8/site-packages/numpy/core/shape_base.py", line 283, in vstack
    return _nx.concatenate(arrs, 0)
  File "<__array_function__ internals>", line 5, in concatenate
ValueError: need at least one array to concatenate

The stacktrace shows Python 3.8, so I downgraded to 3.6 and get the same error.

Thanks.

sevagh commented 3 years ago

Perhaps something changed in numpy since the last time the code was written?

sevagh commented 3 years ago

https://github.com/danilobellini/audiolazy/blob/master/audiolazy/lazy_analysis.py#L789 If I add .take() here, the array passed to numpy is correct and the thing works:

# Normalization to the [-1; 1] range
if normalize:
  steps = Stream(wnd).blocks(hop).map(np.array).take()
  #print(steps)
  gain = np.sum(np.abs(np.vstack(steps)), 0).max()
  if gain: # If gain is zero, normalization couldn't have any effect
    wnd = wnd / gain # Can't use "/=" nor "*=" as Numpy would keep datatype