...
 
Commits (4)
......@@ -128,6 +128,14 @@ Please see the developer documentation
Changes
-------
Version_1.4.1 (2019-12-18)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- extended supported commands to change compression level when writing
flac and ogg files
- fixed PySndfile.read_frames method to preoperly handle reading all
remaining frames in case some frames have already been read
Version_1.4.0 (2019-12-17)
~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -78,6 +78,11 @@ Please see the developer documentation [here](https://pysndfile.readthedocs.io/e
## Changes
### Version_1.4.1 (2019-12-18)
* extended supported commands to change compression level when writing flac and ogg files
* fixed PySndfile.read_frames and sndio.read method to properly handle reading frames from the middle of a file
### Version_1.4.0 (2019-12-17)
* Extended PySndfile class:
......
10859 4963342efebf2a826788cb4017f40fba7099acc7988f29eabde4036131a684d9
11117 10fc52b1b3e51dc148cbbb17742b752908db84a0359d8cf1b16c71d6292e03af
......@@ -35,7 +35,7 @@ from libcpp.string cimport string
cdef extern from "Python.h":
ctypedef int Py_intptr_t
_pysndfile_version=(1, 4, 0)
_pysndfile_version=(1, 4, 1)
def get_pysndfile_version():
"""
return tuple describing the version of pysndfile
......@@ -243,6 +243,14 @@ cdef extern from "pysndfile.hh":
cdef int C_SFC_GET_BROADCAST_INFO "SFC_GET_BROADCAST_INFO"
cdef int C_SFC_SET_BROADCAST_INFO "SFC_SET_BROADCAST_INFO"
cdef int C_SFC_WAVEX_SET_AMBISONIC "SFC_WAVEX_SET_AMBISONIC"
cdef int C_SFC_WAVEX_GET_AMBISONIC "SFC_WAVEX_GET_AMBISONIC"
cdef int C_SFC_RF64_AUTO_DOWNGRADE "SFC_RF64_AUTO_DOWNGRADE"
cdef int C_SFC_SET_VBR_ENCODING_QUALITY "SFC_SET_VBR_ENCODING_QUALITY"
cdef int C_SFC_SET_COMPRESSION_LEVEL "SFC_SET_COMPRESSION_LEVEL"
cdef int C_SF_STR_TITLE "SF_STR_TITLE"
cdef int C_SF_STR_COPYRIGHT "SF_STR_COPYRIGHT"
cdef int C_SF_STR_SOFTWARE "SF_STR_SOFTWARE"
......@@ -441,10 +449,17 @@ _commands_to_id_tuple = (
("SFC_GET_INSTRUMENT" , C_SFC_GET_INSTRUMENT),
("SFC_SET_INSTRUMENT" , C_SFC_SET_INSTRUMENT),
("SFC_GET_LOOP_INFO" , C_SFC_GET_LOOP_INFO),
("SFC_GET_LOOP_INFO", C_SFC_GET_LOOP_INFO),
("SFC_GET_BROADCAST_INFO" , C_SFC_GET_BROADCAST_INFO),
("SFC_SET_BROADCAST_INFO" , C_SFC_SET_BROADCAST_INFO),
("SFC_GET_BROADCAST_INFO", C_SFC_GET_BROADCAST_INFO),
("SFC_SET_BROADCAST_INFO", C_SFC_SET_BROADCAST_INFO),
("SFC_WAVEX_SET_AMBISONIC", C_SFC_WAVEX_SET_AMBISONIC),
("SFC_WAVEX_GET_AMBISONIC", C_SFC_WAVEX_GET_AMBISONIC),
("SFC_RF64_AUTO_DOWNGRADE", C_SFC_RF64_AUTO_DOWNGRADE),
("SFC_SET_VBR_ENCODING_QUALITY", C_SFC_SET_VBR_ENCODING_QUALITY),
("SFC_SET_COMPRESSION_LEVEL", C_SFC_SET_COMPRESSION_LEVEL),
)
......@@ -843,6 +858,8 @@ cdef class PySndfile:
raise RuntimeError("PySndfile::error::no valid soundfilehandle")
if nframes < 0 :
whence = C_SEEK_CUR | C_SFM_READ
pos = self.thisPtr.seek(0, whence)
nframes = self.thisPtr.frames()
if dtype == np.float64:
y = self.read_frames_double(nframes, fill_value=fill_value, min_read=min_read)
......
Changes
-------
Version_1.4.1 (2019-12-18)
~~~~~~~~~~~~~~~~~~~~~~~~~~
- extended supported commands to change compression level when writing
flac and ogg files
- fixed PySndfile.read_frames method to preoperly handle reading all
remaining frames in case some frames have already been read
Version_1.4.0 (2019-12-17)
~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -30,8 +30,9 @@ The module contains 3 functions.
# along with pysndfile. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import absolute_import
from pysndfile import PySndfile, construct_format, stringtype_name_to_id, max_supported_string_length, fileformat_name_to_id, fileformat_id_to_name
from ._pysndfile import PySndfile, construct_format, stringtype_name_to_id, max_supported_string_length, fileformat_name_to_id, fileformat_id_to_name
import numpy as np
def get_info(name, extended_info=False) :
......@@ -124,7 +125,7 @@ enc_norm_map = {
}
def read(name, end=None, start=0, dtype=np.float64, return_format=False,
sf_strings=None, force_2d=False) :
sf_strings=None, force_2d=False):
"""
read samples from arbitrary sound files into a numpy array.
May return subsets of samples as specified by start and end arguments (Def all samples)
......@@ -166,7 +167,7 @@ def read(name, end=None, start=0, dtype=np.float64, return_format=False,
raise IOError("sndio.read::error:: while seeking at starting position")
if end == None:
ff = sf.read_frames(dtype=dtype, force_2d=force_2d)
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)
......
from __future__ import print_function
import numpy as np
import os
import sys
import numpy as np
from pysndfile_inst_dir.pysndfile import get_sndfile_version
from pysndfile_inst_dir.pysndfile import *
import pysndfile_inst_dir.pysndfile as pysndfile
mydir = os.path.dirname(__file__)
print("pysndfile version:",get_pysndfile_version())
......@@ -36,6 +38,7 @@ for d in [np.float64, np.float32, np.int32, np.short]:
b = PySndfile(os.path.join(mydir,'test{0}.wav'.format(str(d).split("'")[1])), "w", a.format(), a.channels(), a.samplerate())
print(b)
b.write_frames(ff)
b.close()
del b
ff=a.read_frames(dtype=np.float64)
......@@ -54,13 +57,58 @@ bff=b.read_frames()
with PySndfile(os.path.join(mydir,'test_2cC.wav')) as b:
bfc=b.read_frames()
read_error= False
write_error =False
if np.any (ff2 != bff):
print('error in test_2cF.wav')
print("ff2", ff2)
print("bff", bff)
write_error = True
elif np.any (ff2 != bfc):
print('error in test_2cC.wav')
print("ff2", ff2)
print("bfc", bfc)
write_error = True
else:
print("no erors detected for io with difernt sample encodings")
# check reading part of file
ss,_,_ = pysndfile.sndio.read(os.path.join(mydir,'test.wav'), force_2d=True)
ssstart,_,_ = pysndfile.sndio.read(os.path.join(mydir,'test.wav'), end=100, force_2d=True)
ssend,_,_ = pysndfile.sndio.read(os.path.join(mydir,'test.wav'), start=100, force_2d=True)
if np.any(ss != np.concatenate((ssstart, ssend), axis=0)):
read_error = True
print("error reading file segments")
# check writing flac
if "flac" in majors:
print('test writing flac')
ss, sr, enc = pysndfile.sndio.read(os.path.join(mydir,'test.wav'), force_2d=True)
flac_file = PySndfile(os.path.join(mydir,'test.flac'), "w", construct_format("flac", "pcm16"), ss.shape[1], sr)
flac_file.command("SFC_SET_COMPRESSION_LEVEL", 1.)
flac_file.write_frames(ss)
flac_file.close()
ss_flac, sr_flac, enc_flac = pysndfile.sndio.read(os.path.join(mydir,'test.flac'), force_2d=True)
if sr != sr_flac:
print('error::flac writing sample rate')
write_error = True
if enc != enc_flac:
print('error::flac writing enc')
write_error = True
if np.any (ss != ss_flac):
print('error in test_2cF.wav')
write_error = True
else:
print('your libsndfile version does not support flac format, skip flac writing test')
if write_error or read_error:
if write_error:
print("write errors encountered")
if read_error:
print("read errors encountered")
sys.exit(1)
else:
print("all seems ok")
sys.exit(0)