Natively read WAV files with bit-depths other than 8/16/24/32 #527

Open
opened 2025-07-23 14:38:53 +00:00 by martinwguy · 0 comments
martinwguy commented 2025-07-23 14:38:53 +00:00 (Migrated from codeberg.org)

Natively read WAV files with bit-depths other than 8/16/24/32

Description

You can create WAV files with unusual bit-depths using

for a in $(seq 1 32); do
  madplay --bit-depth $a -o out$a.wav in.mp3
done

but SoX fails to read anything other than the 8, 16, 24 and 32-bit ones.

sox -t sndfile and sox_ng -t ffmpeg succeed on all of them.

Analysis

Bit-depths 1 to 7

It says

sox_ng FAIL formats: bad input format for file `out1.wav': data encoding or sample size was not specified

and exits 2.

Bit-depths 9-15, 17-23 and 25-31

It says

sox_ng WARN wav: Premature EOF on input file
sox_ng FAIL sox_ng: `out9.wav' this handler does not support this data size: Unsupported data format

and exits 0 having created an out.wav of 44 bytes for 1-15 or 80 bytes for 17-31.

The message this handler does not support this data size comes from raw.c,
which wav.c uses to read the data, and raw.c only supports 8/16/24/32.

Conclusion

There are two issues here:

  • Making it able to read funny bit depths of WAV file (or raw file)
  • Not detecting unsupported WAV bit-depths and making a mess later
# Natively read WAV files with bit-depths other than 8/16/24/32 ## Description You can create WAV files with unusual bit-depths using ``` for a in $(seq 1 32); do madplay --bit-depth $a -o out$a.wav in.mp3 done ``` but SoX fails to read anything other than the 8, 16, 24 and 32-bit ones. `sox -t sndfile` and `sox_ng -t ffmpeg` succeed on all of them. ## Analysis ### Bit-depths 1 to 7 It says ``` sox_ng FAIL formats: bad input format for file `out1.wav': data encoding or sample size was not specified ``` and exits 2. ### Bit-depths 9-15, 17-23 and 25-31 It says ``` sox_ng WARN wav: Premature EOF on input file sox_ng FAIL sox_ng: `out9.wav' this handler does not support this data size: Unsupported data format ``` and exits 0 having created an `out.wav` of 44 bytes for 1-15 or 80 bytes for 17-31. The message `this handler does not support this data size` comes from `raw.c`, which `wav.c` uses to read the data, and `raw.c` only supports 8/16/24/32. ## Conclusion There are two issues here: * Making it able to read funny bit depths of WAV file (or raw file) * Not detecting unsupported WAV bit-depths and making a mess later
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
martinwguy/sox_ng#527
No description provided.