Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible off-by-one bug in number of output samples #3

Open
kylebgorman opened this issue Dec 25, 2013 · 0 comments
Open

Possible off-by-one bug in number of output samples #3

kylebgorman opened this issue Dec 25, 2013 · 0 comments

Comments

@kylebgorman
Copy link

Thanks for scikits.samplerate: it looks like a great package. I am, however, surprised at the number of samples I get from calling resample on a mono signal: it is always exactly one less than my expectations. I wanted to confirm this was the correct behavior and not a bug before I go on using the package "in production". Here’s a worked example that shows what I mean:

from __future__ import division
from math import trunc
from numpy.random import uniform
from scikits.samplerate import resample

L = 10000
SR_in = 44100
SR_out = 16000

signal_in = uniform(size=L)
signal_out = resample(L, SR_in / SR_out, 'sinc_best')
expected_length = trunc(L * SR_in / SR_out)
print expected_length - 1 = len(signal_out) # prints “True"

I took a look at scikits.samplerate-0.3.3/scikits/samplerate/_samplerate.pyx. If I understand correctly, on line 173

osz = (r * nframes - 1)

sets the output length. That explains why the resampled audio is the length it is (original length times ratio, minus 1, truncated towards zero because of the cast to a long integer), but why is 1 being subtracted here?

It’s quite possible there’s a legitimate signal processing reason for this. But if so, what is the actual samplerate of signal_out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant