From patchwork Wed Apr 18 15:03:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricard Wanderlof X-Patchwork-Id: 10348367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 051AF60244 for ; Wed, 18 Apr 2018 15:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9FFD20182 for ; Wed, 18 Apr 2018 15:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE5262040D; Wed, 18 Apr 2018 15:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF0A720182 for ; Wed, 18 Apr 2018 15:04:00 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B57F726766E; Wed, 18 Apr 2018 17:03:58 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id D980A26767A; Wed, 18 Apr 2018 17:03:55 +0200 (CEST) Received: from bastet.se.axis.com (bastet.se.axis.com [195.60.68.11]) by alsa0.perex.cz (Postfix) with ESMTP id BAE4726765C for ; Wed, 18 Apr 2018 17:03:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id 4561018482; Wed, 18 Apr 2018 17:03:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id wTTuuEw7ONsq; Wed, 18 Apr 2018 17:03:51 +0200 (CEST) Received: from boulder03.se.axis.com (boulder03.se.axis.com [10.0.8.17]) by bastet.se.axis.com (Postfix) with ESMTPS id 7B4F918475; Wed, 18 Apr 2018 17:03:51 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E9841E060; Wed, 18 Apr 2018 17:03:51 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 381B11E0C8; Wed, 18 Apr 2018 17:03:15 +0200 (CEST) Received: from thoth.se.axis.com (unknown [10.0.2.173]) by boulder03.se.axis.com (Postfix) with ESMTP; Wed, 18 Apr 2018 17:03:15 +0200 (CEST) Received: from XBOX03.axis.com (xbox03.axis.com [10.0.5.17]) by thoth.se.axis.com (Postfix) with ESMTP id 2AE491785; Wed, 18 Apr 2018 17:03:15 +0200 (CEST) Received: from lnxricardw1.se.axis.com (10.0.5.60) by XBOX03.axis.com (10.0.5.17) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 18 Apr 2018 17:03:14 +0200 Date: Wed, 18 Apr 2018 17:03:09 +0200 From: Ricard Wanderlof X-X-Sender: ricardw@lnxricardw1.se.axis.com To: Takashi Iwai , Jaroslav Kysela Message-ID: User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 X-Originating-IP: [10.0.5.60] X-ClientProxiedBy: XBOX01.axis.com (10.0.5.15) To XBOX03.axis.com (10.0.5.17) X-TM-AS-GCONF: 00 Cc: alsa-devel Subject: [alsa-devel] [PATCH] [alsa-lib] pcm: softvol: Allow up to 90 dB of gain X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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,