]> git.alsa-project.org Git - alsa-lib.git/commit
tlv: Handle 'holes' in SND_CTL_TLVT_DB_RANGE array
authorPeter Ujfalusi <peter.ujfalusi@nokia.com>
Tue, 20 Jul 2010 07:34:53 +0000 (10:34 +0300)
committerTakashi Iwai <tiwai@suse.de>
Tue, 20 Jul 2010 10:55:51 +0000 (12:55 +0200)
commitd81ce4ea7af917f992aa0529c29db590d566ae7a
tree936d6806be1489e4469073afdb218d3d0dcd92a4
parent16a2cad39b7ee29e34b92d39d72eebfc88f8dc22
tlv: Handle 'holes' in SND_CTL_TLVT_DB_RANGE array

When converting from dB to raw value, and DB_RANGE is
used with non overlapping map, dB value in between the
sub ranges will be not found.

For example, if the control has the following:
0: -10dB
1: -5dB
2: 0dB
3: 2dB
4: 4dB

static const unsigned int nonoverlapping_tlv[] = {
        TLV_DB_RANGE_HEAD(2),
        0, 2, TLV_DB_SCALE_ITEM(-1000, 500, 0),
        3, 4, TLV_DB_SCALE_ITEM(200, 200, 0),
};

Range 1: -10 .. 0dB
Range 2: 2 .. 4dB

If user asks for 1dB the snd_tlv_convert_from_dB will not find
the raw value, since the 1dB is not part of either range.

To fix this, we will store the previous non maching range's
maximum raw value. If the dB value is not found in the next range,
we will check, if the requested dB value is in between the current
and the previous range, and if it is than pick the apropriate raw
value based on the xdir (up or down rounding).

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/control/tlv.c