Closed taranasus closed 3 years ago
Hmmm... Doing it the suggested way means the last sample will likely be overwritten with an incorrect value. Seems like we should instead just break the loop immediately. Another option is to subtract 3 from the exit case in the while definition (line 1388) so we always have a multiple of 4 samples decoded, which is probably closer to what the spec calls for (I've not read it in years so I don't remember offhand). Thoughts?
I agree that this is probably not the best approach, and the place where the file has the problem and this case is hit it does produce a tiny audio artefact. I'd say let's go with the second option that you think is closer to the spec, as my fix creates fake data while breaking the loop might produce incorrect / incomplete data.
I'm no authority on MP3 decoding, I just want this to work. I'll make the subtract 3 change now
Awesome, thanks for approving. Do I still have to do anything or is that it and it will be merged at some point?
Where does the - 3
origin from? -1
could have been plausible, but where are those other two increases done?
Where does the
- 3
origin from?-1
could have been plausible, but where are those other two increases done?
If you expand the file, to see the whole while loop you'll see it looks like this:
while (part3end > _bitRes.BitsRead && idx < SBLIMIT * SSLIMIT - 3)
{
Huffman.Decode(_bitRes, h, out x, out y, out v, out w);
_samples[ch][idx] = Dequantize(idx, v, gr, ch); ++idx;
_samples[ch][idx] = Dequantize(idx, w, gr, ch); ++idx;
_samples[ch][idx] = Dequantize(idx, x, gr, ch); ++idx;
_samples[ch][idx] = Dequantize(idx, y, gr, ch); ++idx;
}
So we're doing -3 to make sure that it gets through the last Dequantize without going IndexOutOfRange
Is this going to be merged in? I'm trying to do MP3 > WAV conversion in a docker environment using NLayer and getting this error.
Because of the way it was written, idx could become bigger than SBLIMIT * SSLIMIT within the while, causing an index out of range exception inside the Dequantize method, throwing and stopping to play the song altogether. This fixed that issue allowing the otherwise valid MP3 song to continue playing.