RustAudio / dasp

The fundamentals for Digital Audio Signal Processing. Formerly `sample`.
Other
890 stars 65 forks source link

saturating instead-of/as-well-as unchecked wrapping arithmetic? #39

Open mark-buer opened 8 years ago

mark-buer commented 8 years ago

Should there be variants of sample::[Sample,Frame]::[add_amp,mul_amp] which use saturating arithmetic?

mitchmindtree commented 8 years ago

@mark-buer sorry about the late reply! This sounds like it could be a useful addition. Just to clarify, by saturating do you mean clipping results of addition and multiplication to the minimum and maximum values for each Sample type?

mark-buer commented 8 years ago

by saturating do you mean clipping results of addition and multiplication to the minimum and maximum values for each Sample type?

Yep.

Saturating (clipping) arithmetic seems like a natural choice in certain circumstances.

In a somewhat related topic... I also encountered problems with Rust's checked wrapping arithmetic as used by the current implementations for add_amp etc. For example, Rust panicked when adding two large valued i16 samples together when the library was compiled for debug mode. Thus, I wonder if there is also a need for the library to provide unchecked wrapping arithmetic variants?