pub enum Curve {
Ramp {
peak: i16,
start: i32,
slope: u16,
shift: u8,
floor: i16,
},
Hyper {
peak: i16,
unit: i32,
},
Table {
step_shift: u8,
pts: [u16; 17],
},
Flat(i16),
}Expand description
Distance to level.
The level domain is the SPU’s own, so the output of
level can go straight into a PanLaw and then to the
chip. dist is the distance after the world shift, 0 or more.
§Example
use psx_sfx::space::Curve;
let c = Curve::linear_clip(10000, 1000);
assert_eq!(c.level(0), 10000);
assert!(c.level(500).abs_diff(5000) <= 8);
assert_eq!(c.level(1000), 0);
assert_eq!(c.level(5000), 0);Variants§
Ramp
peak - (max(d - start, 0) * slope >> shift), clamped to
floor..=peak. The shape of Quake, GoldSrc and WipEout attenuation.
Fields
peak: i16Level at and inside start.
start: i32Distance the fall-off begins at.
slope: u16Level lost per unit of distance, in units of 1 / 2^shift. Sixteen
bits so the product with a distance (under 2^15) cannot overflow
and needs no saturating multiply, which on the R3000 is a library
call.
shift: u8Fixed-point shift for slope; below 32.
floor: i16Lowest level the curve returns.
Hyper
peak * unit / (unit + d): the inverse-distance law, one divide.
unit is the distance at which the level has halved; keep it under
131071 so the product fits i32.
Table
Sixteen linear segments of 2^step_shift distance units, no divide.
pts[i] is the level at i << step_shift; past the last point the
level stays at pts[16]. step_shift is at most 14.
Flat(i16)
The same level at any distance.
Implementations§
Source§impl Curve
impl Curve
Sourcepub const fn linear_clip(peak: i16, clip: i32) -> Self
pub const fn linear_clip(peak: i16, clip: i32) -> Self
A ramp from peak that reaches silence at distance clip, with the
slope computed once at construction.
assert_eq!(Curve::linear_clip(8000, 2000).level(0), 8000);
assert_eq!(Curve::linear_clip(8000, 2000).level(2000), 0);The slope is held in 16 bits, so clips under 256 units fall off at the steepest slope there is (the level is gone in 256 units) rather than at their true rate. Distances are in the curve’s own units after the world shift, so a clip that short is a shift away from being useful anyway.
Sourcepub const fn attenuated(peak: i16, attn_milli: u32) -> Self
pub const fn attenuated(peak: i16, attn_milli: u32) -> Self
The Quake and GoldSrc law: peak * (1 - d * attn / 1000), so silence at
1000 / attn units. attn_milli is the attenuation in thousandths;
0 is “no attenuation” and gives a Curve::Flat.
// Attenuation 2.0: silent at 500 units.
assert_eq!(Curve::attenuated(8000, 2000).level(500), 0);
assert_eq!(Curve::attenuated(8000, 0), Curve::Flat(8000));Sourcepub const fn quake(attn: Attn, peak: i16) -> Self
pub const fn quake(attn: Attn, peak: i16) -> Self
Quake S_Spatialize’s distance scale for an attenuation class.
assert_eq!(Curve::quake(Attn::Idle, 8000).level(500), 0);Sourcepub const fn goldsrc(peak: i16, attn_milli: u32) -> Self
pub const fn goldsrc(peak: i16, attn_milli: u32) -> Self
GoldSrc’s linear gain. attn_milli is the attenuation in thousandths
(GOLDSRC_NORM, GOLDSRC_IDLE, GOLDSRC_STATIC, or any other);
0 is ATTN_NONE.
// ATTN_NORM 0.8: silent at 1250 units.
assert_eq!(Curve::goldsrc(8000, GOLDSRC_NORM).level(1250), 0);Sourcepub const fn wipeout() -> Self
pub const fn wipeout() -> Self
WipEout’s one-shot law: 0x2FFF - d, with d in the game’s own
eighth-of-a-unit distance.
assert_eq!(Curve::wipeout().level(1000), 0x2FFF - 1000);Sourcepub const fn wipeout_crowd() -> Self
pub const fn wipeout_crowd() -> Self
WipEout’s crowd law: 0x2FFF - 4 * d.
assert_eq!(Curve::wipeout_crowd().level(1000), 0x2FFF - 4000);Trait Implementations§
impl Copy for Curve
impl Eq for Curve
impl StructuralPartialEq for Curve
Auto Trait Implementations§
impl Freeze for Curve
impl RefUnwindSafe for Curve
impl Send for Curve
impl Sync for Curve
impl Unpin for Curve
impl UnsafeUnpin for Curve
impl UnwindSafe for Curve
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)