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
scipy.io.wavfile should be able to read 24 bit signed wave (Trac #1405) #1930
Comments
@stefanv wrote on 2011-03-10 Could you also attach a (very short) .wav file of the required format? That would help with debugging. Thanks! |
Attachment added by trac user tuxicoman on 2011-03-10: 24test.wav |
trac user tuxicoman wrote on 2011-03-10 Sure, this is one i've done with audacity. |
Milestone changed to |
The gist https://gist.github.com/WarrenWeckesser/7461696 contains a couple functions for generating wav files with a 3 byte sample width. Something like this could be used for unit tests if support for 24 bit files is ever added. |
For anyone who needs to read 24 bit files: I created a gist containing the function Update: The gist now includes a function called Update 2: I moved the gist to a regular github repository at https://github.com/WarrenWeckesser/wavio |
Warren - OK to add this to scipy? |
@matthew-brett: Sure, that would be great. |
Can we add this code from Warren? This is essentially what is required data = numpy.fromfile(fid, dtype='u1', count=size) # first read byte per byte
a = numpy.empty((len(data)/3, 4), dtype=`u1`)
a[:, :3] = data.reshape((-1, 3))
a[:, 3:] = (a[:, 3 - 1:3] >> 7) * 255
data = a.view('<i4').reshape(a.shape[:-1]) 24bit wav format is very common, unfortunately it's not possible to attach a sample to this post... |
@Snotzer if that fixes the issue (I didn't check), then I guess the answer is yes. PR welcome I'd say. Would need to include a small .wav file for a unit test, similar to the ones that are already there now in |
Including a 24bit wav file similar to the one in scipy/io/tests/data
|
3-bytes per sample is only possible for the case of Note that WAV files can have any number of bits per sample. 1-8 bits are interpreted as unsigned, 9 or more are signed. Adobe Audition can output 20-bit files, for instance, starting like so:
It is still stored as 3 bytes per sample, though. I suggested in #5990 that it be possible to convert all different formats into floating point normalized from -1 to +1, the way scikits.audiolab does, for when you just want to process the signal and don't care what format it was stored in. Also if not normalized, it should have an option to output the bit depth. |
gh-6849 has a link to an implementation. The author doesn't want to make the time to do a PR though, so if someone wants to have a look at that that'd be great. |
I encountered this for myself - my DAWS software records in 24-bit WAV files so it would be convenient for me just to reading |
Is the support of 24-bits wav available in a recent release of scipy, or is it still work in progress since 2014? |
@jeremycochoy It's still a work in progress, in PR #6852. Can you use PySoundFile? |
FYI: The gist that I created back in 2013 has since been converted to a package called |
Another way of going around this is to change the input's bit depth using a tool like |
Original ticket http://projects.scipy.org/scipy/ticket/1405 on 2011-03-10 by trac user tuxicoman, assigned to unknown.
So far the scipy.io.wavfile module cannot read 24 bit wave files whereas it's quite a popular format.
After looking to source code, it seems that because there i no numpy.int24 type; the code fails on 24bit wave file. The function crashes on following line :
with dtype = "<i3" :-(
Because 24bit is stored on 3 bytes, scipy.io.wavfile needs additional code to slice and convert filebytes into an 32bit type array for example. Unfortunately, even after googling, I'm not enough talented in python/numpy/wavfile to code this. So i file this ticket for someone else to code it. Thanks.
The text was updated successfully, but these errors were encountered: