mp3 to wav conversion while using piping to output instead of writing to file doesn't work as expected
How to reproduce error:
$: sox Slipknot\ -\ Psychosocial.mp3 -t wav psychosocial2.wav
$: sox Slipknot\ -\ Psychosocial.mp3 -t wav - | cat > psychosocial.wav
$: diff psychosocial.wav psychosocial2.wav
Binary files psychosocial.wav and psychosocial2.wav differ
This should replicate with most mp3 files.
Investigating with a hex editor, it appears certain bytes which should be output as "6E" get output as "80" when piped (there may be others, that is the one which manifested first in my file). I suspect this is actually "FFFFFF80" being output as "80", with the outputs being the wrong types, but haven't confirmed.
Clarification: only incorrect in header section of the wav file, data section outputs correctly.
The length of an MP3 file cannot be determined exactly beforehand. This is why the header info is wrong (or inexact, at least). When writing to a file, the WAV format handler will go back to the header when all samples have been written and fix the length information. When writing to a pipe, this is not possible.