-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
I was getting an exception when decoding MPEG Version 2. Figured out it was because the frame lengths were being calculated incorrectly. I believe the issue is here (in MpegFrame.cs):
// calculate the frame's length
int frameSize;
if (BitRateIndex > 0)
{
if (Layer == MpegLayer.LayerI)
{
frameSize = (12 * BitRate / SampleRate + Padding) * 4;
}
else
{
frameSize = 144 * BitRate / SampleRate + Padding;
}
}Compare to the length calculation used by NAudio:
int coefficient = frame.SampleCount/8;
if (frame.MpegLayer == MpegLayer.Layer1)
{
frame.FrameLength = (coefficient*frame.BitRate/frame.SampleRate + nPadding)*4;
}
else
{
frame.FrameLength = (coefficient*frame.BitRate)/frame.SampleRate + nPadding;
}I don't have access to the specs, but it looks like the hard-coded 144 is only going to be correct for MPEG-1 (when sample count is 1152). Appears to have solved my error switching to use SampleCount / 8.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels