-
Notifications
You must be signed in to change notification settings - Fork 112
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
Feature request: Support interleaved stereo data #407
Comments
There are the |
That's very useful, thanks. Can you clarify— |
Yes, it entirely depends on the format. Have a look at https://libsndfile.github.io/libsndfile/api.html#raw for more information. I'd expect this to only work reasonably for uncompressed PCM-like formats. |
The situation is admittedly a bit complicated, so it is easy to be confused. The parameters The data that you are handling in your Python code is entirely independent of that. In the Here's a hopefully illustrative example: >>> import soundfile as sf
>>> sf.write('myfile.aiff', [1.0], subtype='PCM_16', samplerate=48000) This creates a 16-bit file containing the largest possible signal value. >>> f = sf.SoundFile('myfile.aiff')
>>> bytes(f.buffer_read(dtype='int16'))
b'\xff\x7f' As you can see, you still have to specify the And to come back to the question about endianness: If you look at the file contents (e.g. with AIFF files are stored in big-endian format, but as you can see above, we got the bytes in little-endian format. We are getting native endianness. If you run this on a big-endian system, you should get We can continue exploring: >>> f.seek(0)
0
>>> bytes(f.buffer_read(dtype='int32'))
b'\x00\x00\xff\x7f' We can read the value as 32-bit integer, even though it is stored as 16-bit integer in the file. In summary:
Native endianness.
Nope. |
* Clarifies range of python integer input to write(), addressing issue bastibe#405. * Clarifies, which came up in issue bastibe#407. * Clarifies how to build the docs, which confused me while preparing this PR (Simply installing Sphinx is not enough)
* Clarifies range of python integer input to write(), addressing issue bastibe#405. * Clarifies endianness of buffer_write input, which came up in issue bastibe#407. * Clarifies how to build the docs, which confused me while preparing this PR (Simply installing Sphinx is not enough)
Although python-soundfile is usually used with NumPy, it does support non-NumPy use. A great feature for non-numpy use would be an option to allow inputs to functions such as Soundfile.write() to be input in interleaved stereo format instead of multidimensional array format when the data is stereo. Often data is already in interleaved format for various reasons, and (I could be wrong about this) I think that generating a Python array by concatenating many values to a single list will generate less garbage than producing a 2xMany list of lists.
The text was updated successfully, but these errors were encountered: