Subject: Re: eap(4) and ess(4) and mixer volume values
To: None <tech-kern@netbsd.org>
From: Matthias Scheler <tron@zhadum.de>
List: tech-kern
Date: 08/16/2000 11:18:07
On Wed, Aug 16, 2000 at 12:02:03PM +0300, Jukka Marin wrote:
> > That's not so easy. The fix is to use floating point values for the
> > intermediary result. And I can't do that of course inside the kernel.
>
> How about using 32-bit integers with 16 bits as integer part and 16 bits
> of fraction? Multiply (shift left) the incoming byte (or 16-bit word,
> if necessary) value and store the result.. and convert back when necessary.
I found an easier way already:
#define TO_OSSVOL(x) ((((x) * 200 / 255) + 1) >> 1)
#define FROM_OSSVOL(x) (((((x) > 100 ? 100 : (x)) * 510 / 100) + 1) >> 1)
It uses one extra bit of precision which is enough for appropriate rounding.
Kind regards
--
Matthias Scheler http://www.sighardstrasse.de/~tron/