...
 
Commits (4)
......@@ -128,6 +128,14 @@ Please see the developer documentation
Changes
-------
Version_1.4.3 (2020-01-20)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- changed sndio functions to all use PySndfile as context manager. This
fixes the problem that the sndfile remains open when an error occurs
which may in turn lead to inconsistencies if the sndfile is tried to
be rewritten in an exception handler.
Version_1.4.2 (2019-12-18)
~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -78,6 +78,12 @@ Please see the developer documentation [here](https://pysndfile.readthedocs.io/e
## Changes
### Version_1.4.3 (2020-01-20)
* changed sndio functions to all use PySndfile as context manager. This fixes the problem that the sndfile
remains open when an error occurs which may in turn lead to inconsistencies if the sndfile is tried to be rewritten
in an exception handler.
### Version_1.4.2 (2019-12-18)
* fixed PySndfile.read_frames method to properly handle reading frames in parts (previous fix was incomplete)
......
11243 a4ec0b48c0c848bb860b9d869625fe911b0323e39b13c0cbb2942e71237edf6d
11532 fb9c6e00c3c545f2f72e1179a6c64d66d1b639a3f2123f90a6b22c4c6ec0f6c1
......@@ -35,7 +35,7 @@ from libcpp.string cimport string
cdef extern from "Python.h":
ctypedef int Py_intptr_t
_pysndfile_version=(1, 4, 2)
_pysndfile_version=(1, 4, 3)
def get_pysndfile_version():
"""
return tuple describing the version of pysndfile
......
Changes
-------
Version_1.4.3 (2020-01-20)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- changed sndio functions to all use PySndfile as context manager. This
fixes the problem that the sndfile remains open when an error occurs
which may in turn lead to inconsistencies if the sndfile is tried to
be rewritten in an exception handler.
Version_1.4.2 (2019-12-18)
~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -49,10 +49,10 @@ def get_info(name, extended_info=False) :
in case extended_info is True a 5-tuple comprising additionally the number of frames and the number of channels
is returned.
"""
sf = PySndfile(name)
if extended_info:
return sf.samplerate(), sf.encoding_str(), sf.major_format_str(), sf.frames(), sf.channels()
return sf.samplerate(), sf.encoding_str(), sf.major_format_str()
with PySndfile(name) as sf:
if extended_info:
return sf.samplerate(), sf.encoding_str(), sf.major_format_str(), sf.frames(), sf.channels()
return sf.samplerate(), sf.encoding_str(), sf.major_format_str()
def get_markers(name) :
"""
......@@ -66,8 +66,9 @@ def get_markers(name) :
Note: following the implementation of libsndfile marker labels will be empty strings for all but aiff files.
"""
sf = PySndfile(name)
return sf.get_cue_mrks()
with PySndfile(name) as sf:
return sf.get_cue_mrks()
def write(name, data, rate=44100, format="aiff", enc='pcm16', sf_strings=None) :
......@@ -105,17 +106,18 @@ def write(name, data, rate=44100, format="aiff", enc='pcm16', sf_strings=None) :
elif nchans != 1:
raise RuntimeError("error:sndio.write:can only be called with vectors or matrices ")
sf = PySndfile(name, "w",
with PySndfile(name, "w",
format=construct_format(format, enc),
channels = nchans, samplerate = rate)
channels = nchans, samplerate = rate) as sf:
if sf_strings is not None:
sf.set_strings(sf_strings)
nf = sf.write_frames(data)
if sf_strings is not None:
sf.set_strings(sf_strings)
nf = sf.write_frames(data)
if nf != data.shape[0]:
raise IOError("sndio.write::error::writing of samples failed")
return nf
if nf != data.shape[0]:
raise IOError("sndio.write::error::writing of samples failed")
return nf
enc_norm_map = {
"pcm8" : np.float64(2**7),
......@@ -159,29 +161,22 @@ def read(name, end=None, start=0, dtype=np.float64, return_format=False,
format of the sound file (can be used to recreate a sound file with an identical format).
:rtype: Union[Tuple(numpy.array, int, str),Tuple(numpy.array, int, str, str)]
"""
sf = PySndfile(name)
enc = sf.encoding_str()
nf = sf.seek(start, 0)
if not nf == start:
raise IOError("sndio.read::error:: while seeking at starting position")
with PySndfile(name) as sf:
enc = sf.encoding_str()
nf = sf.seek(start, 0)
if not nf == start:
raise IOError("sndio.read::error:: while seeking at starting position")
if end == None:
ff = sf.read_frames(sf.frames() - start, dtype=dtype, force_2d=force_2d)
else:
ff = sf.read_frames(end-start, dtype=dtype, force_2d=force_2d)
if isinstance(sf_strings, dict):
sf_strings.clear()
sf_strings.update(sf.get_strings())
# if norm and (enc not in ["float32" , "float64"]) :
# if enc in enc_norm_map :
# ff = ff / enc_norm_map[sf.encoding_str()]
# else :
# raise IOError("sndio.read::error::normalization of compressed pcm data is not supported")
if return_format:
return ff, sf.samplerate(), enc, sf.major_format_str()
return ff, sf.samplerate(), enc
if end == None:
ff = sf.read_frames(sf.frames() - start, dtype=dtype, force_2d=force_2d)
else:
ff = sf.read_frames(end-start, dtype=dtype, force_2d=force_2d)
if isinstance(sf_strings, dict):
sf_strings.clear()
sf_strings.update(sf.get_strings())
if return_format:
return ff, sf.samplerate(), enc, sf.major_format_str()
return ff, sf.samplerate(), enc
......@@ -70,7 +70,7 @@ elif np.any (ff2 != bfc):
print("bfc", bfc)
write_error = True
else:
print("no errors detected for io with difernt sample encodings")
print("no errors detected for io with different sample encodings")
# check reading part of file
ss,_,_ = pysndfile.sndio.read(os.path.join(mydir,'test.wav'), force_2d=True)
......