Hi Bob.
Dave was having a problem with files created in SAW being rejected by dbPowerAmp when attempting to convert to mp3, and it mentioned something about "Chunk is out of RIFF area but still inside file". So, I've been attempting to help him run it down. In the process, I've found something that may or may not be related - but is awfully peculiar.
First, let me say that I am not an assembler programmer and rarely deal in hex (all the endians and the bases...). So, it's uncomfortable for me and I have to move real slow to avoid making stupid mistakes. But, I at least don't think I have made a mistake here. Also, though, I've never worked over a wave file before. It's possible that I missed something. But, I don't think so. I think I've found a bug. Plus, it at least looks as if it has solved Dave's dbPowerAmp conversion problem.
Here's the first few bytes in Dave's file from a hex perspective, and the translation. I put it in Courier New - but it gets rid of my spaced columns anyway. So, unfortunately, it's hard to read.
52 49 46 46 98 83 03 00 57 41 56 45 66 6D 74 20
R I F F 230,296 W A V E f m t _
10 00 00 00 01 00 02 00 80 BB 00 00 00 EE 02 00
16 Bytes 1(PCM) 2 ch 48,000 s/sec 192,000 B/sec
04 00 10 00 64 61 74 61 64 83 03 00
4 B/smp 16 b/smp d a t a 230,244 bytes
Here is a table of that data that includes how many bytes each field takes up. (same problem here...)
RIFF Header
-------------------
bytes Field Content
4 Chunk ID "RIFF"
4 Chunk Size 230,296 bytes to end of file beginning at 'W' (below)
So, beginning with the word 'WAVE' to the end of the chunk (also file...) takes up 230,296 bytes. The file is altogether 230,304 bytes long according to Windows. 4 + 4 + 230,296 = 230,304. The RIFF header chunk size ties nicely.
4 Format "WAVE"
SUB CHUNK #1
-------------------
4 SUB CHUNK ID "fmt "
4 SUB CHUNK SIZE 16 bytes
Between the first byte of 'audio format' (below) and the rest of the fmt sub chunk, sub chunk size says it should take 16 bytes. And: 2+2+4+4+2+2 = 16. The fmt subchunk size ties nicely.
2 AUDIO FORMAT 1 (PCM)
2 NUMBER OF CHANNELS 2 (stereo)
4 SAMPLE RATE 48,000 samples per second
4 BYTE RATE 48,000spc * 2 channels * 2 bytes/sample = 192,000 bytes per second
2 BLOCK ALIGN 2 channels * 2 bytes/sample = 4 bytes/sample, stereo
2 BITS PER SAMPLE 16
Now the data subchunk.
SUB CHUNK #2
-------------------
4 SUB CHUNK ID "data"
4 SUB CHUNK SIZE 230,244 bytes from the next byte to the end of the data sub chunk
And so, beginning at the 45th byte, right after the word 'data' are the music samples themselves. And, we know that they should take up 230,244 bytes from the sub chunk #2 size. By extension, if 'data' is the last sub chunk, the size of the entire file must be 44 + 230,244 = 230,288 bytes. But, it isn't. It's actually 230,304: 16 bytes more - as we figured from the chunk size, above, and also as reported by Windows. The data sub chunk size doesn't tie with anything.
The RIFF PCM Soundfile Format contains the potential of additional subchunks though. Usually, those are at the beginning of the file, before the fmt subchunk (copyright, publisher, album, et. al.). But, I don't see any rule that says it can't be after the data subchunk.
So, could that be it? Is there another subchunk hidden in the last 16 bytes of the file? Let's look:
02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
According to the RIFF rules, the first four bytes would have to be the subchunk id, which is text. Here that would be ASCII ^B plus 3 nulls (not spaces (not text...)). Then the sub chunk size would be the next 4 bytes - and those are all nulls. Therefore, a subchunk with an id of ^B and three nulls, and a size of zero, plus 8 more bytes worth of nulls/zeros for content. So - I don't think so. That's gotta be the last 8, two byte, samples of the recording that are outside of the declared data sub chunk size.
I checked a wave file with an origin from someplace else (ripped from a CD) and it does not have the same issue. The data subchunk size matches the number of bytes in the data sub chunk section.
This particular file of Dave's does not have the problem with dbPowerAmp. I suspect that it is because most of the last 16 bytes are nulls. I'm thinking that dbPowerAmp is ignoring those. But, when it (randomly) gets something that looks like a sub chunk definition - it begins to attempt to operate on it, fails, and puts up that (incorrect and misleading) message (since the problem is not with the chunk, per se, but the subchunk). Two files of Dave's that failed in dbPowerAmp work correctly there when I add 16 to the data subchunk size.
I also checked four other files produced by Saw Studio - two more 64 bit and 2 32 bit. They all have the same issue: data sub chunk size declared 16 bytes shorter than the samples it represents. So - I think I've found a bug. What do you think?
Connect With Us