John, we're not done. I thought it was OK. I burned a CD last night and all seemed well but as I listened to it today there's some weird artifacts at the transitions, and the lengths are still messed up somewhere. For those users out there still following this - use 1.6.0 not 1.6.1.
I copied from the SDK (MJRAWInputSource) directly, so I'm not sure.
How does MC use the LengthBlocks information differently if I return it as opposed to when I returned -1 ?? That is, what advantage is there to returning it at all?
[Later]
I've got it now, but there's still a conceptual bust. The SDK (raw wav data) does not implement m_nLengthBlocks at all. It uses m_nLengthMS as total blocks / sample rate / 1000. Where total blocks is total "wide samples" in bytes (e.g. a sample from each channel -- NOTE: flac calls this a single sample). For the SDK it actually calculates this from the file length in bytes.
But for a compressed file, I can't do that. Duration depends on total samples, so I have to compute it as TotalWideSamples / SampleRate / 1000. I think playback of a file uses this, because this seems to work fine.
My two incorrect assumptions were:
1. That the SDK was literally correct, and I was using TotalSamples / BlockAlign, which gave me 1/4 of the right number. The burns were coming off with 25% of the right length, even though lengthMS was correct.
2. That the SDK was literally correct in the other way, and I was using TotalBytes / BlockAlign, which gave me about 60% of the right length, even though LengthMS was correct.
The correct way, is simply that m_nLengthBlocks is the TotalWideSamples. You could have picked a better name for that variable