Replies: 2 comments 6 replies
-
I honestly don't remember how out-of-bounds values are handled. I think panicking could be appropriate, but only on the calling thread, not the audio thread. Otherwise, I think values should be silently clamped to be in bounds. I'd be happy to accept a PR that does one or both of those! |
Beta Was this translation helpful? Give feedback.
-
Honestly, for my own little case, panicking anywhere is something that I cannot afford because the last thing gamers want is their game crashing while they play. Automatic clamping would be acceptable, but I was actually thinking of something simpler: why not leverage Rust's type system to have invalid values unrepresentable? We could have something like: // ...
pub struct PanningError {
OutOfRange,
}
// ...
pub struct Panning(f32);
impl TryFrom<f32> for Panning {
type Error = PanningError;
fn try_from(value: f32) -> Result<Self, Self::Error> {
if value >= -1.0 && value <= 1.0 {
return Ok(Self(value));
}
Err(PanningError::OutOfRange)
}
}
// more methods ... This way it'd be simply impossible to construct a faulty And, since it's generally annoying to have to panning!(0.1); Let me know what you think, I'm willing to give it a try. |
Beta Was this translation helpful? Give feedback.
-
Hi @tesselode I have a question regarding latest changes in
0.10+
with values that range from-1.0
to1.0
, for example:What happens when the value is out of range ? Does it panic ? Or produce unexpected audio output ? Or simply handles it gracefully inside kira ?
Would you like a PR that revisit these values to make them stricter ?
I'm especially thinking about types and values that implement
Deserialize
where basically inputs can easily be incorrectly set.Beta Was this translation helpful? Give feedback.
All reactions