Subject: Volume correction post-processing option

From: Joker
Date: Sat Apr 22 15:19:15 2006

To: UADE-User-discussion
I've noticed that UADE plays MODs at a much lower volume level than
when i play them with for example the DUMB plugin i recently ported
to Audacious.

The big loss of output volume happens when the nice features like
paning and headphone processing is being used. Maybe other filters
also affect the overall output volume since filters usualy do this ;)

Now those filters are really great and another reason why i really like
UADE.

Normalizers are not really an option for me. I dislike the result in most
cases. Yes, i've tried the more sophisticated ones such as the audio
compressor.

A manual setting for a post-processing boost would really be a good
option. It's the best real world solution. Better than all the geeky
automatic things.

The &quot;gain&quot; option seems to happen at a too early stage because even
a value of &quot;1.1&quot; gives me nasty clipping and i'd need at least a value
of &quot;3&quot; to get the volume i need which matches all the other players.

Such a &quot;correction&quot; should happen at the end of everything. For example
the &quot;Pre-amp&quot; option of the EQ in Audacious is able to correct the level
but that option is global for all sound and not per plugin.

---

From: alankila
Date: Mon Apr 24 10:27:52 2006

To: UADE-User-discussion
There is some loss of gain in the headphone plugin at least.

In order to calculate the simplistic headphone DSP that I designed, the signal for left ear is processed and mixed into the right ear, and vice versa.

The headphone effect filters the signal from other ear through a low-pass filter and a short delay pipeline confusing its phase, building a poor man's simulation of reflected sound. This then works like a &quot;virtual room reflection&quot; in more sophisticated systems like dolby headphone.

Because of additional input for each ear, it was (and is) necessary to reduce the gain in respect of the unprocessed signal to avoid clipping. At the moment, the headroom is 6 dB, which is slightly too much, as only 5 dB should actually be necessary.

Because of the DSP occuring in the brain, the processed additional signal is largerly &quot;ignored&quot; by the brain, leaving an impression that the signal comes through but quieter.

However, the gain is already processed as last of the effects. If you find than adjusting the gain drives the system into clipping, then we are already using all the bits.

It seems that with headphone DSP, a gain of 1.1 should be safe. (But without headphone DSP on you'll clip.) Panning should preserve signal gain unchanged.

I should take a while to improve the headphone DSP further, it sounds somewhat artificial still... Maybe I'll fix the gain factor at some point too.

---

From: alankila
Date: Mon Apr 24 12:12:42 2006

To: UADE-User-discussion
Oh yeah, I kind of forgot to reply to your actual question as I went on to rambling tangent...

A gain of 3 sounds incredibly big. On the contrary, if I compare uade's output volume to, say, modplug, uade is very loud and modplug sounds like I need 10 dB more output or something like that.

There must be a bug somewhere to require that sort of gains. We have written UADE to produce output at the maximum intensity just below clipping. My musings about headphone DSP losing about 1 dB of gain from theoretical maximum and so on are completely beside the point.

And yes, I don't believe in volume equalizers, also called dynamic range compressors, either. To use something like that ruins too much of commercial music as it is, let us leave our beloved amiga tracks in their full dynamic range, low as it already is...

---

From: Joker
Date: Mon Apr 24 16:47:50 2006

To: UADE-User-discussion
The volume loss with paning and headphone is not only my ear as the VU
meter shows alot less output (It's pretty cheap and by no means exact
but it shows about 6-8db or even more difference).
And well, the difference is so much that i don't think my ear cheats on me.
6db is really noticable since it's twice as much as the original.

I do not get any clipping by raising the &quot;pre-amp&quot; of the Audacious EQ to
about 6-8db. And while being louder than anything else even 20db does
not give me the nasty click kind of clipping as with uade's gain option.
Usualy too loud output value gives a unpleasant distorsion. But the one
from gain in uade are really short and loud clicks.

---

From: Joker
Date: Mon Apr 24 17:04:49 2006

To: UADE-User-discussion
Modplug on Linux (XMMS and Auda plugins) has a volume problem since
the beginning. It's funny because the Modplug Windows App running with
WINE does have sane output volume. :)

I compare uade volume with mp3, ogg, dumb, mikmod etc. output.

---

From: alankila
Date: Mon Apr 24 20:26:04 2006

To: UADE-User-discussion
Hmm. Well, you should see a 6 dB drop for a test tone of some sorts, let's assume a sample played on just left channel, particularly if you ignore the constructed signal that appears on the other channel. I don't think anything can be done about that because you have to have some headroom for mixing the left and right channels together. The only other option here would be to reduce the gain of the output by default, so that the headphone effect wouldn't have to do it. (Or we could set an optimistic gain and hope that clipping doesn't occur too much, of course, but I bet that in no time flat someone will find a chiptune where it will sound just horrible.)

As to panning, for mono signal (I mean: identical signal played on both channels at once) it should obviously make no difference, but if you again look at a test signal on just one channel, then naturally part of the signal energy is moved from one channel to the other, however if you sum left and right channel together the result should be the same, panning or not. So, nothing should get &quot;lost&quot; and signal energy is preserved by panning...

I mostly use uade123 frontend. It seems to be buggy these days, the CVS version seems to ignore -G for gain and -P for pan, and doesn't even support recursive mode anymore either. Perhaps I should check out audacious, it seems nobody else is using the command-line nowadays.

It seems that at least uade123 is programmed to reject gains outside 0 and 1, that is you can only use it to reduce system volume. That is as should be; uade ought to protect against destroying the signal through setting too high a gain.

---

From: Joker
Date: Mon Apr 24 21:46:17 2006

To: UADE-User-discussion
So at 100% paning (mono). A sample which gets played left at maximum volmue (with no paning) ends up to get played at left and right at the same time with 50% of max volume?

That would be about my 6db as 50% (half) is 6db. That would explain everything to me.

It's a matter of definition but for me a paining of 100% (mono) should
trigger a 6db boost at the very end. And 0.7 paning maybe 4 or 5 db
(i'm not good anymore at calculating those in between values)

I knew we wouldn't agree and that's why i suggested a manual post boost
from the beginning :)... this let's everyoen have what he likes best.
In my case i can boost 6db using the player equalizer and am still far from
any cliping on the output. The problem here is i can't have per plugin
values in those players which makes mixing of different filetypes in a
large playlist impossible :(
But even for console players it's nicer not to always play with the sound
mixer when playing MODs (I get a shock when i forget to set the volume
back to normal and use another player again :) )

---

From: Joker
Date: Mon Apr 24 22:01:51 2006

To: UADE-User-discussion
What about 2 different paning methodes then.

Lets asume that &quot;Original&quot; is a mod which only plays a sample left.

Current:
Original: left=100, right=0
Paning (100% mono): left=50, right=50

New:
Original: left=100, right=0
Paning (100% mono): left=100, right=100
or
Original: left=100, right=0
Paning (0.7): left=100, right=70

I think the 2nd method would sound more right usualy. Maybe a small
inaccuracy when a mod plays the same sample left and right at the same
time. I think the overall result would still be better though.
But again a boost like pre-amp in eq is probably still the best real world
solution.

---

From: alankila
Date: Tue Apr 25 08:37:46 2006

To: UADE-User-discussion
Hmmh. Well, UADE could be made more advanced by using a panning approach you suggest.

If we lowered UADE's default output level by 6 dB and forbade using effects like panning and headphone together, we could have panning and headphone effects appear to preserve signal volume, at least for certain kind of music. This isn't what you wanted, but it's better than nothing.

We can also probably get to bottom with what's wrong with uade's gain. In the post-processing chain the gain control is already the last step. It seems to be optimistically written in this way:

[code:1:019d8bcb95]
static void gain&#40;int gain_amount, int16_t *sm, int frames&#41;
&#123;
    int i;
    for &#40;i = 0; i &lt; 2 * frames;  i+= 1&#41;
        sm&#91;i&#93; = &#40;sm&#91;i&#93; * gain_amount&#41; &gt;&gt; 8;
&#125;
[/code:1:019d8bcb95]

As can be seen, the code is optimistic assuming that no clipping may occur.. But it probably does clip for you if you say that uade with even a small gain sounds bad. In this case, we don't observe clipping but more like total waveform distortion, and this is probably why UADE restricts gain between 0 and 1. I suppose shd has been overzealous in not wasting CPU cycles for doing redundant things like checking for overflow. ;-)

But you are right about this: I don't agree with allowing clipping. Even slight clipping usually sounds horrible, and I hate it considering that we have this 96 dB dynamic range, and Amiga music rarely uses more than some two-thirds of that. So we can safely reduce gain and preserve fiedelity, and it is the right thing to do.

A compromise position is thus:

* allow people who want to shoot themselves at the foot to let them by increasing gain above 1
* reduce output level by 6 dB by default, requiring a gain of 2 without post-processing effects to obtain current situation
* forbid using panning and headphone together
* redefine panning to mean &quot;the original signal plust parts of the other channel&quot; rather than &quot;reduce current channel and blend in the other channel in the 'headroom' thus obtained&quot;.

The upshot of this design is:

* uade sounds quieter by default
* turning on panning or headphone will not appear to diminish volume for many kinds of music, but volume may in fact increase for mono effects
* allow gain to distort output if user so chooses

Joker would likely use a gain of 2 after this. Hopefully not more, though. It is up to shd or mld to comment on this proposal. Don't hold your breath.[/code]

---

From: shd
Date: Tue Apr 25 14:19:54 2006

To: UADE-User-discussion
[quote:a1a8f8a308="alankila"]
I mostly use uade123 frontend. It seems to be buggy these days, the CVS version seems to ignore -G for gain and -P for pan, and doesn't even support recursive mode anymore either. Perhaps I should check out audacious, it seems nobody else is using the command-line nowadays.
[/quote:a1a8f8a308]

Just don't file any bug reports so that they won't get fixed. The refactoring at 2006-04-14 broke effects and recursive mode, it seems. I don't use those options so I didn't notice. Sorry. Checkout CVS now.

uade123 is uades primary frontend btw.

---

From: shd
Date: Tue Apr 25 14:21:27 2006

To: UADE-User-discussion
[quote:8bfba45360="shd"][quote:8bfba45360="alankila"]
I mostly use uade123 frontend. It seems to be buggy these days, the CVS version seems to ignore -G for gain and -P for pan, and doesn't even support recursive mode anymore either. Perhaps I should check out audacious, it seems nobody else is using the command-line nowadays.
[/quote:8bfba45360]

uade123 is uades primary frontend btw.[/quote:8bfba45360]

btw. running 'make feclean' is advisable after checkout. (feclean forces rebuild of frontends)

---

From: shd
Date: Tue Apr 25 15:44:11 2006

To: UADE-User-discussion
[quote:26ee5a7783="Joker"]
The &quot;gain&quot; option seems to happen at a too early stage because even
a value of &quot;1.1&quot; gives me nasty clipping and i'd need at least a value
of &quot;3&quot; to get the volume i need which matches all the other players.
[/quote:26ee5a7783]

It's at the last stage. What you experienced was lack of overflow checking. Overflow checking is now in the latest CVS version.

---

From: shd
Date: Tue Apr 25 15:49:48 2006

To: UADE-User-discussion
[quote:6c0c6dac21="shd"][quote:6c0c6dac21="Joker"]
The &quot;gain&quot; option seems to happen at a too early stage because even
a value of &quot;1.1&quot; gives me nasty clipping and i'd need at least a value
of &quot;3&quot; to get the volume i need which matches all the other players.
[/quote:6c0c6dac21]

It's at the last stage. What you experienced was lack of overflow checking. Overflow checking is now in the latest CVS version.[/quote:6c0c6dac21]

oops. there was a bug in the overflow thing. Thanks to alankila for noticing. Fixed now.

---

From: Joker
Date: Wed Apr 26 15:33:25 2006

To: UADE-User-discussion
If you really consider making UADE more quiet by default my request did
more harm than anything else.

For the best overall result the default output should be roughly the same
as the one from other players.

Since the click noise is now gone i can use as gain of 2.5 or so. The
only negative impact i can imagine is that the gain brings the signal
to clip and postproc later lowers the volume again but the harm done
by cliping would remain. I did not hear any of those effects yet which
could mean my ears are not good enough or it doesn't happen. Maybe
you limit at the end. I don't know but it sounds fine now.

Better ignore my request then and don't consider workarounds which
makes it worse for other people. I'd also dislike if you couldn't mix
paning and headphone anymore.

---

From: Joker
Date: Thu Apr 27 00:53:12 2006

To: UADE-User-discussion
After some tests i've set the value for gain to 2 which is a reasonable
value with my paning and filter options.

I've compared output signal with when i use the sinus tone generator
plugin and make sure uade doesnt reach that absolute max value.

I know in theory i could still hit cliping. Probably when an Amiga MOD
plays the same sample at max. possible volume on all 4 channels.
(well maybe my &quot;copy to other channel&quot; instead of plain &quot;paning&quot;
could handle that saner than hard gain but thats a theoretical thing)
That's a compromise i'm willing to accept when casualy listening
multiple formats in a huge mixed playlist, because it didn't cause
problems during the time i've tested various sounds.

Overall it seems the real issue i hit was that overflow check.
So thanks alot for ajdusting that :-D

---

From: alankila
Date: Thu Apr 27 14:10:13 2006

To: UADE-User-discussion
Well, if this is an acceptable compromise, fine. If you are making a software for others to use, I would recommend you to produce an UI option to have a gain of 1, though.

It indeed requires at least 2 channels blasting at maximum volume to have clipping occur with gain of two, but it will occur, and it will harm chip music where it's quite common to have large pulse waveforms (or somesuch) going on all channels simultaneously.

You will probably not hit it very much for normal music, though. It's a sad fact of life that it may be required to &quot;overdrive&quot; the gain a bit in order to not appear quieter to the other players though... Blame it on the faults of channel-based, unmastered music. The problem would be worse if we had more than 4 channels to deal with, because of the headroom required for each channel under pessimistic assumptions. I wonder if guys who made Intuitracker or Fasttracker 2 or like dedicated any time at this problem, and maybe had a solution. Perhaps a global gain stored in each file, chosen by the musician. For Amiga, we can be almost certain it didn't occur to anyone.

We can circumvent this through a song database where a gain is chosen based on the maximum peak of the song. This would then equalize volumes to the degree they are equalizable, without a hit in sound quality or dynamic range, or change in the module formats to store this data in. Everybody wins.

---

From: Joker
Date: Thu Apr 27 18:21:03 2006

To: UADE-User-discussion
An additional field in the contentdb sounds like a nice idea. Even more
reason to move the contentdb creation from the frontends into the
core.
song.conf is also a good way to manualy change values for special
tunes. Since all this stuff is optional it shouldn't have any negative impact.

---

From: shd
Date: Fri Apr 28 00:04:00 2006

To: UADE-User-discussion
[quote:def9bd3d40="Joker"]An additional field in the contentdb sounds like a nice idea. Even more
reason to move the contentdb creation from the frontends into the
core.[/quote:def9bd3d40]
You have a wrong definition of the word &quot;core&quot;. Core is the emulator part of uade, which can not be directly called from frontends. All frontends, however, do share lots of common code, and contentdb handling is in that common code. See src/frontends/common/eagleplayer.c.

---

From: Joker
Date: Fri Apr 28 13:27:52 2006

To: UADE-User-discussion
Ok ok good nitpicking :-)

I meant the common code which is used for all frontends. So that contentdb
gets written by uade123 xmms-uade audacious-uade and whatever plugin
or player gets added in future.

---

From: Joker
Date: Fri Apr 28 13:31:07 2006

To: UADE-User-discussion
What i really meant in this case is that uade123 should also write contendb entries.

---

From: shd
Date: Sat Apr 29 14:37:53 2006

To: UADE-User-discussion
[quote:a458cd65b6="Joker"]
song.conf is also a good way to manualy change values for special
tunes.[/quote:a458cd65b6]

It's now possible to set gain value for each eagleplayer separately. song.conf and eagleplayer.conf options have been unified. You could have:
[code:1:a458cd65b6]FutureComposer1.4       prefixes=fc,fc14,fc4    gain=2
[/code:1:a458cd65b6]