From alsa-devel-owner@alsa.jcu.cz  Mon May  4 17:30:32 1998
Received: from entry.jcu.cz (perex@entry.jcu.cz [160.217.1.111])
	by marvin.jcu.cz (8.8.8/8.8.8) with SMTP id RAA23517;
	Mon, 4 May 1998 17:29:01 +0200
Date: Mon, 4 May 1998 17:29:01 +0200 (MET DST)
From: Jaroslav Kysela <perex@jcu.cz>
To: Martin Preishuber <Martin.Preishuber@stuco.uni-klu.ac.at>
cc: alsa-devel@alsa.jcu.cz
Subject: Re: mixer settings
In-Reply-To: <354DCF98.B7B35D44@stuco.uni-klu.ac.at>
Message-ID: <Pine.LNX.3.96.980504172611.778H-100000@entry.jcu.cz>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

On Mon, 4 May 1998, Martin Preishuber wrote:

> Hi there,
> 
> I have some problem with the mixer settings ... let's have a look at this
> scenario:
> 
> I have the following mixer settings:
> 
> [preisl@bofh ~]$ cat /proc/sound/0/mixer0
> Mixer 'CTL1745'
> Channel 'Master' 0 31 18 18
> Channel 'Bass' 0 15 14 14
> Channel 'Treble' 0 15 15 15
> Channel 'Synth' 0 31 0 0
> Channel 'PCM' 0 31 28 28
> Channel 'Line-In' 0 31 0 0
> Channel 'MIC' 0 31 0 0
> Channel 'CD' 0 31 0 0
> Channel 'In-Gain' 0 3 2 2
> Channel 'Out-Gain' 0 3 2 2
> Channel 'PC Speaker' 0 3 0 0
> 
> Then I restart the alsa driver using alsasound (former sound.init) ...
> my mp3 player (the sajber jukebox is still running, but not playing).
> then the mixer settings are:
> 
> [preisl@bofh ~]$ cat /proc/sound/0/mixer0
> Mixer 'CTL1745'
> Channel 'Master' 0 31 18 18
> Channel 'Bass' 0 15 14 14
> Channel 'Treble' 0 15 15 15
> Channel 'Synth' 0 31 0 0
> Channel 'PCM' 0 31 28 28
> Channel 'Line-In' 0 31 0 0
> Channel 'MIC' 0 31 0 0
> Channel 'CD' 0 31 0 0
> Channel 'In-Gain' 0 3 2 2
> Channel 'Out-Gain' 0 3 2 2
> Channel 'PC Speaker' 0 3 0 0
> 
> that's ok so far ... but when I move the mouse cursor to the sajber
> jukebox (which gets the focus then), the mixer settings are being changed
> to:
> 
> [preisl@bofh ~]$ cat /proc/sound/0/mixer0
> Mixer 'CTL1745'
> Channel 'Master' 0 31 19 19
> Channel 'Bass' 0 15 15 15
> Channel 'Treble' 0 15 15 15
> Channel 'Synth' 0 31 0 0
> Channel 'PCM' 0 31 29 29
> Channel 'Line-In' 0 31 0 0
> Channel 'MIC' 0 31 0 0
> Channel 'CD' 0 31 0 0
> Channel 'In-Gain' 0 3 2 2
> Channel 'Out-Gain' 0 3 2 2
> Channel 'PC Speaker' 0 3 0 0
> 
> I'm not sure whose fault this is, but that never happened with the
> sound driver included within the kernel ... any ideas what the reason
> for that behaviour is ?

Looks like current rounding algorithm in ALSA driver isn't perfect yet.
I tried modify it in bellow path. Please, report me if this patch helps or
if this patch causes some other problems.

--- mixer.c.old	Mon May  4 16:55:05 1998
+++ mixer.c	Mon May  4 17:02:49 1998
@@ -196,9 +196,9 @@
     device.right_dB = channel -> hw.compute_dB( mixer, channel, channel -> uright );
   } else {
     tmp = channel -> hw.max - channel -> hw.min;
-    device.left_dB = ((((channel -> hw.max_dB - channel -> hw.min_dB) * (channel -> uleft - channel -> hw.min)) + (tmp - 1)) / tmp) + channel -> hw.min_dB;
+    device.left_dB = ((((channel -> hw.max_dB - channel -> hw.min_dB) * (channel -> uleft - channel -> hw.min)) + (tmp >> 1)) / tmp) + channel -> hw.min_dB;
     device.left_dB -= device.left_dB % channel -> hw.step_dB;
-    device.right_dB = ((((channel -> hw.max_dB - channel -> hw.min_dB) * (channel -> uright - channel -> hw.min)) + (tmp - 1)) / tmp) + channel -> hw.min_dB;
+    device.right_dB = ((((channel -> hw.max_dB - channel -> hw.min_dB) * (channel -> uright - channel -> hw.min)) + (tmp >> 1)) / tmp) + channel -> hw.min_dB;
     device.right_dB -= device.right_dB % channel -> hw.step_dB;
   }
   snd_spin_unlock( mixer, lock, &flags );
@@ -264,8 +264,8 @@
       tmp = channel -> hw.max_dB - channel -> hw.min_dB;
       device.left_dB %= channel -> hw.step_dB;
       device.right_dB %= channel -> hw.step_dB;
-      left = ((((channel -> hw.max - channel -> hw.min) * (device.left_dB - channel -> hw.min_dB)) + (tmp - 1)) / tmp) + channel -> hw.min;
-      right = ((((channel -> hw.max - channel -> hw.min) * (device.right_dB - channel -> hw.min_dB)) + (tmp - 1)) / tmp) + channel -> hw.min;
+      left = ((((channel -> hw.max - channel -> hw.min) * (device.left_dB - channel -> hw.min_dB)) + (tmp >> 1)) / tmp) + channel -> hw.min;
+      right = ((((channel -> hw.max - channel -> hw.min) * (device.right_dB - channel -> hw.min_dB)) + (tmp >> 1)) / tmp) + channel -> hw.min;
     }
   }  
   if ( mfile -> exact || (device.flags & SND_MIXER_FLG_DECIBEL) ) {
@@ -274,15 +274,15 @@
     if ( left > channel -> hw.max ) left = channel -> hw.max;
     if ( right > channel -> hw.max ) right = channel -> hw.max;
     tmp = channel -> hw.max - channel -> hw.min;
-    aleft = ( ( 100 * ( left - channel -> hw.min ) ) + ( tmp - 1 ) ) / tmp;
-    aright = ( ( 100 * ( right - channel -> hw.min ) ) + ( tmp - 1 ) ) / tmp;
+    aleft = ( ( 100 * ( left - channel -> hw.min ) ) + ( tmp >> 1 ) ) / tmp;
+    aright = ( ( 100 * ( right - channel -> hw.min ) ) + ( tmp >> 1 ) ) / tmp;
   } else {
     if ( left < 0 ) left = 0;
     if ( right < 0 ) right = 0;
     if ( left > 100 ) left = 100;
     if ( right > 100 ) right = 100;
-    left = ( ( channel -> hw.max * (aleft = left) ) + 99 ) / 100;
-    right = ( ( channel -> hw.max * (aright = right) ) + 99 ) / 100;
+    left = ( ( channel -> hw.max * (aleft = left) ) + 50 ) / 100;
+    right = ( ( channel -> hw.max * (aright = right) ) + 50 ) / 100;
   }
   if ( channel -> aleft != aleft || channel -> aright != aright )
     change = 1;


-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic


