All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain
@ 2018-04-18 15:03 Ricard Wanderlof
  2018-04-20  7:34 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Ricard Wanderlof @ 2018-04-18 15:03 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: alsa-devel


The gain algorithm used in softvol can handle gain factors of up to
32767 which is slightly more than 90 dB, so allow a max_dB of 90 dB.
This doesn't affect existing asound.conf files, but does allow a
max_dB of up to 90 dB when needed.

Tested using Audacity that there is no undue distorsion or other
artefacts when 90 dB of gain is applied to a suitable signal (i.e.
a signal quiet enough not be clipped whan applying 90 dB of gain).

Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
---

I discussed this with Takashi and Jaroslav back in January, but the 
discussion petered out and didn't reach a conclusion on which maximum gain 
would be acceptable, so I thought I'd send an actual patch and we can take 
it from here.

We have a couple of usecases where we are using digital microphones, which 
have 24 bit resolution, and with an acoustic overload point of about 120 
dB SPL, the output level can be quite low when the sound source is a fair 
distance form the microphone. The current softvol limit of 50 dB is 
therefore a bit restrictive.

When studying the code, it becomes apparent that the limit of the actual 
gain function is a gain factor of 32767, which corresponds to 90.3 dB. So 
it makes sense to set the MAX_DB_UPPER_LIMIT (whose only function is to 
cause _snd_pcm_softvol_open() to bail out and emit an error message if the 
gain is set higher than this limit) to 90 dB as it corresponds to the 
technical limitations of the gain algorithm. Granted, 90 dB is probably 
more than most people need, but there's no real harm in allowing a large 
gain; the user gain limit in a given application is still set by the 
max_dB parameter in asound.conf . The worst that can happen is that the 
signal becomes clipped as would happen with any signal if the applied gain 
drives it over 0 dB. If in fact a signal is close to 0 dB to start with, 
then the resulting clipping when increased by 90 dB is not much worse than 
when increased by 50 dB.

 src/pcm/pcm_softvol.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c
index 8bb4a39..0eaeace 100644
--- a/src/pcm/pcm_softvol.c
+++ b/src/pcm/pcm_softvol.c
@@ -59,7 +59,11 @@ typedef struct {
 #define PRESET_RESOLUTION	256
 #define PRESET_MIN_DB		-51.0
 #define ZERO_DB                  0.0
-#define MAX_DB_UPPER_LIMIT      50
+/*
+ * The gain algorithm as it stands supports gain factors up to 32767, which
+ * is a fraction more than 90 dB, so set 90 dB as the maximum possible gain.
+ */
+#define MAX_DB_UPPER_LIMIT      90
 
 static const unsigned int preset_dB_value[PRESET_RESOLUTION] = {
 	0x00b8, 0x00bd, 0x00c1, 0x00c5, 0x00ca, 0x00cf, 0x00d4, 0x00d9,
-- 
2.1.4

-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain
  2018-04-18 15:03 [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain Ricard Wanderlof
@ 2018-04-20  7:34 ` Takashi Iwai
  2018-04-23  9:51   ` Ricard Wanderlof
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2018-04-20  7:34 UTC (permalink / raw)
  To: Ricard Wanderlof; +Cc: alsa-devel

On Wed, 18 Apr 2018 17:03:09 +0200,
Ricard Wanderlof wrote:
> 
> 
> The gain algorithm used in softvol can handle gain factors of up to
> 32767 which is slightly more than 90 dB, so allow a max_dB of 90 dB.
> This doesn't affect existing asound.conf files, but does allow a
> max_dB of up to 90 dB when needed.
> 
> Tested using Audacity that there is no undue distorsion or other
> artefacts when 90 dB of gain is applied to a suitable signal (i.e.
> a signal quiet enough not be clipped whan applying 90 dB of gain).
> 
> Signed-off-by: Ricard Wanderlof <ricardw@axis.com>
> ---
> 
> I discussed this with Takashi and Jaroslav back in January, but the 
> discussion petered out and didn't reach a conclusion on which maximum gain 
> would be acceptable, so I thought I'd send an actual patch and we can take 
> it from here.

Ah, this ended up to null just because I went to my vacation...

> We have a couple of usecases where we are using digital microphones, which 
> have 24 bit resolution, and with an acoustic overload point of about 120 
> dB SPL, the output level can be quite low when the sound source is a fair 
> distance form the microphone. The current softvol limit of 50 dB is 
> therefore a bit restrictive.
> 
> When studying the code, it becomes apparent that the limit of the actual 
> gain function is a gain factor of 32767, which corresponds to 90.3 dB. So 
> it makes sense to set the MAX_DB_UPPER_LIMIT (whose only function is to 
> cause _snd_pcm_softvol_open() to bail out and emit an error message if the 
> gain is set higher than this limit) to 90 dB as it corresponds to the 
> technical limitations of the gain algorithm. Granted, 90 dB is probably 
> more than most people need, but there's no real harm in allowing a large 
> gain; the user gain limit in a given application is still set by the 
> max_dB parameter in asound.conf . The worst that can happen is that the 
> signal becomes clipped as would happen with any signal if the applied gain 
> drives it over 0 dB. If in fact a signal is close to 0 dB to start with, 
> then the resulting clipping when increased by 90 dB is not much worse than 
> when increased by 50 dB.

Honestly speaking, I still don't like to change something just because
the number can reach.  But this is a minor issue and if any damage
happens, it can be said to be self-responsibility, so I applied as
is.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain
  2018-04-20  7:34 ` Takashi Iwai
@ 2018-04-23  9:51   ` Ricard Wanderlof
  0 siblings, 0 replies; 3+ messages in thread
From: Ricard Wanderlof @ 2018-04-23  9:51 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel


On Fri, 20 Apr 2018, Takashi Iwai wrote:

> > When studying the code, it becomes apparent that the limit of the actual 
> > gain function is a gain factor of 32767, which corresponds to 90.3 dB. So 
> > ...

> Honestly speaking, I still don't like to change something just because
> the number can reach.  But this is a minor issue and if any damage
> happens, it can be said to be self-responsibility, so I applied as
> is.

Thanks Takashi!

I agree that 90 dB might be excessive, but at any rate I couldn't think 
of a logical motivation for any particular lower value in this case.

/Ricard
-- 
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-23  9:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 15:03 [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain Ricard Wanderlof
2018-04-20  7:34 ` Takashi Iwai
2018-04-23  9:51   ` Ricard Wanderlof

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.