Add assertions to ensure parameter ranges are clamped, and add ScalarPan::center().

This commit is contained in:
Nolan Darilek 2022-06-03 11:23:03 -05:00
parent 4f45cb6ee6
commit 14235e0a68

View File

@ -112,6 +112,10 @@ impl ScalarPan {
Self(-1.) Self(-1.)
} }
pub fn center() -> Self {
Self(0.)
}
pub fn right() -> Self { pub fn right() -> Self {
Self(1.) Self(1.)
} }
@ -222,6 +226,8 @@ pub fn update_sound_properties(
looping, looping,
.. ..
} = *sound; } = *sound;
assert!(gain >= 0.);
assert!(pitch >= 0.);
if sound.restart { if sound.restart {
if let Some(generator) = sound.generator.as_mut() { if let Some(generator) = sound.generator.as_mut() {
generator generator
@ -327,6 +333,7 @@ pub fn update_sound_properties(
let distance_ref = distance_ref let distance_ref = distance_ref
.map(|v| **v) .map(|v| **v)
.unwrap_or_else(|| context.default_distance_ref().get().unwrap()); .unwrap_or_else(|| context.default_distance_ref().get().unwrap());
assert!(distance_ref >= 0.);
source source
.distance_ref() .distance_ref()
.set(distance_ref) .set(distance_ref)
@ -334,6 +341,7 @@ pub fn update_sound_properties(
let distance_max = distance_max let distance_max = distance_max
.map(|v| **v) .map(|v| **v)
.unwrap_or_else(|| context.default_distance_max().get().unwrap()); .unwrap_or_else(|| context.default_distance_max().get().unwrap());
assert!(distance_max >= 0.);
source source
.distance_max() .distance_max()
.set(distance_max) .set(distance_max)
@ -341,6 +349,7 @@ pub fn update_sound_properties(
let rolloff = rolloff let rolloff = rolloff
.map(|v| **v) .map(|v| **v)
.unwrap_or_else(|| context.default_rolloff().get().unwrap()); .unwrap_or_else(|| context.default_rolloff().get().unwrap());
assert!(rolloff >= 0.);
source source
.rolloff() .rolloff()
.set(rolloff) .set(rolloff)
@ -348,6 +357,7 @@ pub fn update_sound_properties(
let closeness_boost = closeness_boost let closeness_boost = closeness_boost
.map(|v| **v) .map(|v| **v)
.unwrap_or_else(|| context.default_closeness_boost().get().unwrap()); .unwrap_or_else(|| context.default_closeness_boost().get().unwrap());
assert!(closeness_boost >= 0.);
source source
.closeness_boost() .closeness_boost()
.set(closeness_boost) .set(closeness_boost)
@ -356,6 +366,7 @@ pub fn update_sound_properties(
closeness_boost_distance.map(|v| **v).unwrap_or_else(|| { closeness_boost_distance.map(|v| **v).unwrap_or_else(|| {
context.default_closeness_boost_distance().get().unwrap() context.default_closeness_boost_distance().get().unwrap()
}); });
assert!(closeness_boost_distance >= 0.);
source source
.closeness_boost_distance() .closeness_boost_distance()
.set(closeness_boost_distance) .set(closeness_boost_distance)
@ -365,10 +376,12 @@ pub fn update_sound_properties(
} }
} else if let Some(angular_pan) = angular_pan { } else if let Some(angular_pan) = angular_pan {
if let Some(source) = source.cast_to::<syz::AngularPannedSource>().unwrap() { if let Some(source) = source.cast_to::<syz::AngularPannedSource>().unwrap() {
assert!(angular_pan.azimuth >= 0. && angular_pan.azimuth <= 360.);
source source
.azimuth() .azimuth()
.set(angular_pan.azimuth) .set(angular_pan.azimuth)
.expect("Failed to set azimuth"); .expect("Failed to set azimuth");
assert!(angular_pan.elevation >= -90. && angular_pan.elevation <= 90.);
source source
.elevation() .elevation()
.set(angular_pan.elevation) .set(angular_pan.elevation)
@ -378,6 +391,7 @@ pub fn update_sound_properties(
} }
} else if let Some(scalar_pan) = scalar_pan { } else if let Some(scalar_pan) = scalar_pan {
if let Some(source) = source.cast_to::<syz::ScalarPannedSource>().unwrap() { if let Some(source) = source.cast_to::<syz::ScalarPannedSource>().unwrap() {
assert!(**scalar_pan >= -1. && **scalar_pan <= 1.);
source source
.panning_scalar() .panning_scalar()
.set(**scalar_pan) .set(**scalar_pan)