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

OneShot

Struct OneShot 

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

A sample with the settings it should be played at.

Implementations§

Source§

impl OneShot

Source

pub const fn new(sample: Sample, volume: Volume) -> Self

A one-shot at its own recorded rate, under [Adsr::default_tone].

default_tone rather than percussive: percussive self-fades in about 150 ms, which is most of a quarter-second sound. The cutoff, not the envelope, is what stops this.

Source

pub const fn with_volume(self, volume: Volume) -> Self

Play at a different level. For sounds whose loudness depends on what happened – how hard a hit landed, a volume setting – rather than on which sample it is.

Source

pub const fn with_adsr(self, adsr: Adsr) -> Self

Override the envelope.

Source

pub const fn with_pitch(self, pitch: Pitch) -> Self

Play at an explicit pitch instead of the sample’s own rate. 0x1000 is unity; lower stretches the sound and raises how long it lasts, which OneShot::ticks accounts for.

Source

pub const fn sample(&self) -> Sample

The sample behind this one-shot.

Source

pub const fn ticks(&self, ticks_hz: u32) -> Option<u32>

How long this will sound, in ticks of a ticks_hz clock, with any pitch override applied. None when the sample’s length is unknown.

Source

pub fn configure(&self, voice: Voice)

Point voice at this one-shot without starting it.

Separate from OneShot::play because a program that keeps one voice per sound can set it up once at boot and then only key on. A program sharing voices has to do both together.

Source

pub fn play(&self, voice: Voice)

Key this one-shot on voice.

Volume is set on every key-on rather than once at upload, because the cutoff silences a voice by writing volume 0 and start does not restore it. Omitting this is how the demo disc’s v0.11 pressing ended up with a browse blip that played exactly once and never again.

Trait Implementations§

Source§

impl Clone for OneShot

Source§

fn clone(&self) -> OneShot

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 Copy for OneShot

Auto Trait Implementations§

§

impl Freeze for OneShot

§

impl RefUnwindSafe for OneShot

§

impl Send for OneShot

§

impl Sync for OneShot

§

impl Unpin for OneShot

§

impl UnsafeUnpin for OneShot

§

impl UnwindSafe for OneShot

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.