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

Interleaving bug #3

Open
cournape opened this issue Aug 12, 2010 · 3 comments · May be fixed by #20
Open

Interleaving bug #3

cournape opened this issue Aug 12, 2010 · 3 comments · May be fixed by #20

Comments

@cournape
Copy link
Owner

From Dr. Gabriël J.L. Beckers

"""
If you read a stereo file with "f.read_frames(f.nframes)", then the samples of each channel are in the correct columns, but if you add a dtype argument while reading exactly the same data "f.read_frames(f.nframes, dtype=np.float32)", then samples from both channels end up in both columns, so that each column now has interleaved data.
"""

script + wav in my gmail inbox

@wslihgt
Copy link

wslihgt commented Feb 28, 2013

Hi David,

I just noticed I had this problem as well: passing the dtype argument to read_frames ends up messing the samples, and interleaving them the wrong way around. Not sure where that comes from. Have you found out where the problem was? I must admit I use a fairly old version (0.11.0), and I noticed my issue with dtype=np.int16. Maybe you fixed it already in the mean time... In which case you could maybe drop a few lines here?

Cheers!

@mgeier
Copy link

mgeier commented Jul 13, 2013

I also experienced this bug in version 0.11.0.
I've illustrated it with an IPython notebook: http://nbviewer.ipython.org/5990729/audiolab_bug.ipynb

@mgeier
Copy link

mgeier commented Jul 13, 2013

I had a look at the code and I think I know where the error is located.

In the file audiolab/pysndfile/_sndfile.pyx, the function read_frames() is defined which forwards to read_frames_double(), read_frames_float(), read_frames_int() and read_frames_short().

The main difference between read_frames_double() (which is used by default) and the others is that it uses C ordering for the memory of the array while the others use Fortran ordering.

There is also a comment about Fortran ordering, but I think this is obsolete:

# Use Fortran order to cope with interleaving
ty = np.empty((nframes, self._sfinfo.channels),
              dtype=np.float32, order='F')

I tried changing 'F' to 'C' in the 3 functions and my soundfiles were read correctly.

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 a pull request may close this issue.

3 participants