Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Curve

Enum Curve 

Source
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: i16

Level at and inside start.

§start: i32

Distance the fall-off begins at.

§slope: u16

Level 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: u8

Fixed-point shift for slope; below 32.

§floor: i16

Lowest 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.

Fields

§peak: i16

Level at distance zero.

§unit: i32

Distance of the half-level point.

§

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.

Fields

§step_shift: u8

log2 of the segment length.

§pts: [u16; 17]

Levels at the segment boundaries.

§

Flat(i16)

The same level at any distance.

Implementations§

Source§

impl Curve

Source

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.

Source

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));
Source

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);
Source

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);
Source

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);
Source

pub const fn wipeout_crowd() -> Self

WipEout’s crowd law: 0x2FFF - 4 * d.

assert_eq!(Curve::wipeout_crowd().level(1000), 0x2FFF - 4000);
Source

pub const fn inverse(peak: i16, unit: i32) -> Self

The inverse-distance law with its half-level point at unit.

assert_eq!(Curve::inverse(8000, 300).level(300), 4000);
Source

pub fn level(&self, dist: i32) -> i16

The level at distance dist.

assert_eq!(Curve::Flat(500).level(12345), 500);

Trait Implementations§

Source§

impl Clone for Curve

Source§

fn clone(&self) -> Curve

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Curve

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Curve

Source§

fn eq(&self, other: &Curve) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Curve

Source§

impl Eq for Curve

Source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.