diff options
| author | HiFiPHile <[email protected]> | 2026-08-27 03:31:01 +0200 |
|---|---|---|
| committer | HiFiPHile <[email protected]> | 2026-08-27 10:34:34 +0200 |
| commit | 178426720cbe2f170872cc1469329570d37726a3 (patch) | |
| tree | a6b280b93ff8a4861065624c8761665a823bd4a0 /src/class/audio/audio_host.c | |
| parent | 6019e538125e9863a4fa4bcf0b026d3e639a1a4d (diff) | |
audio: normalize Feature Unit volume requests
Accept the defined silence value and round ordinary volume requests to the nearest supported resolution step within the cached range. Add tests for silence, clamping, and step alignment.
Signed-off-by: HiFiPHile <[email protected]>
Diffstat (limited to 'src/class/audio/audio_host.c')
| -rw-r--r-- | src/class/audio/audio_host.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/class/audio/audio_host.c b/src/class/audio/audio_host.c index ad2fd677f..c73e9f225 100644 --- a/src/class/audio/audio_host.c +++ b/src/class/audio/audio_host.c @@ -2592,7 +2592,16 @@ bool tuh_audio_volume_set(uint8_t idx, uint8_t stream_idx, int16_t volume, tuh_x uintptr_t user_data) { tuh_audio_volume_range_t range; TU_VERIFY(tuh_audio_volume_range_get(idx, stream_idx, &range), false); - TU_VERIFY(volume >= range.min && volume <= range.max, false); + if (volume != TUH_AUDIO_VOLUME_SILENCE) { + TU_VERIFY(volume >= range.min && volume <= range.max && range.res != 0, false); + const uint32_t offset = (uint32_t)((int32_t)volume - range.min); + const uint32_t steps = (offset + range.res / 2u) / range.res; + int32_t rounded = (int32_t)range.min + (int32_t)(steps * range.res); + if (rounded > range.max) { + rounded -= range.res; + } + volume = (int16_t)rounded; + } return tuh_audio_feature_unit_set(idx, stream_idx, AUDIO10_FU_CTRL_VOLUME, 0, (uint16_t)volume, complete_cb, user_data); } |
