mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
tlv: implement nearest rounding in snd_tlv_convert_from_dB() for xdir == 0
We should round-up values to nearest to get more precise results. BugLink: https://github.com/alsa-project/alsa-utils/issues/35 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
d39f5acd9b
commit
d54fde85db
2 changed files with 20 additions and 7 deletions
|
|
@ -286,7 +286,8 @@ int snd_tlv_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,
|
||||||
* \param db_gain the dB gain to convert (in 0.01dB unit)
|
* \param db_gain the dB gain to convert (in 0.01dB unit)
|
||||||
* \param value the pointer to store the converted raw volume value
|
* \param value the pointer to store the converted raw volume value
|
||||||
* \param xdir the direction for round-up. The value is round up
|
* \param xdir the direction for round-up. The value is round up
|
||||||
* when this is positive.
|
* when this is positive. A negative value means round down.
|
||||||
|
* Zero means round-up to nearest.
|
||||||
* \return 0 if successful, or a negative error code
|
* \return 0 if successful, or a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
||||||
|
|
@ -346,6 +347,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
||||||
long v = (db_gain - min) * (rangemax - rangemin);
|
long v = (db_gain - min) * (rangemax - rangemin);
|
||||||
if (xdir > 0)
|
if (xdir > 0)
|
||||||
v += (max - min) - 1;
|
v += (max - min) - 1;
|
||||||
|
else if (xdir == 0)
|
||||||
|
v += ((max - min) + 1) / 2;
|
||||||
v = v / (max - min) + rangemin;
|
v = v / (max - min) + rangemin;
|
||||||
*value = v;
|
*value = v;
|
||||||
}
|
}
|
||||||
|
|
@ -368,6 +371,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
||||||
long v = (db_gain - min) * (rangemax - rangemin);
|
long v = (db_gain - min) * (rangemax - rangemin);
|
||||||
if (xdir > 0)
|
if (xdir > 0)
|
||||||
v += (max - min) - 1;
|
v += (max - min) - 1;
|
||||||
|
else if (xdir == 0)
|
||||||
|
v += ((max - min) + 1) / 2;
|
||||||
v = v / (max - min) + rangemin;
|
v = v / (max - min) + rangemin;
|
||||||
*value = v;
|
*value = v;
|
||||||
}
|
}
|
||||||
|
|
@ -392,6 +397,8 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
||||||
v = (v - vmin) * (rangemax - rangemin) / (vmax - vmin);
|
v = (v - vmin) * (rangemax - rangemin) / (vmax - vmin);
|
||||||
if (xdir > 0)
|
if (xdir > 0)
|
||||||
v = ceil(v);
|
v = ceil(v);
|
||||||
|
else if (xdir == 0)
|
||||||
|
v = lrint(v);
|
||||||
*value = (long)v + rangemin;
|
*value = (long)v + rangemin;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,8 @@ int snd_mixer_selem_ask_playback_vol_dB(snd_mixer_elem_t *elem, long value, long
|
||||||
* \brief Return corresponding integer playback volume for given dB value for a mixer simple element
|
* \brief Return corresponding integer playback volume for given dB value for a mixer simple element
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param value value to be converted to dB range
|
* \param value value to be converted to dB range
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \param dBvalue pointer to returned dB value
|
* \param dBvalue pointer to returned dB value
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
|
|
@ -454,7 +455,8 @@ int snd_mixer_selem_set_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param channel mixer simple element channel identifier
|
* \param channel mixer simple element channel identifier
|
||||||
* \param value control value in dB * 100
|
* \param value control value in dB * 100
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir)
|
int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir)
|
||||||
|
|
@ -491,7 +493,8 @@ int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t *elem, long value)
|
||||||
* \brief Set value in dB of playback volume control for all channels of a mixer simple element
|
* \brief Set value in dB of playback volume control for all channels of a mixer simple element
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param value control value in dB * 100
|
* \param value control value in dB * 100
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir)
|
int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir)
|
||||||
|
|
@ -706,7 +709,8 @@ int snd_mixer_selem_ask_capture_vol_dB(snd_mixer_elem_t *elem, long value, long
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param dBvalue dB value to be converted to integer range
|
* \param dBvalue dB value to be converted to integer range
|
||||||
* \param value pointer to returned integer value
|
* \param value pointer to returned integer value
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_mixer_selem_ask_capture_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value)
|
int snd_mixer_selem_ask_capture_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value)
|
||||||
|
|
@ -777,7 +781,8 @@ int snd_mixer_selem_set_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_c
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param channel mixer simple element channel identifier
|
* \param channel mixer simple element channel identifier
|
||||||
* \param value control value in dB * 100
|
* \param value control value in dB * 100
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir)
|
int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir)
|
||||||
|
|
@ -814,7 +819,8 @@ int snd_mixer_selem_set_capture_volume_all(snd_mixer_elem_t *elem, long value)
|
||||||
* \brief Set value in dB of capture volume control for all channels of a mixer simple element
|
* \brief Set value in dB of capture volume control for all channels of a mixer simple element
|
||||||
* \param elem Mixer simple element handle
|
* \param elem Mixer simple element handle
|
||||||
* \param value control value in dB * 100
|
* \param value control value in dB * 100
|
||||||
* \param dir rounding mode - rounds up if dir > 0, otherwise rounds down
|
* \param dir rounding mode - rounds up if dir > 0, round to nearest if dir == 0,
|
||||||
|
* rounds down if dir < 0
|
||||||
* \return 0 on success otherwise a negative error code
|
* \return 0 on success otherwise a negative error code
|
||||||
*/
|
*/
|
||||||
int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir)
|
int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue