Skip to contentSkip to conversation

dB range compound

RFC In review Takashi Iwai 2 participants 5 messages Sep 1, 2006 – Sep 5, 2006

lore
Share & tools
lore
#0 lore raw

RFC 1/1 dB range compound

Hi,

I found that some hardwares require the combination of dB scale ranges. For example, es1938 has volume controls with two curves, e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the values 8-15.

The patch below introduces a new TLV type, DB_RANGE, to implement the compound dB scales. It can contain one or more child TLVs, together with min and max values for each.

The first patch is for the kernel and the second for alsa-lib.

Any comments?

Takashi

include/tlv.h +15 -8
diff -r a42a910c5302 include/tlv.h
@@ -34,19 +34,26 @@
 #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 SNDRV_CTL_TLVT_DB_RANGE 3	/* dB range container */
 
+#define TLV_DB_SCALE_ITEM(min, step, mute)			\
+	SNDRV_CTL_TLVT_DB_SCALE, 2 * sizeof(unsigned int),	\
+	(min), ((step) & 0xffff) | ((mute) ? 0x10000 : 0)
 #define DECLARE_TLV_DB_SCALE(name, min, step, mute) \
-unsigned int name[] = { \
-        SNDRV_CTL_TLVT_DB_SCALE, 2 * sizeof(unsigned int), \
-        (min), ((step) & 0xffff) | ((mute) ? 0x10000 : 0) \
-}
+	unsigned int name[] = { TLV_DB_SCALE_ITEM(min, step, mute) }
 
 /* linear volume between min_dB and max_dB (.01dB unit) */
+#define TLV_DB_LINEAR_ITEM(min_dB, max_dB)		    \
+	SNDRV_CTL_TLVT_DB_LINEAR, 2 * sizeof(unsigned int), \
+	(min_dB), (max_dB)
 #define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB)	\
-unsigned int name[] = { \
-        SNDRV_CTL_TLVT_DB_LINEAR, 2 * sizeof(unsigned int), \
-        (min_dB), (max_dB)				\
-}
+	unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) }
+
+/* dB range container */
+/* Each item is: <min> <max> <TLV> */
+/* The below assumes that each item TLV is 4 words like DB_SCALE or LINEAR */
+#define TLV_DB_RANGE_HEAD(num)			\
+	SNDRV_CTL_TLVT_DB_RANGE, 6 * (num) * sizeof(unsigned int)
 
 #define TLV_DB_GAIN_MUTE	-9999999
 
pci/es1938.c +86 -17

147 lines not on this page · raw message

include/control.h +2 -0
diff -r 0c766669b691 include/control.h
@@ -172,6 +172,8 @@ typedef enum _snd_ctl_event_type {
 #define SND_CTL_TLVT_DB_SCALE		0x0001
 /** TLV type - linear volume */
 #define SND_CTL_TLVT_DB_LINEAR		0x0002
+/** TLV type - dB range container */
+#define SND_CTL_TLVT_DB_RANGE		0x0003
 
 /** Mute state */
 #define SND_CTL_TLV_DB_GAIN_MUTE	-9999999
src/mixer/simple_none.c +133 -52

275 lines not on this page · raw message

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

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#1 lore raw
Quoted 11 lines · Takashi Iwai

Hi,

I found that some hardwares require the combination of dB scale ranges. For example, es1938 has volume controls with two curves, e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the values 8-15.

The patch below introduces a new TLV type, DB_RANGE, to implement the compound dB scales. It can contain one or more child TLVs, together with min and max values for each.

Quoted 7 lines

The first patch is for the kernel and the second for alsa-lib.

Any comments?

Takashi

+static int do_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,
+ long volume, long *db_gain)
+{
+ switch (tlv[0]) {
+ case SND_CTL_TLVT_DB_RANGE: {
+ unsigned int pos, len;
+ len = tlv[1] / sizeof(int);
+ pos = 2;

Be careful with this len limit in the while loop. I suggest adding a further comparison to limit the loop to a constant size:
e.g.
while (pos + 4 <= len && (pos + 4 < MAX_BUFFER_SIZE) ) { There are similar cases elsewhere in the patch.

+ while (pos + 4 <= len) {
+ rangemin = (int)tlv[pos];
+ rangemax = (int)tlv[pos + 1];
+ if (volume >= rangemin && volume <= rangemax)
+ return do_convert_to_dB(tlv + pos + 2,
+ rangemin, rangemax,
+ volume, db_gain);
+ pos += tlv[pos + 3] + 4;
+ }
return -EINVAL;

Apart from that, It looks OK to me.

With regard to this control actually being to separate register in the chip, I think it might be nice to implement two separate controls between kernel and alsa-lib, but add some TLV tag to link the two controls together so that they appear as one. This will save code size in the kernel.
For example, with the EMU DSPs one control can do 0 dB to -inf gain, and another can to 0 dB to X gain. I was thinking of implementing these in the emu10k1 module, with special code to link the two at the kernel module level, but it might save code duplication if we let alsa-lib do this task.
We might be able to do a similar link between mic gain and mic boost switches.

James

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

#2 lore raw

At Mon, 04 Sep 2006 13:40:13 +0100,

Quoted 30 lines · James Courtier-Dutton
Quoted 11 lines · Takashi Iwai

Hi,

I found that some hardwares require the combination of dB scale ranges. For example, es1938 has volume controls with two curves, e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the values 8-15.

The patch below introduces a new TLV type, DB_RANGE, to implement the compound dB scales. It can contain one or more child TLVs, together with min and max values for each.

Quoted 7 lines

The first patch is for the kernel and the second for alsa-lib.

Any comments?

Takashi

+static int do_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,

src/mixer/simple_none.c +7 -0
+			    long volume, long *db_gain)
+{
+	switch (tlv[0]) {
+	case SND_CTL_TLVT_DB_RANGE: {
+		unsigned int pos, len;
+		len = tlv[1] / sizeof(int);
+		pos = 2;
Quoted 5 lines

Be careful with this len limit in the while loop. I suggest adding a further comparison to limit the loop to a constant size:
e.g.
while (pos + 4 <= len && (pos + 4 < MAX_BUFFER_SIZE) ) { There are similar cases elsewhere in the patch.

Yes, it'd be safer. Will fix them.

Quoted 13 lines
src/mixer/simple_none.c +9 -0
+		while (pos + 4 <= len) {
+			rangemin = (int)tlv[pos];
+			rangemax = (int)tlv[pos + 1];
+			if (volume >= rangemin && volume <= rangemax)
+				return do_convert_to_dB(tlv + pos + 2,
+							rangemin, rangemax,
+							volume, db_gain);
+			pos += tlv[pos + 3] + 4;
+		}
 		return -EINVAL;
Quoted 7 lines

Apart from that, It looks OK to me.

With regard to this control actually being to separate register in the chip, I think it might be nice to implement two separate controls between kernel and alsa-lib, but add some TLV tag to link the two controls together so that they appear as one. This will save code size in the kernel.

Agreed, this should really depend on the implementation. In the case of es1938, however, it's clearly a single control (just the dB scale curve is non-linear).

Thanks,

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

#3 lore raw

At Mon, 04 Sep 2006 15:31:31 +0200,

Quoted 33 lines · I wrote:

At Mon, 04 Sep 2006 13:40:13 +0100,

Quoted 30 lines · James Courtier-Dutton
Quoted 11 lines · Takashi Iwai

Hi,

I found that some hardwares require the combination of dB scale ranges. For example, es1938 has volume controls with two curves, e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the values 8-15.

The patch below introduces a new TLV type, DB_RANGE, to implement the compound dB scales. It can contain one or more child TLVs, together with min and max values for each.

Quoted 7 lines

The first patch is for the kernel and the second for alsa-lib.

Any comments?

Takashi

+static int do_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,

(quoted diff) +7 -0
+			    long volume, long *db_gain)
+{
+	switch (tlv[0]) {
+	case SND_CTL_TLVT_DB_RANGE: {
+		unsigned int pos, len;
+		len = tlv[1] / sizeof(int);
+		pos = 2;
Quoted 7 lines
Quoted 5 lines

Be careful with this len limit in the while loop. I suggest adding a further comparison to limit the loop to a constant size:
e.g.
while (pos + 4 <= len && (pos + 4 < MAX_BUFFER_SIZE) ) { There are similar cases elsewhere in the patch.

Yes, it'd be safer. Will fix them.

The below is the fixed version.

Takashi

include/control.h +2 -0
diff -r 0c766669b691 include/control.h
@@ -172,6 +172,8 @@ typedef enum _snd_ctl_event_type {
 #define SND_CTL_TLVT_DB_SCALE		0x0001
 /** TLV type - linear volume */
 #define SND_CTL_TLVT_DB_LINEAR		0x0002
+/** TLV type - dB range container */
+#define SND_CTL_TLVT_DB_RANGE		0x0003
 
 /** Mute state */
 #define SND_CTL_TLV_DB_GAIN_MUTE	-9999999
src/mixer/simple_none.c +146 -52

295 lines not on this page · raw message

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

#4 lore raw

At Mon, 04 Sep 2006 20:40:04 +0200,

Quoted 44 lines · I wrote:

At Mon, 04 Sep 2006 15:31:31 +0200,

Quoted 33 lines · I wrote:

At Mon, 04 Sep 2006 13:40:13 +0100,

Quoted 30 lines · James Courtier-Dutton
Quoted 11 lines · Takashi Iwai

Hi,

I found that some hardwares require the combination of dB scale ranges. For example, es1938 has volume controls with two curves, e.g. the volume step in the value 0-8 is 3 dB while it's 1.5 dB in the values 8-15.

The patch below introduces a new TLV type, DB_RANGE, to implement the compound dB scales. It can contain one or more child TLVs, together with min and max values for each.

Quoted 7 lines

The first patch is for the kernel and the second for alsa-lib.

Any comments?

Takashi

+static int do_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,

(quoted diff) +7 -0
+			    long volume, long *db_gain)
+{
+	switch (tlv[0]) {
+	case SND_CTL_TLVT_DB_RANGE: {
+		unsigned int pos, len;
+		len = tlv[1] / sizeof(int);
+		pos = 2;
Quoted 7 lines
Quoted 5 lines

Be careful with this len limit in the while loop. I suggest adding a further comparison to limit the loop to a constant size:
e.g.
while (pos + 4 <= len && (pos + 4 < MAX_BUFFER_SIZE) ) { There are similar cases elsewhere in the patch.

Yes, it'd be safer. Will fix them.

Quoted 1 line

The below is the fixed version.

... and it was buggy. The version below is the correct one.

I'll commit it if no further objection arises.

Takashi

include/control.h +2 -0
diff -r 0c766669b691 include/control.h
@@ -172,6 +172,8 @@ typedef enum _snd_ctl_event_type {
 #define SND_CTL_TLVT_DB_SCALE		0x0001
 /** TLV type - linear volume */
 #define SND_CTL_TLVT_DB_LINEAR		0x0002
+/** TLV type - dB range container */
+#define SND_CTL_TLVT_DB_RANGE		0x0003
 
 /** Mute state */
 #define SND_CTL_TLV_DB_GAIN_MUTE	-9999999
src/mixer/simple_none.c +146 -52

295 lines not on this page · raw message

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