Zeugma440 / atldotnet

Fully managed, portable and easy-to-use C# library to read and edit audio data and metadata (tags) from various audio formats, playlists and CUE sheets
MIT License
442 stars 60 forks source link

Wrong track duration for stereo .mp3 files #211

Closed Ellusive1 closed 11 months ago

Ellusive1 commented 11 months ago

The problem

When creating a Track object for a stereo mp3 file, the Duration and DurationMs properties are twice what they should be.

Environment

Details

The problem does not arise for mono files or stereo files in .wav / .ogg / .aac / joint stereo .mp3. Only for .mp3 files with ChannelsArrangement.Description equals to Stereo (2/0.0).

Code To Reproduce Issue

var = File.ReadAllBytes("./sample-6s.mp3");

using (MemoryStream memoryStream = new MemoryStream(mp3Bytes))
{
    var track = new Track( memoryStream );

    Console.WriteLine(track.DurationMs)// display 12872, should be  6436
}

Sample audio file: https://file.io/mVQpFtw6QGY9

Zeugma440 commented 11 months ago

Thanks for your feedback. I'll get back to you next week-end.

Unfortunately I can't do anything right now as I'm on vacation 😉

Zeugma440 commented 11 months ago

The issue does not happen with all Stereo MP3s, hopefully 😅

The file you submitted has a very peculiar structure, as its MPEG headers contradict each other :

I've adjusted the code for reading MPEG headers to be able to detect such cases. Now it's slightly slower but it covers your issue ;)

Zeugma440 commented 11 months ago

Fix is available on today's v5.00