From: Takashi Iwai Subject: [RFC] TLV entry for linear volume Date: Wed, 23 Aug 2006 15:52:45 +0200 Message-ID: Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Wed_Aug_23_15:52:45_2006-1" Return-path: 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: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Wed_Aug_23_15:52:45_2006-1 Content-Type: text/plain; charset=US-ASCII Hi, some codecs and dsp chips use linear volumes instead of logarithmic one. The patch below adds a new TLV type for such a volume type. In alsa-lib, it's converted to dB on the fly. If no one has objection, I'll push it together with AC97-TLV and other similar patches after 1.0.12 release. Takashi --Multipart_Wed_Aug_23_15:52:45_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="tlv-linear-kernel.diff" Content-Transfer-Encoding: 7bit diff -r d8d32c66f4f5 include/tlv.h --- a/include/tlv.h Wed Aug 23 13:07:19 2006 +0200 +++ b/include/tlv.h Wed Aug 23 12:47:04 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,10 @@ unsigned int name[] = { \ (min), ((step) & 0xffff) | ((mute) ? 0x10000 : 0) \ } +#define DECLARE_TLV_DB_LINEAR(name, min, max) \ +unsigned int name[] = { \ + SNDRV_CTL_TLVT_DB_LINEAR, 2 * sizeof(unsigned int), \ + (min), (max) \ +} + #endif /* __SOUND_TLV_H */ --Multipart_Wed_Aug_23_15:52:45_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="tlv-linear-lib.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 15:53:02 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,38 @@ 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 min, max; + if (volume <= rec->min) + *db_gain = MIN_DB_GAIN; + else { + min = rec->db_info[2]; + max = rec->db_info[3]; + *db_gain = (long)(100.0 * 20.0 * + log10((double)(volume - rec->min) / + (double)(max - min))); + } + return 0; + } +#endif } return -EINVAL; } --Multipart_Wed_Aug_23_15:52:45_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_15:52:45_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_15:52:45_2006-1--