Open
Conversation
added 3 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
…ith cython 0.17.4
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.
Hi David,
let me first thank you thanks for your nice work! Your audiolab module has proven quite useful for me in trying out some dsp related stuff in python.
While trying to generate some bit exact testdata I ran into problems with saving this data via audiolab on my 64bit machine. The problem seems to be that audiolab assumes np.int == np.int32 in the write_frames() method which isn't true on my 64bits installation of python.
I looked into the code and found a solution which works for me and should solve that problem. I'd be happy if you could take a look on this pull request and tell me if you see any problems with the changes I made.
Cheers,
Matthias