kern/65485: sb16 mixer: uneven mapping from % volume to absolute
volume
Andriy Gapon
avg at icyb.net.ua
Tue Apr 13 04:50:15 PDT 2004
>Number: 65485
>Category: kern
>Synopsis: sb16 mixer: uneven mapping from % volume to absolute volume
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Apr 13 04:50:13 PDT 2004
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
More information about the freebsd-bugs
mailing list