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

read(): Strange behavior if frames, out, and fill_value are given? #210

Open
mgeier opened this issue Oct 14, 2017 · 2 comments
Open

read(): Strange behavior if frames, out, and fill_value are given? #210

mgeier opened this issue Oct 14, 2017 · 2 comments

Comments

@mgeier
Copy link
Contributor

mgeier commented Oct 14, 2017

This behavior seems strange to me:

>>> import soundfile as sf
>>> import numpy as np
>>> out = np.zeros(9, dtype='int16')
>>> sf.read('tests/mono.wav', frames=7, out=out, fill_value=99)
(array([ 0,  1,  2, -2, -1, 99, 99, 99, 99], dtype=int16), 44100)

I'd expect that a view into out with 7 elements would be returned, i.e.

(array([ 0,  1,  2, -2, -1, 99, 99], dtype=int16), 44100)

I think it is strange that frames is only ignored if out and fill_value are given, but it is not ignored if only out is given:

>>> sf.read('tests/mono.wav', frames=3, out=out, fill_value=99)
(array([ 0,  1,  2, 99, 99, 99, 99, 99, 99], dtype=int16), 44100)
>>> sf.read('tests/mono.wav', frames=3, out=out)
(array([0, 1, 2], dtype=int16), 44100)

I think that if specified by the user, frames should never be ignored. I'd expect this behavior:

>>> sf.read('tests/mono.wav', frames=3, out=out, fill_value=99)
(array([0, 1, 2], dtype=int16), 44100)
>>> sf.read('tests/mono.wav', frames=3, out=out)
(array([0, 1, 2], dtype=int16), 44100)

Is anybody with me on that?
Or am I missing something?

@bastibe
Copy link
Owner

bastibe commented Oct 16, 2017

I agree!

mgeier added a commit to mgeier/python-soundfile that referenced this issue Nov 14, 2017
Partial solution to bastibe#210, but this breaks blocks()!

The tests can be run without testing blocks():

    python3 -m pytest -k"not blocks"
@mgeier
Copy link
Contributor Author

mgeier commented Nov 14, 2017

I've started to address this in #214, but there is still some work to be done ...

mgeier added a commit to mgeier/python-soundfile that referenced this issue Nov 14, 2017
Partial solution to bastibe#210, but this breaks blocks()!

The tests can be run without testing blocks():

    python3 -m pytest -k"not blocks"
mgeier added a commit to mgeier/python-soundfile that referenced this issue Nov 14, 2017
Partial solution to bastibe#210, but this breaks blocks()!

The tests can be run without testing blocks():

    python3 -m pytest -k"not blocks"
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

2 participants