-
Notifications
You must be signed in to change notification settings - Fork 378
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
odd number of frames with an odd number of bytes-per-frame behaves odd #887
Comments
btw, if i change the WAV-file (with some binary editor) to report a data chunk size of 304, the error goes away (even if now the RIFF-header indicates the wrong size)... |
Thanks for report @umlaeute . |
That warning message is purely informational, libsndfile is still able to read such a file. The bug is that we write such an odd-length file, that no padding byte is added to the end. Another scenario to test would be mono formats of 8-bit or 4-bit sample size which could also potentially have an odd-length data-chunk given an odd sample length. Eg, wav with 1 channel and S8, U8, or ADPCM formats like MS-ADPCM, IMA-ADPCM, G726. |
So the problem is generic to any data section that is odd in length. 101 samples of unsigned 8-bit PCM have the same issue. But it get weirder. Padding the data chunk was added way back in #61 (same error report too, odd number of mono 24-bit samples). So the chunks are padded, but the parser is incorrectly reporting the odd length. This log warning was added in the same commit 4e6c87b . So the chunk parser has two bugs
|
Correction, the chunk parser DOES heed the padding byte. So the only bug really is the log message, which is in fact spurious. |
i think this is the real bug.
and i agree that this error message should go away iff WAV-files with odd data chunk lengths are really allowed. it's surprisingly hard to find an "official standards document" for RIFF/WAV (and the link I gave in the original post can only be considered informal). on page 11 it says:
So if we accept this document as a reference, the padding byte must be written, and it is therefore a "bug" if it is missing. |
Except it's not a bug, we do currently write the padding byte. The first part of 4e6c87b added a line that writes a padding byte before any post-DATA chunks, if any. The commit doesn't have a comment, so it's otherwise a bit mysterious. @@ -1188,6 +1191,9 @@ wav_write_tailer (SF_PRIVATE *psf)
else
psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
+ if (psf->dataend & 1)
+ psf_binheader_writef (psf, "z", 1) ; Confirmed with a test file with 101 samples of 8-bit mono pcm of 0x80 and a trailing INFO chunk:
Output of
|
And it writes the padding byte if there aren't any trailing chunks as well
|
So I think the bug is just that the message complaining about odd length data chunks is wrong. The message makes no sense, it is triggered when the data chunk reports that it contains an odd length of data, not when the data chunk is an odd length and has no padding byte. Containing an odd length of data is a legitimate condition. It's kinda the question of, does the padding byte belong "in" the data chunk, or is the padding byte "between" the data chunk and what comes next. The chunk parser cannot detect if the padding byte is missing, so it can't usefully report the message. In fact, if you modify the file and remove the padding byte, the chunk parser falls on it's face, because it expects the next chunk to begin at the next 16-bit boundary. So, the padding byte, while specified, is also kinda implied from the fact that in RIFF files, chunks should always start on 16-bit boundaries.
From https://learn.microsoft.com/en-us/windows/win32/xaudio2/resource-interchange-file-format--riff- , emphasis added. |
ah indeed. i confused myself.
i think it is quite clear by now that it is between the chunks (and the 2nd chunk is permitted to not exist), at least form the RIFF perspecive (or i misunderstood your question). otoh, i have no idea why the chose a term like |
It's MS. The terms "WORD" (and "DWORD", "QWORD") are dogma there. They made the choice to use that name to mean a 16-bit integer everywhere because when they were starting out they were a company purely focused on the 16-bit microcomputer market, hence "micro"-soft, not that inventive when you realize it. In hindsight, bad choice, because as their success and the platform they become most associated with grew, other word sizes became a thing they had to deal with, but they are anchored to terms locked in a 16-bit processor world. (Also not helped by the fact that both pre-NT Windows and the x86 architecture "start" in 16-bit, then "add" 32-bit, if you follow me.) I too chuckle when I see modern MS docs reference WORD in their specs, reminds me of my time playing with MS-DOS. It's what system level MS does. ;-)
I think I was trying to imagine the intent of the original author of the error message code. He misinterpreted the pad byte in one instance but not the other 🤷♂️ |
so I have a 24bit PCM WAV that consists of 101 frames, which gives me a data-chunk worth of 303 bytes.
such a file can be created as follows:
but if I read it back, like so:
i get a nasty error:
so who is to blame for this?
SFM_WRITE
add a zero-padding byte, so the number of bytes in the data chunk is even?SFM_READ
check whether the number of bytes equalsbytesperframe*frames
, (and not complain if its odd)?reading https://mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html, i see:
which indicates that the reported 'data' chunksize (as written into the chunk header) can indeed be odd (but the actual chunksize must be even, supposedly for alignment with the chunk that follows the 'data'-chunk which must always be last 🤔 )
(sorry for the pun in the title, but it was irresistible).
The text was updated successfully, but these errors were encountered: