0

Using Audacity, I have exported a mp3 file from a very short wav file.

Bringing the mp3 file back into Audacity and viewing the wav and mp3 together shows the files as different lengths with (mostly!) silent audio added at the beginning and end of the waveform. This is the same on both Windows and Mac.

They are also different lengths when using the NAudio API.

However, if I view in Sonic Visualiser on Windows, both the wav and mp3 files are the same length.

They are also the same length on the Mac when using AVFoundation API components.

I expect some difference in the sample amplitudes due to lossy encoding, but not the length of the file. Why do some tools and frameworks load the mp3 file incorrectly, having a different length and spurious audio sections at the beginning and end?

(The erroneous lengths are different in Audacity and NAudio by the way.)

WAV and MP3 in Audacity on Windows

  • 1
    How long is this "short" WAV file? depending on your sample rate you might be at the limit of the smallest mp3 frame size stackoverflow.com/questions/6220660/… at your sample rate it looks like you should have a frame of approximately 26 milliseconds and if your sample is shorter than that it could be getting padded up to it. – Mokubai Apr 24 at 16:31
  • The wav file is 56ms long. When the mp3 file is pulled into Audacity it is 131ms. When loaded into Sonic Visualizer (for example) the mp3 length is the same as the original wav. – fractor Apr 25 at 8:45
  • 1
    Well 131/5 does equal 26.2 so it does appear to be padding. 56ms would need a minimum of 3 frames and one of those frames would have to be padded up anyway. After that it looks like it has added a frame at the start and the end to "smooth" the data a bit. I know that later mp3 encoders were able to add data to state when the actual music data started and finished in order to facilitate gapless playback which would explain why some programs show the "proper" length... While I can explain each individual feature of what you are seeing I can't really explain why overall... – Mokubai Apr 25 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.