Skip to content

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

Open
@mgeier

Description

@mgeier

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions