When exporting audio, do not use oversize buffer; make OGG match piece duration #31679
+7
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves: not a numbered issue, but it can be observed that OGG files come out shorter than the WAVs and MP3s for the same piece. (And I should point out, it's a step towards a fix for #16496 )
In the file
soundtrackwriter.cpp, avector<float>was resized such that the number of elements was a multiple of the size of a float, which was peculiar. Experimentation suggested it was not necessary; the vector in question, the buffer of audio samples needed only contain the number of samples per channel times the number of channels. This shortened the allocated but unused memory by half, but revealed another issue:It became too short for the expectations of the oggencoder (and only the oggencoder), which expected a few more samples (to address a time-estimation issue). Exploring this revealed that an important function in the LibOpusEnc API was not called; the second commit resolves this time-estimation issue in a cleaner way.
Confirmed that it was able to export flac, mp3, ogg, and wav of two different pieces on both Windows 11 and Ubuntu 22; ogg duration and sound now matches that of the others.