Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Something really terrible is happening when encoding 20Hz sine wave (Read 30473 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Something really terrible is happening when encoding 20Hz sine wave

I decided to test what happens when encoding 20hz sine wave with Opus (this is something that can easily be in "real music", so why not), and to my big surprise, it fails spectacularly. 

I used this setting "--bitrate 128" and nothing else (all else is on default). 
The bitrate at the end is 263 kbps, almost as high as the source file in 24 bit FLAC. 
It also sounds very obviously different from original, there's a lot of distortion that wasn't there. (yes I did ABX, see below, also, easiest ABX ever even at very low loudness level)

I tried to do the same with quieter signal (to check if maybe encoder is just overflowing something inside) but there's virtually no difference, same problem with inflated bitrate and non transparent sounding.

Also tried using different build of opusenc (the one came from foobar2000 encoder pack), again, same issues.

Is it a legit problem with Opus? Or am I using some outdated version or doing something wrong?

2 versions that I tried:
Quote
opusenc --version
opusenc opus-tools 0.1.10 (using libopus 1.1.2)
Copyright (C) 2008-2017 Xiph.Org Foundation

wine ~/Documents/foobar2000/encoders/opusenc.exe --version
opusenc opus-tools 0.2-3-gf5f571b (using libopus 1.3.1)
Copyright (C) 2008-2018 Xiph.Org Foundation

Code: [Select]
foo_abx 2.0.6c report
foobar2000 v1.4.6
2019-08-18 18:40:16

File A: 20hz 30 seconds.flac
SHA1: 692b1d490bbb37b937fefbf0bcba8998f810990c
File B: 20hz 30 seconds.opus
SHA1: a76f486c75d2675b634a1f49808ab0af9898b00d

Output:
DS : Out: default
Crossfading: NO

18:40:16 : Test started.
18:40:28 : 01/01
18:40:43 : 02/02
18:40:58 : 03/03
18:41:07 : 04/04
18:41:19 : 05/05
18:41:26 : 06/06
18:41:31 : 07/07
18:41:35 : 08/08
18:41:41 : 09/09
18:41:47 : 10/10
18:41:56 : 11/11
18:42:03 : 12/12
18:42:07 : 13/13
18:42:13 : 14/14
18:42:18 : 15/15
18:42:23 : 16/16
18:42:23 : Test finished.

 ----------
Total: 16/16
p-value: 0 (0%)

 -- signature --
1631b7e7986adb72438b4f7b8fc660dd1d8077d4
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #1
by the way, this sample also "kills" LAME V0, at least the bitrate doesn't get so big, but there's also an easy to hear difference (different kind difference)
it doesn't kill LAME CBR 320, so might be an issue with the VBR quality estimation in LAME.
Vorbis at -q 6 also isn't transparent with this sample, but the difference is definitely less annoying than with Opus or LAME.
(these tests with LAME and Vorbis were done without converting to 44100hz sample rate, perhaps that's a wrong thing to do, I'll try with 44100hz as well)
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #2
Note that the source is mono (1 channel).
But when I tried to convert it to stereo and re-do the test with Opus, there's no significant changes, all the same issues.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #3
Just for giggles decided to also check musepack, and... I can't hear any difference if using Musepack (default settings). (doesn't matter if it's 1 or 2 channels)
bitrate is also reasonable (40 kbps), good enough given that other choices produce non transparent result on it (except cbr mp3 @ 320).
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #4
FDK AAC encoder at VBR mode 4 is also transparent (for me at least) and takes only 7 kbps, clear winner so far.
(didn't test other quality levels of FDK AAC)
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #5
So...
I'm hoping that this problem gets fixed and Opus will also not choke on it. 
I'm assuming that AAC as a format is working on kind of the same principle, so if AAC can do it, Opus should too?
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #6
You do know that Opus is a lossy codec, right?

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #7
Yes. But it has a goal to achieve transparency at this bitrate (and it does so on most music, which is great). This is just a problematic sample that triggers some kind of bug, I guess.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #8
Opus has a high pass filter, so perhaps you're seeing that filtering your signal.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #9
IIRC that filter has the transition point much lower than 20 hz. And the difference that I hear isn't in the lack of signal, it's the inverse, I hear higher frequency sounds that weren't there (some kind of distortion). So if it's the filter, then it must be adding some distortion.
Replaygain also confirms that the signal isn't getting any quieter.
Anyway, it's not possible to disable the DC filter in Opus. So even if the bug is related to that filter, seems like there's still no workaround until it's fixed.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #10
Mix it with real song, if it still is problematic then it's worthwhile.
Otherwise 20Hz alone is an inaudible infrasound for which no audio codec should be tuned.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #11
> Otherwise 20Hz alone is an inaudible infrasound for which no audio codec should be tuned.
It is audible for me. (in Bose QC 35 II headphones). There's clearly a sound, and it isn't much quieter than something like 50Hz for example.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #12
Perhaps 22050 Hz sine is audible for you too, but it is nearly meaningless in everyday audio - such extreme frequencies are masked in everyday audio and there's no ABX test proving that excluding/altering them in lossy codecs is a bad idea.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #13
> Perhaps 22050 Hz sine is audible for you too

no, even 16000hz becomes hard in isolation, and it has to be louder than everything else to not get masked.
I can try find some music with loud and clear bass though, if that would be much stronger argument.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #14
Opus high pass is at 3Hz, its just to block DC signals which mess things up.  Introduced in 1.1 I think, no high pass before that.  Low frequencies don't take a lot of bits to encode, doubly so because they are barely audible as part of any real audio signal and so don't get allocated a lot of bits in lossy codecs.

Opus encodes in 21 (at this bitrate, using CELT) different frequency bands.  The lowest is 0-200 Hz.  In theory, it allocates bits to the bands in accordance with various weights, and the lowest band is not heavily weighted.  I would still expect that in this case, a lot of bits might go to that band, since it allocates bits between the bands in an attempt to reach the specified bitrate, but I don't understand all the details.  Maybe there is a good reason why that band doesn't get enough bits, or maybe some calculation just blows up in this abnormal case.  At lower bitrates, the low frequencies will be handled by SILK (either SILK alone or in hybrid mode), so it might be interesting to try your test signal at very low bitrates.  It might actually sound better!  Try below 64 kbs and keep going down to see what happens.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #15
> Maybe there is a good reason why that band doesn't get enough bits
just saying, for this case the overall bitrate is certainly more than enough, it's nearly twice the target bitrate.
> maybe some calculation just blows up in this abnormal case
that's what I'm thinking too.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #16
IIRC that filter has the transition point much lower than 20 hz. And the difference that I hear isn't in the lack of signal, it's the inverse, I hear higher frequency sounds that weren't there (some kind of distortion). So if it's the filter, then it must be adding some distortion.
Replaygain also confirms that the signal isn't getting any quieter.
Anyway, it's not possible to disable the DC filter in Opus. So even if the bug is related to that filter, seems like there's still no workaround until it's fixed.

It is definitely distortion, I just checked your file:



Does it happen if you use a higher frequency sin wave?  Like 1 kHz? 

FWIW, this is less than 0.01% distortion, so probably this is of no significance, but interesting that it happens. 

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #17
If amount of this kind of distortion is fixed (not affected by psymodel, just, say, always -40dB compared to the signal) then it's going to be most noticeable when the tone itself is in the area where human ear is less sensitive.

Tried some more with Opus @ 128 kbps:
27.5 Hz (A0 note, lowest "legal" note on a bass in dropped A tuning), easy to ABX.
30.868 Hz (B0 note, lowest on standard tuned 5 string bass), can't ABX anymore, actual bitrate is 239 kbps.
41.204 Hz (E1 note, lowest note on a standard bass tuning), can't ABX, bitrate bloat is still a problem (240kbps)
I assume anything higher than 41Hz would be transparent as well.
1kHz is also transparent. Also has bloated bitrate but less ("only" 199 kbps).

So, the lowest "real note" is affected, but anything higher than that, not so much.
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #18
I just tried this in Apple AAC (128k, VBR) and it encoded very nicely with a resultant bit rate of about 42kbps.  When I subtracted the resultant file from the original, there was only a little bit of second harmonic, maybe 60 dB down.  I can hear the tone clearly in my headphones, but there's nothing I could ABX between the two files; it seems like my phones are generating more distortion than the encoder did, so it would be pointless.

I have a fair amount of organ music with isolated, dominant pedal tones between 14 and 30 Hz, so I'm happy to note that AAC handles this well.

 

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #19
@Nichttaub: which encoding settings are you using for AAC? Because when I convert it to 128k VBR (Q64 - in Foobar) I get a 16kbps file that can be easily ABXed. It's not as bad as the Opus one, but still pretty bad.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #20
The bitrate at the end is 263 kbps, almost as high as the source file in 24 bit FLAC. 
The resulting bitrate, that is. Not "at the end" as in increasing to the end of the file.

Got curious. Used foobar2000 to look for a discontinuity. Found it between bitrates 52 and 53:
Target 52 -> 48
Target 53 -> 113

Checked target 128, got 264 (as yours - fb2k reports both as 264. But yours and and mine do not decode bit-identically; fb2k: difference -42.49 dB)

Now, foo_bitcompare is limited to how many bits PCM internally? Target 150 and up decode identically according to it.
And it is above twice the target until 256->513. Target 320 also produces 513.

Results are "worse" relative to FLAC if I reduce volume, but going 34 dB down (to make it approx. 16 bit "true" resolution) I didn't get .opus higher than 453.


Mix it with real song, if it still is problematic then it's worthwhile.
Otherwise 20Hz alone is an inaudible infrasound for which no audio codec should be tuned.
If you were right, it would be even worse - it would be a VBR lossy codec spending space on something it should have discarded and spent nothing on.
But 20 kHz certainly isn't inaudible.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #21
52 kbps is a believable value to switch to hybrid mode, which would confirm that the bloating occurs in the CELT layer.  Did you listen to the sub-52 version?  I wonder whether the encoder thinks it is speech or music?

P.SA.  The maximum frame length in Opus is equivalent to 510 kbps (with standard frames).  Your 513 presumably represents that plus overhead.

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #22

Mix it with real song, if it still is problematic then it's worthwhile.
Otherwise 20Hz alone is an inaudible infrasound for which no audio codec should be tuned.
If you were right, it would be even worse - it would be a VBR lossy codec spending space on something it should have discarded and spent nothing on.
But 20 kHz certainly isn't inaudible.
Every proper mixing should have highpass with very aggresive slope somewhere between 14-40Hz.
I attach your sine mixed with real music. The terrible unreal sine is still garbled but bitrate is correct.
What would be interesting, is testing this issue with real music Nichttaub mentioned (organs with 14-30 Hz pedals).

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #23
> Every proper mixing should have highpass with very aggresive slope somewhere between 14-40Hz

Almost none from my library have that. Also, why would you remove something that can be perceived, even if not always by ear but by body or by shattering glass in windows?
a fan of AutoEq + Meier Crossfeed

Re: Something really terrible is happening when encoding 20Hz sine wave

Reply #24
Before judging check with proper tool like Ultra High Resolution Spectrum Analyzer from MusicScope - you need huge window size for FFT. Large part of my library is clearly highpassed, even records from 80s. Similarly as proper CDDA masters should be 20kHz lowpassed even though some people would hear extreme sine at that frequency.
There are many reasons to do that.
Such low and intense infrasonics are expected only in movie sound effects and rare cases like the ones mentioned by Nichttaub. In 99% of music they are not expected and every good audio engineer will filter them out to keep things in control.

Don't get me wrong, this is some kind of issue and not the first one for Opus. But extreme artificial cases are often misleading in case of psychoacoustic lossy codecs and I'd rather see it tested with real material.