* [PATCH] pcm: softvol: fix conversion of TLVs min_db and max_dB value
@ 2016-05-08 18:48 Jörg Krause
2016-05-09 12:52 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Jörg Krause @ 2016-05-08 18:48 UTC (permalink / raw)
To: alsa-devel; +Cc: Jörg Krause, Clemens Ladisch
Both, min_dB and max_dB, are floating type whereas the TLV is (always)
unsigned.
The problem with the conversion of a negative floating-point number into an
unsigned integer is, that the behavior is undefined. This may, depending on
the platform, result in a wrong TLV, i.e. for the default values of min_dB
(-51dB) and max_dB (0dB), alsactl generates the following state on an ARM
cpu build with GCC:
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
}
}
With the fix applied, alsactl stores the correct TLV:
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.
Replaces:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107733.html
Fixes:
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107628.html
Cc: Clemens Ladisch <clemens@ladisch.de>
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..061080d 100644
--- a/src/pcm/pcm_softvol.c
+++ b/src/pcm/pcm_softvol.c
@@ -658,8 +658,8 @@ static int add_tlv_info(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo)
unsigned int tlv[4];
tlv[0] = SND_CTL_TLVT_DB_SCALE;
tlv[1] = 2 * sizeof(int);
- tlv[2] = svol->min_dB * 100;
- tlv[3] = (svol->max_dB - svol->min_dB) * 100 / svol->max_val;
+ tlv[2] = (int)(svol->min_dB * 100);
+ tlv[3] = (int)((svol->max_dB - svol->min_dB) * 100 / svol->max_val);
return snd_ctl_elem_tlv_write(svol->ctl, &cinfo->id, tlv);
}
--
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] 2+ messages in thread
* Re: [PATCH] pcm: softvol: fix conversion of TLVs min_db and max_dB value
2016-05-08 18:48 [PATCH] pcm: softvol: fix conversion of TLVs min_db and max_dB value Jörg Krause
@ 2016-05-09 12:52 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2016-05-09 12:52 UTC (permalink / raw)
To: Jörg Krause; +Cc: alsa-devel, Clemens Ladisch
On Sun, 08 May 2016 20:48:42 +0200,
Jörg Krause wrote:
>
> Both, min_dB and max_dB, are floating type whereas the TLV is (always)
> unsigned.
>
> The problem with the conversion of a negative floating-point number into an
> unsigned integer is, that the behavior is undefined. This may, depending on
> the platform, result in a wrong TLV, i.e. for the default values of min_dB
> (-51dB) and max_dB (0dB), alsactl generates the following state on an ARM
> cpu build with GCC:
>
> 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
> }
> }
>
> With the fix applied, alsactl stores the correct TLV:
>
> 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.
>
> Replaces:
> http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107733.html
>
> Fixes:
> http://mailman.alsa-project.org/pipermail/alsa-devel/2016-May/107628.html
>
> Cc: Clemens Ladisch <clemens@ladisch.de>
> Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
Applied, thanks.
Takashi
> ---
> 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..061080d 100644
> --- a/src/pcm/pcm_softvol.c
> +++ b/src/pcm/pcm_softvol.c
> @@ -658,8 +658,8 @@ static int add_tlv_info(snd_pcm_softvol_t *svol, snd_ctl_elem_info_t *cinfo)
> unsigned int tlv[4];
> tlv[0] = SND_CTL_TLVT_DB_SCALE;
> tlv[1] = 2 * sizeof(int);
> - tlv[2] = svol->min_dB * 100;
> - tlv[3] = (svol->max_dB - svol->min_dB) * 100 / svol->max_val;
> + tlv[2] = (int)(svol->min_dB * 100);
> + tlv[3] = (int)((svol->max_dB - svol->min_dB) * 100 / svol->max_val);
> return snd_ctl_elem_tlv_write(svol->ctl, &cinfo->id, tlv);
> }
>
> --
> 2.8.2
>
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-09 12:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-08 18:48 [PATCH] pcm: softvol: fix conversion of TLVs min_db and max_dB value Jörg Krause
2016-05-09 12:52 ` 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.