From: Takashi Iwai Subject: Re: [RFC] TLV entry for linear volume Date: Mon, 28 Aug 2006 12:00:25 +0200 Message-ID: References: <44EC6F16.6090807@superbug.co.uk> <44EC9CED.8040408@superbug.co.uk> <44ECE949.9010207@superbug.co.uk> <44EF24E0.3080802@superbug.co.uk> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <44EF24E0.3080802@superbug.co.uk> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@lists.sourceforge.net Errors-To: alsa-devel-bounces@lists.sourceforge.net To: James Courtier-Dutton Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Fri, 25 Aug 2006 17:27:12 +0100, James Courtier-Dutton wrote: > > Takashi Iwai wrote: > > At Thu, 24 Aug 2006 11:16:45 +0200, > > I wrote: > > > >> The difference between us is just how to express and pass the > >> coefficeints. My suggestion is to pass the values given in the > >> datasheet as they are, min and max dB. > >> > > > > The below is the latest version I have on my local tree. > > It's against HG tree. > > > > > > Takashi > > > +#ifndef HAVE_SOFT_FLOAT > + case SND_CTL_TLVT_DB_LINEAR: { > + int mindb = rec->db_info[2]; > + int maxdb = rec->db_info[3]; > Maybe I am unclear about what rec->min is, but I though that it was the > lowest value the volume(old % scale) could be. > So, what exactly is this section trying to do? Just handling error cases? > + if (volume <= rec->min || rec->max <= rec->min) > + *db_gain = mindb; > + else if (volume >= rec->max) > + *db_gain = maxdb; > + else { Yes. The edge condition is also a special case that you can handle easily. > > This makes sense. (part A), when combined with (part B) > + double val = (double)(volume - rec->min) / > + (double)(rec->max - rec->min); > > This special case is for when mindb = negative infinity. > + if (mindb <= SND_CTL_TLV_DB_GAIN_MUTE) > + *db_gain = (long)(100.0 * 20.0 * log10(val)) + > + maxdb; > + else { > > This makes sense. (Part B) when combined with (Part A) > It covers a good general case of mapping (linear_min...linear_max) onto > (dB_min...dB_max) > + /* FIXME: precalculate and cache these values */ > + double lmin = pow(10.0, mindb/20.0); > + double lmax = pow(10.0, maxdb/20.0); > + val = (lmax - lmin) * val + lmin; > + *db_gain = (long)(100.0 * 20.0 * log10(val)); > + } > + } > + return 0; > + } > +#endif > > > Summary, I am happy with this now. Great :) I'll commit the patch later, then. Takashi ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642