Opus files distort/clip in peaks

Issue description:

Issue: Some transcoded files distort heavily in peaks when played back in symfonium. Same transcoded file exported from symfonium and then played back in another music player (Poweramp) did not distort/clip. Noticed that playback in symfonium was louder than in Poweramp.

The same song played in symfonium as a flac does not distort.

Media provider: navidrome

Original file: flac 44.1/16

Transcoded to: 128 opus

Song: Djrum - Unweaving

Type of song: piano song

Time: multiple points but for example 1:36.

Have noticed it with other songs too.

All DSP settings are turned off, only replaygain is turned on. Prefer album, track fallback - 18 LUFS (- 23 also distorts)

Logs:

Upload description: elaiden

Additional information:

Android Samsung galaxy s23

Playback on bluetooth earbuds. Jabra Elite 8 active.

Files have been cached on the device.

I noticed when I exported the files from symfonium to test in Poweramp that the files are .flac, but the size corresponds with an opus file of 3.75mb. The original flac file Is 14mb. I tried to change the extension to opus with a simple rename and playback in Poweramp. Still no distortion then.

Reproduction steps:

Media provider:

Subsonic

Screenshots:

Increase the replay gain negative values, or enable negative pre amp or enable limiter.

Poweramp by default have negative pre amp and I think limiter enabled too. Symfonium by default ensure the most untouched natural sound.

I got very close to a solution, but not quite:

Different combinations of these 3 settings pictured below sometimes worked to remove the distortion. Mostly when they all were turned on, but sometimes when either the sample rate or the Hi-res setting was turned off. I got it to work with a second set of headphones (Sennheiser PXC 550-II). For a while, but then tried it with the jabra and couldn’t get the same result. Then when I tried with the sennheisers again the distortion was back there too, and I could not manage to get it to work there either again. Very finicky.

Other things I tried that did not work:

I tried disabling replay gain. Still distorts. It shouldn’t have made a difference since replay gain decreases the gain when enabled.

I enabled the Android DSP preamp setting (within symfonium), no matter how low I set it I still get distortion. Even tried setting it to - 15 dB. Still distorts. The music gets lower in volume, so the setting is working. But the distortion must be happening before it in the chain.

Also tried the limiter at an absurd threshold setting. Distorts. Even if it would have worked I would never want to have a limiter turned on in my listening chain..

I tried with a second set of bluetooth over ear headphones (Sennheiser PXC 550-II). Listening at a low volume to make sure the headphones are not getting overloaded, it still distorts. So its not the headphones.

So what can it be? :

It seems like somewhere in the playback chain before the DSP settings there might be an unintended gain boost after the transcode. And it does not seem to be embedded in the file, since on export the problem is gone. Although i got a bit unsure about that when I exported the file and it said .flac, Poweramp still identifies the format as being opus in the app, and it has the right size of an opus file.

I would appreciate if you could look into this, I’m an audio engineer and perfect playback that I can trust is extremely important to me. I want to hear how my mixes work when they are being transcoded with lossy compression methods, as well as in their original wav. I’m quite sure that I have checked the settings and not made an user error to cause this, though its possible.

Provide the files (original and transcoded) to https://upload.symfonium.app the transcoder you use probably add some positive base gain in the stream data.

I sent you the files with a description and some more info.

Sending the description here also:

Opus files distort/clip in peaks - music files
user: elaiden

file descriptions:

    1. Unweaving.flac = original.
  • Unweaving.flac = transcoded opus version.

  • 3 Unweaving.flac = 44.1/24 extra non transcoded i downloaded to check.

I know that the last one in 24 bit has not touched my replay gain tagger (rsgain in a docker container). If Navidrome does any gain tagging i do not know. I do not think so, since i needed to use rsgain to be able to use replay gain in symfonium. Anyway, my rsgain program has not touched it, and i still hear distortion after it has been transcoded and then played back in symfonium. When i export the one that had been transcoded from the 24 bit original, and play it back in poweramp, there is no distortion.

Listen from 1:36. At around 1:39 in the crescendo it distorts in all three files when they have been transcoded into opus and played back in symfonium.

There is a slight type of distortion in the actual song that is supposed to be there and can be heard with both files. The distortion i can hear in symfonium is much more apparent. When i play back these files on my computer and wired headphones they sound fine to me. I can hear the slight distortion in the track thats supposed to be there, but nothing like in symfonium.

Here are the 3 transcoding commands that are being used in navidrome. Pretty sure only the opus one is being used by symfonium and i see no mention of positive gain in any of them.

ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a libopus -f opus -
ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a aac -f adts -
ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -f mp3 -

Your files clip due to compression and their content, you should add some room in the source files.

Or use ffmpeg -i "%s" -ss %t -map 0:a:0 -c:a libopus -b:a %bk -af "volume=-2dB" -v 0 -f opus - to add room during transcoding and avoid compression clipping.

Alright got it! That fixed it, thanks. It’s not my song, so can’t add room in the source files, but the new transcoding command worked. Have you considered adding -1 to -2 of gain in the decoding stage in symfonium? That way this could also be avoided. Though i suppose nipping it in the bud as early in the chain is best. Maybe i should pester navidrome devs to change their default transcoding command instead..

That command with citation didn’t work in navidrome, this one did though:
ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a libopus -af volume=-2dB -f opus -

Those nasty intersample peaks. Thanks!

1 Like

Again Symfonium does not touch the audio unless necessary. And in all cases doing this at the transcode phase ensure better handling of your specific files issue.

1 Like

@elaiden Thanks for this. It has also helped me to eliminate the peak distortion.

And btw… What a fantastic Album that is :wink:

1 Like

@TheKingPin Sweet, glad I could be of help. Always nice when my own struggles and troubleshooting can also help others. Makes that time feel well worth it, so thanks for telling me :slight_smile:

And yes yes really good album! Love me some idm. Was my first djrum record, do you have any recommendations for his earlier stuff?

1 Like

@TheKingPin

Related to this, I also fixed an other problem. Gapless playback wasn’t working well with the default navidrome command when transcoding to opus.

This command solves both issues:

ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a libopus -af volume=-2dB -frame_duration 10 -application audio -fflags +bitexact -flags:a +bitexact -f opus -

1 Like

I don’t because its my first album from him also :smiley: But he done a BBC Radio 1 Essential mix which is great. You can probably find it online some where but sound quality of those mixes is always sub par.

1 Like

Thanks for that because I didnt notice some miniscule silence gaps with the previous transcode options. Im interested to know how you handle replaygain or do you use it all?

Im using Replaygain 2.0 values but its just too low overall in comparison with any streaming services. I kind of combat this by using 5db pre gain in Eq settings.

I’m not the guy you were asking, but my (limited) understanding is that ReplayGain 2.0 targets -18LUFS for most files while the default for OPUS is -23LUFS… Which is exactly your +5db compensation.

Streaming services seem to target -14 or -16LUFS. (Source: RG2.0’s GitHub) So you could add a bit more pre-gain to match those?

1 Like

Thanks for chipping in. I understand also from my limited knowledge the same :slightly_smiling_face:

Thing is more gain = more chance of peaking. I know a limiter on top can combat that but I would like to avoid adding to much to the chain.

The current symfonium pre amp is also in beta and I find it will just not work sometimes. This will most likely be fixed soon so I’m not complaining.

I also tried poweramp Equalizer app and it worked pretty well but recently I get audio drops / stutter on track change, so I reverted back to out of the box symfonium eq.

It’s not in beta and there’s no known issue to fix :wink:

1 Like

I do apologise. Last time I checked some time ago it still was. :slightly_smiling_face: I will need to test it properly again.

@Tolriq out of curiosity, and, also because you are good at this sort of thing. What would be your suggested approach if Im taking all responsibility for the end result?

Pre Amp + limiter or something else?