[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#748124: kmix: Volume in kmix not equal to alsamixer (logarithmic scale / "mapped volume" should be used)



Package: kmix
Version: 4:4.12.2-2
Severity: important

Dear Maintainer,

Starting with 4.10, kmix has incorrect volume regulation for me. I.e. it adjusts the volume linearly, while the correct behaviour is to adjust it logarithmically (in dB...). So the volume scale is incorrect, very unintuitive and the volume level isn't equal to alsamixer's. I use plain ALSA. I DON'T use PulseAudio and DON'T want to use it, because PA is a totally useless Lennart creation, wrapper around ALSA. I don't use network streaming, bluetooth etc, I just want to have sound coming from my speakers. (with PA this bug also doesn't reproduce)

I personally solve this problem on my machines by by applying the patch (attached) which makes kmix use mapped volume. But I've already reported this bug to KDE bugtracker - https://bugs.kde.org/show_bug.cgi?id=331582 - and they say KMix never used the logarithmic / dB values! So this is probably not a kmix issue!

Both machines on which the bug does reproduce run Debian unstable i386, both aren't a fresh installation - I continuosly upgrade them since debian 4.0 etch. So maybe the bug is somehow related to ALSA setup on Debian? If so, the single alsa-related upgrade on my machine was libasound2 1.0.27.2-1 -> 1.0.27.2-3, happened 2014-01-03... As I remember that was somewhere around when it broke the first time... And the previous update happened 2013-07-16, 1.0.27.1-2 -> 1.0.27.2-1, and everything was OK...

-- System Information:
Debian Release: jessie/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (x86_64)
Foreign Architectures: amd64

Kernel: Linux 3.12-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages kmix depends on:
ii  kde-runtime              4:4.12.4-1
ii  libasound2               1.0.27.2-3
ii  libc6                    2.18-5
ii  libcanberra0             0.30-2
ii  libkdecore5              4:4.12.4-1
ii  libkdeui5                4:4.12.4-1
ii  libplasma3               4:4.12.4-1
ii  libpulse-mainloop-glib0  5.0-2
ii  libpulse0                5.0-2
ii  libqt4-dbus              4:4.8.6+dfsg-1
ii  libqt4-xml               4:4.8.6+dfsg-1
ii  libqtcore4               4:4.8.6+dfsg-1
ii  libqtgui4                4:4.8.6+dfsg-1
ii  libsolid4                4:4.12.4-1
ii  libstdc++6               4.9.0-3

kmix recommends no packages.

kmix suggests no packages.

-- no debconf information
diff -NaurpBb kmix-4.10.4/backends/mixer_alsa9.cpp kmix-4.10.4-mapped-volume/backends/mixer_alsa9.cpp
--- kmix-4.10.4/backends/mixer_alsa9.cpp	2013-05-28 23:31:29.000000000 +0400
+++ kmix-4.10.4-mapped-volume/backends/mixer_alsa9.cpp	2013-07-07 02:42:46.459072815 +0400
@@ -43,6 +43,8 @@
 #include <assert.h>
 #include <qsocketnotifier.h>
 
+#include "volume_mapping.h"
+
 //#include "core/mixer.h"
 //class Mixer;
 
@@ -407,6 +409,7 @@ void Mixer_ALSA::addEnumerated(snd_mixer
    }
 }
 
+#define MAP_VOL_RES ((unsigned long)((long)-1) / 100)
 
 Volume* Mixer_ALSA::addVolume(snd_mixer_elem_t *elem, bool capture)
 {
@@ -415,10 +418,12 @@ Volume* Mixer_ALSA::addVolume(snd_mixer_
 
     // Add volumes
     if ( !capture && snd_mixer_selem_has_playback_volume(elem) ) {
-        snd_mixer_selem_get_playback_volume_range( elem, &minVolume, &maxVolume );
+        minVolume = 0;
+        maxVolume = MAP_VOL_RES;
     }
     else if ( capture && snd_mixer_selem_has_capture_volume(elem) ) {
-       snd_mixer_selem_get_capture_volume_range( elem, &minVolume, &maxVolume );
+        minVolume = 0;
+        maxVolume = MAP_VOL_RES;
     }
 
 
@@ -735,15 +740,15 @@ Mixer_ALSA::readVolumeFromHW( const QStr
         {
                int ret = 0;
                switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol); break;
+                   case Volume::LEFT         : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  ); break;
+                   case Volume::RIGHT        : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT ); break;
+                   case Volume::CENTER       : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER); break;
+                   case Volume::SURROUNDLEFT : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   ); break;
+                   case Volume::SURROUNDRIGHT: vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  ); break;
+                   case Volume::REARCENTER   : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER ); break;
+                   case Volume::WOOFER       : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_WOOFER      ); break;
+                   case Volume::REARSIDELEFT : vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   ); break;
+                   case Volume::REARSIDERIGHT: vol = MAP_VOL_RES * get_normalized_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  ); break;
                    default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
               }
               if ( ret != 0 )
@@ -771,15 +776,15 @@ Mixer_ALSA::readVolumeFromHW( const QStr
 		{
                int ret = 0;
                switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , &vol); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , &vol); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, &vol); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , &vol); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , &vol); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , &vol); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , &vol); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , &vol); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_get_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , &vol);     break;
+                   case Volume::LEFT         : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  ); break;
+                   case Volume::RIGHT        : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT ); break;
+                   case Volume::CENTER       : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER); break;
+                   case Volume::SURROUNDLEFT : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   ); break;
+                   case Volume::SURROUNDRIGHT: vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  ); break;
+                   case Volume::REARCENTER   : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER ); break;
+                   case Volume::WOOFER       : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_WOOFER      ); break;
+                   case Volume::REARSIDELEFT : vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   ); break;
+                   case Volume::REARSIDERIGHT: vol = MAP_VOL_RES * get_normalized_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  ); break;
                    default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
               }
               if ( ret != 0 ) kDebug() << "readVolumeFromHW(" << devnum << ") [get_capture_volume] failed, errno=" << ret;
@@ -856,15 +861,15 @@ Mixer_ALSA::writeVolumeToHW( const QStri
                int ret = 0;
                switch(vc.chid)
                {
-                   case Volume::LEFT         : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
+                   case Volume::LEFT         : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::RIGHT        : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::CENTER       : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::SURROUNDLEFT : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::SURROUNDRIGHT: ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::REARCENTER   : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_REAR_CENTER , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::WOOFER       : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_WOOFER      , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::REARSIDELEFT : ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::REARSIDERIGHT: ret = set_normalized_playback_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , (double)vc.volume / MAP_VOL_RES, 0 ); break;
                    default: kDebug() << "FATAL: Unknown channel type for playback << " << vc.chid << " ... please report this";  break;
               }
               if ( ret != 0 )
@@ -883,15 +888,15 @@ Mixer_ALSA::writeVolumeToHW( const QStri
       {
                int ret = 0;
                switch(vc.chid) {
-                   case Volume::LEFT         : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , vc.volume); break;
-                   case Volume::RIGHT        : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , vc.volume); break;
-                   case Volume::CENTER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, vc.volume); break;
-                   case Volume::SURROUNDLEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , vc.volume); break;
-                   case Volume::SURROUNDRIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , vc.volume); break;
-                   case Volume::REARCENTER   : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , vc.volume); break;
-                   case Volume::WOOFER       : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , vc.volume); break;
-                   case Volume::REARSIDELEFT : ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , vc.volume); break;
-                   case Volume::REARSIDERIGHT: ret = snd_mixer_selem_set_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , vc.volume); break;
+                   case Volume::LEFT         : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_LEFT  , (double)vc.volume / MAP_VOL_RES, 0 ); break;
+                   case Volume::RIGHT        : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_RIGHT , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::CENTER       : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_FRONT_CENTER, (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::SURROUNDLEFT : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_LEFT   , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::SURROUNDRIGHT: ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_RIGHT  , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::REARCENTER   : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_REAR_CENTER , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::WOOFER       : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_WOOFER      , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::REARSIDELEFT : ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_SIDE_LEFT   , (double)vc.volume / MAP_VOL_RES, 0); break;
+                   case Volume::REARSIDERIGHT: ret = set_normalized_capture_volume( elem, SND_MIXER_SCHN_SIDE_RIGHT  , (double)vc.volume / MAP_VOL_RES, 0); break;
                    default: kDebug() << "FATAL: Unknown channel type for capture << " << vc.chid << " ... please report this";  break;
               }
               if ( ret != 0 ) kDebug() << "writeVolumeToHW(" << devnum << ") [set_capture_volume] failed, errno=" << ret;
diff -NaurpBb kmix-4.10.4/backends/volume_mapping.cpp kmix-4.10.4-mapped-volume/backends/volume_mapping.cpp
--- kmix-4.10.4/backends/volume_mapping.cpp	1970-01-01 03:00:00.000000000 +0300
+++ kmix-4.10.4-mapped-volume/backends/volume_mapping.cpp	2013-07-07 02:30:34.395050999 +0400
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2010 Clemens Ladisch <clemens@ladisch.de>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * The functions in this file map the value ranges of ALSA mixer controls onto
+ * the interval 0..1.
+ *
+ * The mapping is designed so that the position in the interval is proportional
+ * to the volume as a human ear would perceive it (i.e., the position is the
+ * cubic root of the linear sample multiplication factor).  For controls with
+ * a small range (24 dB or less), the mapping is linear in the dB values so
+ * that each step has the same size visually.  Only for controls without dB
+ * information, a linear mapping of the hardware volume register values is used
+ * (this is the same algorithm as used in the old alsamixer).
+ *
+ * When setting the volume, 'dir' is the rounding direction:
+ * -1/0/1 = down/nearest/up.
+ */
+
+#define _ISOC99_SOURCE /* lrint() */
+#define _GNU_SOURCE /* exp10() */
+#include <math.h>
+#include "volume_mapping.h"
+
+#ifdef __UCLIBC__
+/* 10^x = 10^(log e^x) = (e^x)^log10 = e^(x * log 10) */
+#define exp10(x) (exp((x) * log(10)))
+#endif /* __UCLIBC__ */
+
+#define MAX_LINEAR_DB_SCALE	24
+
+#define use_linear_dB_scale(dBmin, dBmax) (dBmax - dBmin <= MAX_LINEAR_DB_SCALE * 100)
+
+static long lrint_dir(double x, int dir)
+{
+	if (dir > 0)
+		return lrint(ceil(x));
+	else if (dir < 0)
+		return lrint(floor(x));
+	else
+		return lrint(x);
+}
+
+enum ctl_dir { PLAYBACK, CAPTURE };
+
+static int (* const get_dB_range[2])(snd_mixer_elem_t *, long *, long *) = {
+	snd_mixer_selem_get_playback_dB_range,
+	snd_mixer_selem_get_capture_dB_range,
+};
+static int (* const get_raw_range[2])(snd_mixer_elem_t *, long *, long *) = {
+	snd_mixer_selem_get_playback_volume_range,
+	snd_mixer_selem_get_capture_volume_range,
+};
+static int (* const get_dB[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long *) = {
+	snd_mixer_selem_get_playback_dB,
+	snd_mixer_selem_get_capture_dB,
+};
+static int (* const get_raw[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long *) = {
+	snd_mixer_selem_get_playback_volume,
+	snd_mixer_selem_get_capture_volume,
+};
+static int (* const set_dB[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long, int) = {
+	snd_mixer_selem_set_playback_dB,
+	snd_mixer_selem_set_capture_dB,
+};
+static int (* const set_raw[2])(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, long) = {
+	snd_mixer_selem_set_playback_volume,
+	snd_mixer_selem_set_capture_volume,
+};
+
+static double get_normalized_volume(snd_mixer_elem_t *elem,
+				    snd_mixer_selem_channel_id_t channel,
+				    enum ctl_dir ctl_dir)
+{
+	long min, max, value;
+	double normalized, min_norm;
+	int err;
+
+	err = get_dB_range[ctl_dir](elem, &min, &max);
+	if (err < 0 || min >= max) {
+		err = get_raw_range[ctl_dir](elem, &min, &max);
+		if (err < 0 || min == max)
+			return 0;
+
+		err = get_raw[ctl_dir](elem, channel, &value);
+		if (err < 0)
+			return 0;
+
+		return (value - min) / (double)(max - min);
+	}
+
+	err = get_dB[ctl_dir](elem, channel, &value);
+	if (err < 0)
+		return 0;
+
+	if (use_linear_dB_scale(min, max))
+		return (value - min) / (double)(max - min);
+
+	normalized = exp10((value - max) / 6000.0);
+	if (min != SND_CTL_TLV_DB_GAIN_MUTE) {
+		min_norm = exp10((min - max) / 6000.0);
+		normalized = (normalized - min_norm) / (1 - min_norm);
+	}
+
+	return normalized;
+}
+
+static int set_normalized_volume(snd_mixer_elem_t *elem,
+				 snd_mixer_selem_channel_id_t channel,
+				 double volume,
+				 int dir,
+				 enum ctl_dir ctl_dir)
+{
+	long min, max, value;
+	double min_norm;
+	int err;
+
+	err = get_dB_range[ctl_dir](elem, &min, &max);
+	if (err < 0 || min >= max) {
+		err = get_raw_range[ctl_dir](elem, &min, &max);
+		if (err < 0)
+			return err;
+
+		value = lrint_dir(volume * (max - min), dir) + min;
+		return set_raw[ctl_dir](elem, channel, value);
+	}
+
+	if (use_linear_dB_scale(min, max)) {
+		value = lrint_dir(volume * (max - min), dir) + min;
+		return set_dB[ctl_dir](elem, channel, value, dir);
+	}
+
+	if (min != SND_CTL_TLV_DB_GAIN_MUTE) {
+		min_norm = exp10((min - max) / 6000.0);
+		volume = volume * (1 - min_norm) + min_norm;
+	}
+	value = lrint_dir(6000.0 * log10(volume), dir) + max;
+	return set_dB[ctl_dir](elem, channel, value, dir);
+}
+
+double get_normalized_playback_volume(snd_mixer_elem_t *elem,
+				      snd_mixer_selem_channel_id_t channel)
+{
+	return get_normalized_volume(elem, channel, PLAYBACK);
+}
+
+double get_normalized_capture_volume(snd_mixer_elem_t *elem,
+				     snd_mixer_selem_channel_id_t channel)
+{
+	return get_normalized_volume(elem, channel, CAPTURE);
+}
+
+int set_normalized_playback_volume(snd_mixer_elem_t *elem,
+				   snd_mixer_selem_channel_id_t channel,
+				   double volume,
+				   int dir)
+{
+	return set_normalized_volume(elem, channel, volume, dir, PLAYBACK);
+}
+
+int set_normalized_capture_volume(snd_mixer_elem_t *elem,
+				  snd_mixer_selem_channel_id_t channel,
+				  double volume,
+				  int dir)
+{
+	return set_normalized_volume(elem, channel, volume, dir, CAPTURE);
+}
diff -NaurpBb kmix-4.10.4/backends/volume_mapping.h kmix-4.10.4-mapped-volume/backends/volume_mapping.h
--- kmix-4.10.4/backends/volume_mapping.h	1970-01-01 03:00:00.000000000 +0300
+++ kmix-4.10.4-mapped-volume/backends/volume_mapping.h	2013-07-07 02:31:22.015052418 +0400
@@ -0,0 +1,19 @@
+#ifndef VOLUME_MAPPING_H_INCLUDED
+#define VOLUME_MAPPING_H_INCLUDED
+
+#include <alsa/asoundlib.h>
+
+double get_normalized_playback_volume(snd_mixer_elem_t *elem,
+				      snd_mixer_selem_channel_id_t channel);
+double get_normalized_capture_volume(snd_mixer_elem_t *elem,
+				     snd_mixer_selem_channel_id_t channel);
+int set_normalized_playback_volume(snd_mixer_elem_t *elem,
+				   snd_mixer_selem_channel_id_t channel,
+				   double volume,
+				   int dir);
+int set_normalized_capture_volume(snd_mixer_elem_t *elem,
+				  snd_mixer_selem_channel_id_t channel,
+				  double volume,
+				  int dir);
+
+#endif
diff -NaurpBb kmix-4.10.4/CMakeLists.txt kmix-4.10.4-mapped-volume/CMakeLists.txt
--- kmix-4.10.4/CMakeLists.txt	2013-05-28 23:31:29.000000000 +0400
+++ kmix-4.10.4-mapped-volume/CMakeLists.txt	2013-07-07 02:31:54.371053383 +0400
@@ -67,7 +67,7 @@ set(kmix_backend_SRCS
 
 if (HAVE_LIBASOUND2)
   set(kmix_backend_SRCS ${kmix_backend_SRCS}
-      backends/mixer_alsa9.cpp )
+      backends/mixer_alsa9.cpp backends/volume_mapping.cpp)
 endif (HAVE_LIBASOUND2)
 
 if (PULSEAUDIO_FOUND)

Attachment: kmix_vol1.png
Description: Binary data

Attachment: kmix_vol2.png
Description: Binary data

Attachment: kmix_vol3.png
Description: Binary data


Reply to: