From 00e3ddabbfc79a59adc543ca6a28d008671d7325 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Fri, 9 Jan 2015 13:41:28 +0100 Subject: [PATCH] Reset SoundFile.frames to 0 in SFM_WRITE mode See #68. --- pysoundfile.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pysoundfile.py b/pysoundfile.py index 6912a84..b2fd47a 100644 --- a/pysoundfile.py +++ b/pysoundfile.py @@ -673,6 +673,13 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, # truncate the file, because SFM_RDWR doesn't: _os.close(_os.open(file, _os.O_WRONLY | _os.O_TRUNC)) self._file = _snd.sf_open(file.encode(), mode_int, self._info) + if mode_int == _snd.SFM_WRITE: + # Due to a bug in libsndfile version <= 1.0.25, frames != 0 + # when opening a named pipe in SFM_WRITE mode. + # See http://github.com/erikd/libsndfile/issues/77. + self._info.frames = 0 + # This is not necessary for "normal" files (because + # frames == 0 in this case), but it doesn't hurt, either. elif isinstance(file, int): self._file = _snd.sf_open_fd(file, mode_int, self._info, closefd) elif all(hasattr(file, a) for a in ('seek', 'read', 'write', 'tell')):