bmcfee / pyrubberband

python wrapper for rubberband
ISC License
154 stars 20 forks source link

long window mode for signals with sr <= 210Hz #14

Open markostam opened 6 years ago

markostam commented 6 years ago

Pyrubberband will hang when faced with low-sr signals unless the --window-long flag is set. This PR adds that flag for signals below 210Hz and allows the process to complete.

bmcfee commented 6 years ago

Interesting -- looks like the tests are bombing out though. Any idea what's up with that?

BTW, @jongwook, is this also an issue in your fork?

jongwook commented 6 years ago

I am traveling, but let me try in the next 24 hours or so. I never knew that there can be WAV files with <210Hz sample rate..

markostam commented 6 years ago

I took a quick look at test_pitch and it seems like signals under a certain sample rate start losing samples compared to the original. The rate under which samples start getting chopped seems to be 1524, at least for the length of signal I quickly looked at. For example:

sr=1523; num_samples=3000; freq=500; n_step=0.5
y = synth(sr, num_samples, freq)
y_s = pyrubberband.pitch_shift(y, sr, n_step)
len(y_s)

returns 2998. But if you change sr=1524 and redo the above steps, len(y_s) returns 3000 as expected...

bmcfee commented 6 years ago

The rate under which samples start getting chopped seems to be 1524, at least for the length of signal I quickly looked at. For example:

This is starting to sound like something amiss in rubberband itself, and not pyrb?

markostam commented 6 years ago

I'd agree with that assessment.

Does anyone know what rubberband is using under the hood? Some PSOLA variant or a phase vocoder?

bmcfee commented 6 years ago

It's open-source: https://bitbucket.org/breakfastquay/rubberband/ but the documentation/comments are a bit thin. I don't have the bandwidth to pick it apart right now.

markostam commented 6 years ago

I should probably also add a link the issue this PR was meant to address https://github.com/bmcfee/pyrubberband/issues/13

jongwook commented 6 years ago

It hangs with the Cython version as well,

In [1]: import pyrubberband.rubberband as pyrb

In [2]: import numpy as np

In [3]: a=np.random.randn(10000)

In [4]: a
Out[4]:
array([ 0.31215944,  0.40128545, -1.52564994, ...,  1.40697364,
        1.81780644,  1.3080728 ])

In [5]: pyrb.pitch_shift(a, 200, 1, ['--debug', '3'])
RubberBandStretcher::Impl::Impl: rate = 200, options = 8208
configure: effective ratio = 1.05946
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 4096
Window area: 0.5; synthesis window area: 0.5
FFT::FFT(8): using implementation: vdsp
Resampler::Resampler: using Speex implementation with q = 4
Not real time mode: prefilling
configure: effective ratio = 1.05946
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 4096
Not real time mode: prefilling
configure: effective ratio = 1.05946
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 4096

I am also seeing that pyrb.pitch_shift(a, 200, 1, ['--window-long']) fixes the problem