rodio icon indicating copy to clipboard operation
rodio copied to clipboard

ChannelVolume overflows when using u16 samples

Open Rua opened this issue 5 years ago • 1 comments

When using ChannelVolume with u16 samples, the output is overloaded and clipped. If I print the output samples next to the input ones, it appears that 0x8000 is consistently added to each sample:

7c7c fc7c
8080 ffff
8585 ffff
8787 ffff
8383 ffff
7e7e fe7e
7171 f171
7373 f373
8484 ffff
8181 ffff
8282 ffff
7575 f575
7d7d fd7d
8989 ffff
8f8f ffff

This appears to be done by this code on channel_volume.rs line 90 (similar code also on line 34):

Some(self.current_sample
.get_or_insert_with(|| I::Item::zero_value())
.saturating_add(s));

Since with u16 samples, the zero value is 0x8000, this ends up clipping the upper half of the waveform.

Rua avatar Feb 15 '20 12:02 Rua

Not sure why Sample is implemented for unsigned u16 in the first place, that's weird.

est31 avatar Feb 15 '20 12:02 est31