python-soundfile icon indicating copy to clipboard operation
python-soundfile copied to clipboard

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

Open mgeier opened this issue 8 years ago • 2 comments
trafficstars

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?

mgeier avatar Oct 14 '17 12:10 mgeier

I agree!

bastibe avatar Oct 16 '17 07:10 bastibe

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

mgeier avatar Nov 14 '17 20:11 mgeier