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
impl Master
Sourcepub const fn new() -> Self
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.
Sourcepub fn set_sfx(&mut self, sfx: Ratio)
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));Sourcepub fn set_music(&mut self, music: Ratio)
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);Sourcepub const fn scale_level(&self, level: i16) -> i16
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 rangeSourcepub fn set_duck_rates(&mut self, attack: u16, release: u16)
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);Sourcepub fn step_duck(&mut self, target: u16)
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);Sourcepub const fn duck_gain_q12(&self) -> u16
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);Sourcepub const fn duck_settled(&self, target: u16) -> bool
pub const fn duck_settled(&self, target: u16) -> bool
Has the duck reached target?
assert!(Master::new().duck_settled(4096));Sourcepub const fn music_level_q15(&self) -> i16
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§
impl Copy for Master
impl Eq for Master
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 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)