LMMS / lmms

Cross-platform music production software
https://lmms.io
GNU General Public License v2.0
7.96k stars 993 forks source link

Exported audio length is not perfect in WAV/FLAC/OGG #3465

Open lydianchord opened 7 years ago

lydianchord commented 7 years ago

For example, if you export a song that should be exactly 40 seconds long, if your buffer size in LMMS is 64 frames, the resulting file will be short of 40 seconds by more than 30 frames, and increasing the buffer size will make it shorter by even more frames. This affects the end of the file, not the beginning.

Sawuare commented 6 years ago

I can't reproduce with LMMS 1.2.0-rc.5 using SDL.

@lydianchord Please test with the latest beta release. If the issue is still present, post your audio interface.

lydianchord commented 6 years ago

I've downloaded LMMS 1.2.0-rc.5, and it seems like the issue is still there (using SDL). For example, mathematically, this should be exactly 40.0 seconds long when exported as a loop at 60 BPM:

lmms_length

However, when you examine the resulting audio file, it falls short of 40.0 seconds by >30 samples:

lmms_length_file

And changing the buffer size in LMMS's settings affects the gap (>160 samples using the maximum buffer size in this case):

lmms_length_file2

This isn't an issue with other audio programs I've tried, which always export files that reach the 40.0 second mark with a similar setup.

Sawuare commented 6 years ago

Yes, there is an issue. My first test was incorrect.

However, the buffer size and export options do not affect the exported audio length, but the export file format does.

In Audacity's export: WAV, FLAC, and OGG are perfect, but their MP3 has the same issue as ours (this is probably the nature of MP3). So we have issues in WAV, FLAC, and OGG.

Spekular commented 6 years ago

MP3 files have a short silence at the start for metadata: https://superuser.com/questions/400790/how-to-convert-wav-to-mp3-without-adding-silence-at-the-beginning

I suppose it's still worth checking if our mp3 exports are the right length. Perhaps export one wav and one mp3. Convert the wav export to mp3 with audacity, and compare the lengths of the two files? I don't have mp3 export as an option or I'd test.

Sawuare commented 6 years ago

I suppose it's still worth checking if our mp3 exports are the right length.

Both LMMS's and Audacity's MP3 exports are longer by 3168 samples, but FL Studio's is longer by 2016 samples, and all of them use LAME. FL Studio is probably customized to shorten exported MP3s, so I think our MP3 exports are the right length.

lydianchord commented 6 years ago

Oh yeah, to clarify, I only tested this by exporting to WAV. Also, I closed and reopened LMMS between changing buffer size settings, in case that's why you're not seeing a difference.

Sawuare commented 6 years ago

@lydianchord I did that, but there were no differences, even with a buffer size of 16384 frames.

zonkmachine commented 4 years ago

lmms_length_file

This looks familiar to other issues and I think this may have been fixed already. Either in lmms-1.2 or in master. @lydianchord Can you please try and reproduce this again in the latest lmms-1.2 release and if you can still reproduce the issue could you then upload a minimal demo project that displays the bug so we can test this under the same conditions as you?

softrabbit commented 4 years ago

This looks familiar to other issues and I think this may have been fixed already. Either in lmms-1.2 or in master.

I'd point at the lack of logic to handle a fractional buffer at the end of rendering, this probably isn't fixed. (ProjectRenderer.cpp )

44100 Hz * 40 seconds / 256 = 6890.625 buffers, and that remainder is the 160 samples mentioned above.

zonkmachine commented 4 months ago

Total export length would now be affected by the fixes in https://github.com/LMMS/lmms/pull/6908. At least if the last sound in the exported file is a native lmms plugin.