From: Takashi Iwai Subject: Re: [RFC] TLV entry for linear volume Date: Wed, 23 Aug 2006 19:09:25 +0200 Message-ID: References: <44EC6F16.6090807@superbug.co.uk> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Wed_Aug_23_19:09:25_2006-1" Return-path: In-Reply-To: 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 --Multipart_Wed_Aug_23_19:09:25_2006-1 Content-Type: text/plain; charset=US-ASCII At Wed, 23 Aug 2006 17:31:10 +0200, I wrote: > > > So, 0 dB is when (volume - rec->min) / (max - min) == 1 > > So, for +6 dB gain, the volume will need to be higher than max? > > Does this sound right? In that case, maybe "max" is not a good name for > > it because volume can be greater than max. > > Hm, right, I didn't think of overload case with a linear volume > codec. By min and max, I thought of a "segment" between mute and > 0dB (although not implemented rightly in alsa-lib). > > Maybe min and max should be in (0.01) dB expressions since the min and > max "values" are known from snd_ctl_elem_info. The only problem is > that we have no standard definition of "mute" in dB expression. > In alsa-lib, -9999999 indicates mute. But it should be defined as a > constant in a public header. It turned out that minimal dB makes the computation too complicated, and chips are very likely from mute to a certain dB. So, I decided to drop the min dB there. The below are the revised patches. Takashi --Multipart_Wed_Aug_23_19:09:25_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="tlv-linear-kernel2.diff" Content-Transfer-Encoding: 7bit diff -r 2df0d1a21cc9 include/tlv.h --- a/include/tlv.h Wed Aug 23 18:35:35 2006 +0200 +++ b/include/tlv.h Wed Aug 23 18:56:49 2006 +0200 @@ -33,6 +33,7 @@ #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */ #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */ +#define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */ #define DECLARE_TLV_DB_SCALE(name, min, step, mute) \ unsigned int name[] = { \ @@ -40,4 +41,11 @@ unsigned int name[] = { \ (min), ((step) & 0xffff) | ((mute) ? 0x10000 : 0) \ } +/* linear volume between mute - max_dB (.01dB) */ +#define DECLARE_TLV_DB_LINEAR(name, max_dB) \ +unsigned int name[] = { \ + SNDRV_CTL_TLVT_DB_LINEAR, sizeof(unsigned int), \ + (max_dB) \ +} + #endif /* __SOUND_TLV_H */ --Multipart_Wed_Aug_23_19:09:25_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="tlv-linear-lib2.diff" Content-Transfer-Encoding: 7bit diff -r 2728d2269be9 include/control.h --- a/include/control.h Wed Aug 23 15:44:09 2006 +0200 +++ b/include/control.h Wed Aug 23 15:44:23 2006 +0200 @@ -170,6 +170,8 @@ typedef enum _snd_ctl_event_type { #define SND_CTL_TLVT_CONTAINER 0x0000 /** TLV type - basic dB scale */ #define SND_CTL_TLVT_DB_SCALE 0x0001 +/** TLV type - linear volume */ +#define SND_CTL_TLVT_DB_LINEAR 0x0002 /** CTL type */ typedef enum _snd_ctl_type { diff -r 2728d2269be9 src/mixer/simple_none.c --- a/src/mixer/simple_none.c Wed Aug 23 15:44:09 2006 +0200 +++ b/src/mixer/simple_none.c Wed Aug 23 18:59:43 2006 +0200 @@ -1014,6 +1014,9 @@ static int parse_db_range(struct selem_s } break; case SND_CTL_TLVT_DB_SCALE: +#ifndef HAVE_SOFT_FLOAT + case SND_CTL_TLVT_DB_LINEAR: +#endif rec->db_info = malloc(size + sizeof(int) * 2); if (! rec->db_info) return -ENOMEM; @@ -1027,20 +1030,39 @@ static int parse_db_range(struct selem_s /* convert the given raw volume value to a dB gain */ + +#define MIN_DB_GAIN -9999999 /* should be in the public header? */ + static int convert_db_range(struct selem_str *rec, long volume, long *db_gain) { - int min, step, mute; - switch (rec->db_info[0]) { - case SND_CTL_TLVT_DB_SCALE: + case SND_CTL_TLVT_DB_SCALE: { + int min, step, mute; min = rec->db_info[2]; step = (rec->db_info[3] & 0xffff); mute = (rec->db_info[3] >> 16) & 1; if (mute && volume == rec->min) - *db_gain = -9999999; + *db_gain = MIN_DB_GAIN; else *db_gain = (volume - rec->min) * step + min; return 0; + } +#ifndef HAVE_SOFT_FLOAT + case SND_CTL_TLVT_DB_LINEAR: { + int maxdb = rec->db_info[2]; + if (volume <= rec->min) + *db_gain = MIN_DB_GAIN; + else if (rec->max <= rec->min) + *db_gain = maxdb; + else { + *db_gain = (long)(100.0 * 20.0 * + log10((double)(volume - rec->min) / + (double)(rec->max - rec->min))); + *db_gain += maxdb; + } + return 0; + } +#endif } return -EINVAL; } --Multipart_Wed_Aug_23_19:09:25_2006-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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 --Multipart_Wed_Aug_23_19:09:25_2006-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Alsa-devel mailing list Alsa-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-devel --Multipart_Wed_Aug_23_19:09:25_2006-1--