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

Master

Struct Master 

Source
pub struct Master { /* private fields */ }
Expand description

Effects and music master volumes plus the music duck.

§Example

use psx_sfx::master::{Master, Ratio};

let mut m = Master::new();
m.set_sfx(Ratio::new(1, 2));
assert_eq!(m.scale_level(8000), 4000);

// A protected sound asks for the music to drop to a quarter, then lets go.
m.set_duck_rates(1024, 128);
m.step_duck(1024);
assert_eq!(m.duck_gain_q12(), 3072);

Implementations§

Source§

impl Master

Source

pub const fn new() -> Self

Everything at unity, no duck, a duck that moves the whole range in one tick until set_duck_rates says otherwise.

Source

pub fn set_sfx(&mut self, sfx: Ratio)

Set the effects master.

let mut m = Master::new();
m.set_sfx(Ratio::new(7, 10));
assert_eq!(m.sfx(), Ratio::new(7, 10));
Source

pub fn set_music(&mut self, music: Ratio)

Set the music master.

let mut m = Master::new();
m.set_music(Ratio::MUTE);
assert_eq!(m.music_level_q15(), 0);
Source

pub const fn sfx(&self) -> Ratio

The effects master.

Source

pub const fn music(&self) -> Ratio

The music master.

Source

pub const fn scale_level(&self, level: i16) -> i16

Scale one signed SPU level by the effects master and clamp it to the range the chip accepts.

let mut m = Master::new();
m.set_sfx(Ratio::new(3, 2));
assert_eq!(m.scale_level(10000), 15000);
assert_eq!(m.scale_level(12000), 0x3FFF); // clamped to the chip's range
Source

pub fn set_duck_rates(&mut self, attack: u16, release: u16)

How fast the duck moves, in Q12 gain per tick: attack when the music is being pulled down, release when it is coming back.

let mut m = Master::new();
m.set_duck_rates(2048, 256);
m.step_duck(0);
assert_eq!(m.duck_gain_q12(), 2048);
Source

pub fn step_duck(&mut self, target: u16)

Move the duck one tick toward target (Q12; 4096 is no duck). Mixer::tick calls this with the deepest duck any live sound is asking for.

let mut m = Master::new(); // rates default to the whole range per tick
m.step_duck(1000);
assert_eq!(m.duck_gain_q12(), 1000);
m.step_duck(4096);
assert_eq!(m.duck_gain_q12(), 4096);
Source

pub const fn duck_gain_q12(&self) -> u16

The current duck gain, Q12 (4096 = music at full level).

assert_eq!(Master::new().duck_gain_q12(), 4096);
Source

pub const fn duck_settled(&self, target: u16) -> bool

Has the duck reached target?

assert!(Master::new().duck_settled(4096));
Source

pub const fn music_level_q15(&self) -> i16

The music level to write to the CD volume register: the music master times the duck, as signed Q15 (0x7FFF is full scale).

let mut m = Master::new();
m.set_music(Ratio::new(1, 2));
assert_eq!(m.music_level_q15(), 0x3FFF);

Trait Implementations§

Source§

impl Clone for Master

Source§

fn clone(&self) -> Master

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 Master

Source§

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

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

impl Default for Master

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Master

Source§

fn eq(&self, other: &Master) -> 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 Master

Source§

impl Eq for Master

Source§

impl StructuralPartialEq for Master

Auto Trait Implementations§

§

impl Freeze for Master

§

impl RefUnwindSafe for Master

§

impl Send for Master

§

impl Sync for Master

§

impl Unpin for Master

§

impl UnsafeUnpin for Master

§

impl UnwindSafe for Master

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.