Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer handling #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

kevmitch
Copy link

There was a similar problem for reading. The buffer was allocated as "np.int" which prevented me from reading 32-bit integer data. I've changed it to explicitly allocate a np.int32 buffer instead which appears to do the right thing.

Matthias Lichter and others added 7 commits May 19, 2013 01:52
when trying to write integer data with audiolabs write_frames() method.

Problem: When trying to write integer data to a soundfile on a 64bit
machine the written data gets truncated in odd ways if it is stored in
an np.array of dtype np.int, because libsndfile expects 32bit integer data
but np.int is 64bit wide on that machine.
Storing the data as np.int32 doesn't help either, because np.int32 != np.int
on 64bit and audiolab refuses to accept it that way.

Fix: Explicitly adding np.int32 as accepted dtype for libsndfiles write_frames_int()
function allows to write int32 data. Additionally handling of np.int64 is done by
shifting the data 32 bits to the right and converting it to np.int32 on the fly.
This way it gets truncated in the way described in audiolabs and libsndfiles
documentation which says that truncation is done so that MSB always stays MSB.
As far as I have tried the dtype comparison of input data given as np.int yields
True for np.int32 or np.int64 depending on the actual width of np.int.
This is also true for the comparison of np.short with np.int16, so I changed that too.

Additionally: To regenerate _sndfile.c from _sndfile.pyx with cython 0.17.4 I had to
change "cimport stdlib" to "cimport libc.stdlib" and replace calls to stdlib.strlen()
with pythons builtin len() which according to http://wiki.cython.org/FAQ seems to be
the way to do that since cython 0.12.1
$ cython _sndfile.pyx
$ cython -V
Cython version 0.19.1
… This seemed to be causing some weird transposition of the data.
cython -V 0.19.1
@kevmitch
Copy link
Author

Ping. Any comments or suggestions for inclusion in the master branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant