beetbox / audioread

cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python
MIT License
489 stars 108 forks source link

rawread error with 24bit wave #48

Closed slychief closed 7 years ago

slychief commented 7 years ago

Hi,

I'm currently facing a problem trying to read PCM S24 LE encoded wave files. I get the following error on an UBUNTU host using Anaconda with up-to-date libraries:

File "/home/schindler/anaconda/lib/python2.7/site-packages/audioread/rawread.py", line 112, in read_data
    data = audioop.lin2lin(data, old_width, TARGET_WIDTH)
audioop.error: Size should be 1, 2 or 4

I printed the arguments just before the failing statements:

print len(data), old_width, TARGET_WIDTH
data = audioop.lin2lin(data, old_width, TARGET_WIDTH)

and received these values:

6144, 3, 2

here some infomration about the audio file:

soxi

Input File     : '/data/music/DCASE2016/task1/TUT-acoustic-scenes-2016-development/audio/b106_0_30.wav'
Channels       : 2
Sample Rate    : 44100
Precision      : 24-bit
Duration       : 00:00:30.00 = 1323001 samples = 2250 CDDA sectors
File Size      : 7.94M
Bit Rate       : 2.12M
Sample Encoding: 24-bit Signed Integer PCM

ffprobe

Input #0, wav, from '/data/music/DCASE2016/task1/TUT-acoustic-scenes-2016-development/audio/b106_0_30.wav':
  Duration: 00:00:30.00, bitrate: 2116 kb/s
    Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s32 (24 bit), 2116 kb/s
sampsyo commented 7 years ago

Interesting! Thanks for the report. It seems you're right—audiooop.lin2lin says:

Convert samples between 1-, 2- and 4-byte formats.

meaning that sources can be 8, 16, or 32 bits but not 24. It looks like this has been fixed in Python 3, where this now says:

Convert samples between 1-, 2-, 3- and 4-byte formats.

Is there any chance you can switch to Python 3 for your application?

On our side, we should catch this error before it happens and "give up" on Python 2 for files of the wrong bitdepth.

sampsyo commented 7 years ago

OK! I added the check. Can you see whether the above commit avoids the crash?

slychief commented 7 years ago

Thanks! Now it's working!

sampsyo commented 7 years ago

Yay!

DMU-3dTuneIn commented 7 years ago

Hi,

I am facing the same problem in python 2 and I am running code on server so I can not make change to "audioread/rawread.py" as you mentioned. So how can I give up the ".wav" file with bit rate different than 8, 16, 32 ? I am using urbanSound data.

Thanks Nitesh

sampsyo commented 7 years ago

Hmm... we’d need a complete bug report with full information about your setup to help. Good luck!