Open
Conversation
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
…ith cython 0.17.4
$ 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
Author
|
Ping. Any comments or suggestions for inclusion in the master branch? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.