From avg@oddity.topspin.kiev.ua  Tue Apr 13 04:48:50 2004
Return-Path: <avg@oddity.topspin.kiev.ua>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BB37216A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Apr 2004 04:48:50 -0700 (PDT)
Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1BB5743D31
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Apr 2004 04:48:49 -0700 (PDT)
	(envelope-from avg@oddity.topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (oddity.topspin.kiev.ua [212.40.38.87])
	by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id OAA00791
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Apr 2004 14:48:43 +0300 (EEST)
	(envelope-from avg@oddity.topspin.kiev.ua)
Received: from oddity.topspin.kiev.ua (localhost [127.0.0.1])
	by oddity.topspin.kiev.ua (8.12.10/8.12.10) with ESMTP id i3DBmhZ2049166
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Apr 2004 14:48:43 +0300 (EEST)
	(envelope-from avg@oddity.topspin.kiev.ua)
Received: (from avg@localhost)
	by oddity.topspin.kiev.ua (8.12.10/8.12.10/Submit) id i3DBmgUF049165
	for FreeBSD-gnats-submit@freebsd.org; Tue, 13 Apr 2004 14:48:42 +0300 (EEST)
	(envelope-from avg)
Message-Id: <200404131117.i3DBH61j048928@oddity.topspin.kiev.ua>
Date: Tue, 13 Apr 2004 14:17:06 +0300 (EEST)
From: Andriy Gapon <avg@icyb.net.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: sb16 mixer: uneven mapping from % volume to absolute volume
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         65485
>Category:       kern
>Synopsis:       sb16 mixer: uneven mapping from % volume to absolute volume
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    josef
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 13 04:50:13 PDT 2004
>Closed-Date:    Mon Jun 14 15:36:02 GMT 2004
>Last-Modified:  Mon Jun 14 15:36:02 GMT 2004
>Originator:     Andriy Gapon
>Release:        FreeBSD 5.2.1-RELEASE-p4 i386
>Organization:
>Environment:
System: FreeBSD x.x.x.x 5.2.1-RELEASE-p4 FreeBSD 5.2.1-RELEASE-p4 #16: Fri Apr 2 20:05:58 EEST 2004 avg i386
any i386 FreeBSD 4.x, 5.x with SB16


	
>Description:
	current function for mapping userland relative volume levels (0-100) to device volume levels looks like this:

left = (left * max) / 100;

this is probably good enough for main or pcm volume where max=31, but is suboptimal for ogain, where max=3, because 0-100 range is virtually split into only 3 subranges instead of possible 4: 
00-33 => 0
34-66 => 1
67-99 => 2
100 => 3

IMHO, something like the following fomula should do better:
abs = [(max+1)*rel/max]*max/100
[] stands fo integer part
>How-To-Repeat:
	
try to regulate ogain and you will see /hear :-)/ that 0-100 range is actually split into 3 subranges and maximum is reached only when volume==100%
>Fix:

	

--- sb16.c.patch begins here ---
--- sb16.c.orig	Tue Apr 13 14:09:46 2004
+++ sb16.c	Tue Apr 13 14:10:03 2004
@@ -326,6 +326,12 @@
 }
 
 static int
+rel2abs_volume(int x, int max)
+{
+	return ((((max + 1) * x) / max) * max) / 100;
+}
+
+static int
 sb16mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
 {
     	struct sb_info *sb = mix_getdevinfo(m);
@@ -335,8 +341,8 @@
 	e = &sb16_mixtab[dev];
 	max = (1 << e->bits) - 1;
 
-	left = (left * max) / 100;
-	right = (right * max) / 100;
+	left = rel2abs_volume(left, max);
+	right = rel2abs_volume(right, max);
 
 	sb_setmixer(sb, e->reg, left << e->ofs);
 	if (e->stereo)
--- sb16.c.patch ends here ---

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->josef 
Responsible-Changed-By: josef 
Responsible-Changed-When: Sun May 16 12:46:46 PDT 2004 
Responsible-Changed-Why:  
i'll handle this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=65485 
State-Changed-From-To: open->closed 
State-Changed-By: josef 
State-Changed-When: Mon Jun 14 15:35:56 GMT 2004 
State-Changed-Why:  
Committed, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=65485 
>Unformatted:
