All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] TLV entry for linear volume
@ 2006-08-23 13:52 Takashi Iwai
  2006-08-23 15:07 ` James Courtier-Dutton
  0 siblings, 1 reply; 11+ messages in thread
From: Takashi Iwai @ 2006-08-23 13:52 UTC (permalink / raw)
  To: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

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

[-- Attachment #2: tlv-linear-kernel.diff --]
[-- Type: application/octet-stream, Size: 733 bytes --]

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 */

[-- Attachment #3: tlv-linear-lib.diff --]
[-- Type: application/octet-stream, Size: 1915 bytes --]

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;
 }

[-- Attachment #4: Type: text/plain, Size: 373 bytes --]

-------------------------------------------------------------------------
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

[-- Attachment #5: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-08-28 10:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-23 13:52 [RFC] TLV entry for linear volume Takashi Iwai
2006-08-23 15:07 ` James Courtier-Dutton
2006-08-23 15:31   ` Takashi Iwai
2006-08-23 17:09     ` Takashi Iwai
2006-08-23 18:22       ` James Courtier-Dutton
2006-08-23 18:34         ` Takashi Iwai
2006-08-23 23:48           ` James Courtier-Dutton
2006-08-24  9:16             ` Takashi Iwai
2006-08-25 10:23               ` Takashi Iwai
2006-08-25 16:27                 ` James Courtier-Dutton
2006-08-28 10:00                   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.