Commit bbe58100 authored by Axel Roebel's avatar Axel Roebel
Browse files

pysndfile 1.3.4 preview

- first version of win32 implementation
- changed to use expanduser
parent 910565fa
PYTHON=python
python_version_full := $(wordlist 2,4,$(subst ., ,$(shell ${PYTHON} --version 2>&1)))
python_version_major := $(word 1,${python_version_full})
CYTHON=cython
PIP=pip
all: build
build : cythonize Makefile setup.py
python setup.py build_ext
$(PYTHON) setup.py build_ext
cythonize : _pysndfile.cpp
_pysndfile.cpp: _pysndfile.pyx pysndfile.hh
cython --cplus $<
$(CYTHON) -${python_version_major} --cplus $<
install:
pip install .
$(PIP) install .
install-user:
pip install . --user
$(PIP) install . --user
clean:
python setup.py clean -a
$(PYTHON) setup.py clean -a
sdist:
python setup.py sdist
$(PYTHON) setup.py sdist
@echo now do
@echo twine upload -r test dist/pysndfile-1.3.2.tar.gz
@echo for testing and
......
......@@ -31,7 +31,22 @@ import os
cimport numpy as cnp
from libcpp.string cimport string
_pysndfile_version=(1,3,3)
IF UNAME_SYSNAME == "Windows":
from libc.stddef cimport wchar_t
cdef extern from "Windows.h":
ctypedef const wchar_t *LPCWSTR
cdef extern from "Python.h":
wchar_t* PyUnicode_AsWideCharString(object, Py_ssize_t *)
void PyMem_Free(void *p)
cdef extern from *:
"""
#define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
"""
_pysndfile_version=(1,3,4)
def get_pysndfile_version():
"""
return tuple describing the version opf pysndfile
......@@ -57,7 +72,6 @@ cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(cnp.ndarray arr, int flags)
cdef extern from "pysndfile.hh":
cdef struct SF_FORMAT_INFO:
int format
char *name
......@@ -89,35 +103,9 @@ cdef extern from "pysndfile.hh":
unsigned int cue_count
SF_CUE_POINT cue_points[100]
ctypedef SF_FORMAT_INFO SF_FORMAT_INFO
cdef int sf_command(SNDFILE *sndfile, int command, void *data, int datasize)
cdef int sf_format_check (const SF_INFO *info)
cdef char *sf_error_number(int errnum)
cdef cppclass SndfileHandle :
SndfileHandle(const char *path, int mode, int format, int channels, int samplerate)
SndfileHandle(const int fh, int close_desc, int mode, int format, int channels, int samplerate)
sf_count_t frames()
int format()
int channels()
int samplerate()
int seekable()
int error()
char* strError()
int command (int cmd, void *data, int datasize)
int get_cue_count()
sf_count_t seek (sf_count_t frames, int whence)
void writeSync ()
sf_count_t readf (short *ptr, sf_count_t items)
sf_count_t readf (int *ptr, sf_count_t items)
sf_count_t readf (float *ptr, sf_count_t items)
sf_count_t readf (double *ptr, sf_count_t items)
sf_count_t writef (const short *ptr, sf_count_t items)
sf_count_t writef (const int *ptr, sf_count_t items)
sf_count_t writef (const float *ptr, sf_count_t items)
sf_count_t writef (const double *ptr, sf_count_t items)
SNDFILE* rawHandle()
int setString (int str_type, const char* str)
const char* getString (int str_type)
cdef int C_SF_FORMAT_WAV "SF_FORMAT_WAV" # /* Microsoft WAV format (little endian default). */
cdef int C_SF_FORMAT_AIFF "SF_FORMAT_AIFF" # /* Apple/SGI AIFF format (big endian). */
......@@ -272,6 +260,10 @@ cdef extern from "pysndfile.hh":
cdef int C_SF_COUNT_MAX "SF_COUNT_MAX"
IF UNAME_SYSNAME == "Linux":
include "sndfile_linux.pxi"
IF UNAME_SYSNAME == "Windows":
include "sndfile_win32.pxi"
# these two come with more recent versions of libsndfile
# to not break compilation they are defined outside sndfile.h
......@@ -636,6 +628,11 @@ cdef class PySndfile:
cdef int sfmode
cdef const char*cfilename
cdef int fh
IF UNAME_SYSNAME == "Windows":
cdef Py_ssize_t length
cdef wchar_t *my_wchars
# -1 will indicate that the file has been open from filename, not from
# file descriptor
self.fd = -1
......@@ -665,11 +662,25 @@ cdef class PySndfile:
self.filename = b""
self.fd = filename
else:
if len(filename)> 2 and filename[0] == "~" and filename[1] == "/":
filename = os.path.join(os.environ['HOME'], filename[2:])
filename = os.path.expanduser(filename)
IF UNAME_SYSNAME == "Windows":
# Need to get the wchars before filename is converted to utf-8
my_wchars = PyUnicode_AsWideCharString(filename, &length)
if isinstance(filename, unicode):
filename = bytes(filename, "UTF-8")
self.filename = filename
IF UNAME_SYSNAME == "Windows":
if length > 0:
self.thisPtr = new SndfileHandle(my_wchars, sfmode, format, channels, samplerate)
PyMem_Free(my_wchars)
else:
raise RuntimeError("PySndfile::error while converting {0} into wchars".format(filename))
ELSE:
self.thisPtr = new SndfileHandle(self.bfilename.c_str(), sfmode, format, channels, samplerate)
self.thisPtr = new SndfileHandle(self.filename.c_str(), sfmode, format, channels, samplerate)
if self.thisPtr == NULL or self.thisPtr.rawHandle() == NULL:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment