alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pcm: softvol: fix signedness of tlv data type
@ 2016-05-06 21:08 Jörg Krause
  2016-05-07  7:06 ` Clemens Ladisch
  0 siblings, 1 reply; 3+ messages in thread
From: Jörg Krause @ 2016-05-06 21:08 UTC (permalink / raw)
  To: alsa-devel; +Cc: Jörg Krause

For the softvol plugin the TLV data are written wrong, e.g. for the default values
of min_dB = -51 dB and max_dB = 0 dB, alsactl generates the following state:

	control.1 {
                iface MIXER
                name Master
                value.0 255
                value.1 255
                comment {
                        access 'read write user'
                        type INTEGER
                        count 2
                        range '0 - 255'
                        tlv '00000001000000080000000000000014'
                        dbmin 0
                        dbmax 5100
                        dbvalue.0 5100
                        dbvalue.1 5100
                }
        }

As both min_dB and max_dB can be negative numbers, the tlv type must not be
unsigned. This fixes the TLV and the correct state is generated:

	control.1 {
                iface MIXER
                name Master
                value.0 255
                value.1 255
                comment {
                        access 'read write user'
                        type INTEGER
                        count 2
                        range '0 - 255'
                        tlv '0000000100000008ffffec1400000014'
                        dbmin -5100
                        dbmax 0
                        dbvalue.0 0
                        dbvalue.1 0
                }
        }

Also tested for different combinations of min_dB and max_dB other than the
default values.

Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
---
 src/pcm/pcm_softvol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c
index 802aa4b..1748667 100644
--- a/src/pcm/pcm_softvol.c
+++ b/src/pcm/pcm_softvol.c
@@ -655,7 +655,7 @@ static void snd_pcm_softvol_dump(snd_pcm_t *pcm, snd_output_t *out)
 
 static int add_tlv_info(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo)
 {
-	unsigned int tlv[4];
+	int tlv[4];
 	tlv[0] = SND_CTL_TLVT_DB_SCALE;
 	tlv[1] = 2 * sizeof(int);
 	tlv[2] = svol->min_dB * 100;
@@ -768,7 +768,7 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol,
 			}
 		} else if (svol->max_val > 1) {
 			/* check TLV availability */
-			unsigned int tlv[4];
+			int tlv[4];
 			err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv, sizeof(tlv));
 			if (err < 0)
 				add_tlv_info(svol, cinfo);
-- 
2.8.2

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

end of thread, other threads:[~2016-05-08 18:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-06 21:08 [PATCH] pcm: softvol: fix signedness of tlv data type Jörg Krause
2016-05-07  7:06 ` Clemens Ladisch
2016-05-08 18:18   ` Jörg Krause

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).