Skip to contentSkip to conversation

TLV question - ranges not in volume order

DISCUSSION David Henningsson 4 participants 7 messages May 8, 2013 – May 10, 2013 Sound

lore
Share & tools
lore
#0 lore raw

Hi,

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below. I believe the numbers correctly match the hardware.

However alsamixer seems not to handle this "reordering" correctly. My question is if this is something that should be fixed in alsamixer (or possibly alsa-lib?), or does one need to write some kind of mapping table in the kernel, just to make something come in volume order to userspace?

Any TLV documentation on what TLVs are valid and invalid is also welcome :-)

static const unsigned int tlv[] = {
        TLV_DB_RANGE_HEAD(8),
        0, 0, TLV_DB_SCALE_ITEM(-100, 0, 1),
        1, 1, TLV_DB_SCALE_ITEM(400, 0, 0),
        2, 2, TLV_DB_SCALE_ITEM(200, 0, 0),
        3, 3, TLV_DB_SCALE_ITEM(1000, 0, 0),
        4, 4, TLV_DB_SCALE_ITEM(0, 0, 0),
        5, 5, TLV_DB_SCALE_ITEM(800, 0, 0),
        6, 6, TLV_DB_SCALE_ITEM(600, 0, 0),
        7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
};
Signature · 2 lines
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
#1 lore raw
Quoted 9 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below.

However alsamixer seems not to handle this "reordering" correctly. My question is if this is something that should be fixed in alsamixer (or possibly alsa-lib?), or does one need to write some kind of mapping table in the kernel, just to make something come in volume order to userspace?

Items in a DB_RANGE container must be ordered by their values *and* by their dB values. This implies that larger values must correspond with larger dB values, whis is also required for all other mixer controls.

If the register values are unordered, the driver must reorder them.

Quoted 2 lines
static const unsigned int tlv[] = {
        TLV_DB_RANGE_HEAD(8),

This should be rewritten as:

static const DECLARE_TLV_DB_RANGE(tlv,

	0, 0, TLV_DB_SCALE_ITEM(-100, 0, 1),
	...

);

Regards,
Clemens

#2 lore raw

At Wed, 08 May 2013 14:09:31 +0200,

Quoted 12 lines · Clemens Ladisch
Quoted 9 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below.

However alsamixer seems not to handle this "reordering" correctly. My question is if this is something that should be fixed in alsamixer (or possibly alsa-lib?), or does one need to write some kind of mapping table in the kernel, just to make something come in volume order to userspace?

Quoted 5 lines

Items in a DB_RANGE container must be ordered by their values *and* by their dB values. This implies that larger values must correspond with larger dB values, whis is also required for all other mixer controls.

If the register values are unordered, the driver must reorder them.

Yep. Although there is no explicit definition, it's an implicit rule, as we have never implemented the parser code to allow the disorder.

We should add a text mentioning that somewhere. A patch is welcome ;)

thanks,

Takashi

#3 lore raw
Quoted 18 lines · Takashi Iwai

At Wed, 08 May 2013 14:09:31 +0200,

Quoted 16 lines · Clemens Ladisch
Quoted 9 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below.

However alsamixer seems not to handle this "reordering" correctly. My question is if this is something that should be fixed in alsamixer (or possibly alsa-lib?), or does one need to write some kind of mapping table in the kernel, just to make something come in volume order to userspace?

Items in a DB_RANGE container must be ordered by their values *and* by their dB values. This implies that larger values must correspond with larger dB values, whis is also required for all other mixer controls.

Quoted 6 lines
Quoted 1 line

If the register values are unordered, the driver must reorder them.

Yep. Although there is no explicit definition, it's an implicit rule, as we have never implemented the parser code to allow the disorder.

We should add a text mentioning that somewhere. A patch is welcome ;)

Like this? (Feel free to apply if you think it's good)

Signature · 2 lines
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
Quoted 1 line

From 19778a06ef5bd995ba1e800dc14bbe7ff27dcb97 Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Wed, 8 May 2013 15:28:49 +0200
Subject: [PATCH] ALSA: Add comment for control TLV API

Userspace is not meant to have to handle all strange dB ranges, so add a specification comment.

---
 include/sound/tlv.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/sound/tlv.h +4 -1
index 28c65e1..84fc31a 100644
@@ -74,7 +74,10 @@
 #define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB)	\
 	unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) }
 
-/* dB range container */
+/* dB range container. Items in dB range container must be ordered
+by their values and by their dB values. This implies that larger values
+must correspond with larger dB values (which is also required for all
+other mixer controls). */
 /* Each item is: <min> <max> <TLV> */
 #define TLV_DB_RANGE_ITEM(...) \
 	TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
Signature · 1 line
1.7.9.5
#4 lore raw

At Wed, 08 May 2013 15:33:11 +0200,

Quoted 21 lines · David Henningsson

[1 <text/plain; ISO-8859-1 (7bit)>]

Quoted 18 lines · Takashi Iwai

At Wed, 08 May 2013 14:09:31 +0200,

Quoted 16 lines · Clemens Ladisch
Quoted 9 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below.

However alsamixer seems not to handle this "reordering" correctly. My question is if this is something that should be fixed in alsamixer (or possibly alsa-lib?), or does one need to write some kind of mapping table in the kernel, just to make something come in volume order to userspace?

Items in a DB_RANGE container must be ordered by their values *and* by their dB values. This implies that larger values must correspond with larger dB values, whis is also required for all other mixer controls.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

If the register values are unordered, the driver must reorder them.

Yep. Although there is no explicit definition, it's an implicit rule, as we have never implemented the parser code to allow the disorder.

We should add a text mentioning that somewhere. A patch is welcome ;)

Like this? (Feel free to apply if you think it's good)

Thanks, I applied it with slight modification (align the comment lines).

Takashi

Quoted 39 lines
Signature · 4 lines
-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
[2 0001-ALSA-Add-comment-for-control-TLV-API.patch <text/x-patch (7bit)>]
Quoted 1 line

From 19778a06ef5bd995ba1e800dc14bbe7ff27dcb97 Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Wed, 8 May 2013 15:28:49 +0200
Subject: [PATCH] ALSA: Add comment for control TLV API

Userspace is not meant to have to handle all strange dB ranges, so add a specification comment.

---
 include/sound/tlv.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/sound/tlv.h +4 -1
index 28c65e1..84fc31a 100644
@@ -74,7 +74,10 @@
 #define DECLARE_TLV_DB_LINEAR(name, min_dB, max_dB)	\
 	unsigned int name[] = { TLV_DB_LINEAR_ITEM(min_dB, max_dB) }
 
-/* dB range container */
+/* dB range container. Items in dB range container must be ordered
+by their values and by their dB values. This implies that larger values
+must correspond with larger dB values (which is also required for all
+other mixer controls). */
 /* Each item is: <min> <max> <TLV> */
 #define TLV_DB_RANGE_ITEM(...) \
 	TLV_ITEM(SNDRV_CTL_TLVT_DB_RANGE, __VA_ARGS__)
Signature · 1 line
1.7.9.5
#5 lore raw
In reply to David Henningsson
Quoted 4 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below. I believe the numbers correctly match the hardware.

Oh, joy. What driver is this?

#6 lore raw
Quoted 8 lines · Mark Brown
Quoted 4 lines · David Henningsson

I recently came across a strange ASoC volume control. In this case, the values are not in volume order, i e, the control is declared something like below. I believe the numbers correctly match the hardware.

Oh, joy. What driver is this?

I think it's not in the mainline kernel at this point.

Signature · 2 lines
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic