7 May
2016
7 May
'16
7:06 a.m.
Jörg Krause wrote:
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:
tlv '00000001000000080000000000000014'
As both min_dB and max_dB can be negative numbers, the tlv type must not be unsigned.
TLVs always are unsigned. But they can contain bit patterns that are to be interpreted as signed.
- 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;
The problem is that conversion of a negative floating-point number into an unsigned integer results in undefined behaviour, and on your architecture (whatever it is), this results in zero.
The correct way to handle this would be something like this:
tlv[i] = (int)(...);
Regards, Clemens