Skip to main content

Drum

Struct Drum 

Source
pub struct Drum {
    pub kind: DrumKind,
    pub kit: DrumKit,
    pub pitch_hz: u16,
    pub tone_ms: u32,
    pub noise_ms: u32,
    pub sweep_cents: u16,
    pub sweep_ms: u32,
    pub noise_percent: u8,
    pub click_percent: u8,
    pub seed: u32,
}
Expand description

A drum preset with integer, portable controls. Notes transpose pitched components relative to C4; noise filters stay fixed. Envelope times are finite lengths, not exponential time constants. Each trigger resets oscillators, filters and seed. A component shorter than its 1 ms attack (including a one-frame envelope at low sample rates) can be silent. Presets use longer envelopes.

Fields§

§kind: DrumKind§kit: DrumKit§pitch_hz: u16

Fundamental/metal-bank base at C4, 20..=20000 Hz, clamped below Nyquist.

§tone_ms: u32

Tone envelope length, 0..=10000 ms. Zero silences that component.

§noise_ms: u32

Noise envelope length, 0..=10000 ms. Clap adds 30 ms for its initial bursts.

§sweep_cents: u16

Initial pitch above the base, 0..=4800 cents, falling linearly in cents.

§sweep_ms: u32

Time to reach the base pitch, 0..=1000 ms. Zero starts at the base.

§noise_percent: u8

Noise blend, 0..=100 percent; the tone receives the complementary amount.

§click_percent: u8

A separate 3 ms filtered-noise transient, 0..=100 percent.

§seed: u32

Fixed noise seed. Zero maps to one; the chiptune register uses its low 15 bits.

Implementations§

Source§

impl Drum

Source

pub fn new(kind: DrumKind, kit: DrumKit) -> Self

Source

pub fn validate(&self) -> Result<()>

Source

pub fn duration_ms(&self) -> u32

Finite duration including a clap’s bursts and the click, excluding muted components.

Source

pub fn render(&self, sample_rate: u32, velocity: u8) -> Result<Audio>

Renders one hit at C4, with velocity 0..=127, using band-limited chip tones. This offline convenience allocates its output; score Synth::fill does not.

Trait Implementations§

Source§

impl Clone for Drum

Source§

fn clone(&self) -> Drum

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Drum

Source§

impl Debug for Drum

Source§

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

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

impl Eq for Drum

Source§

impl Hash for Drum

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Drum

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Drum

Auto Trait Implementations§

§

impl Freeze for Drum

§

impl RefUnwindSafe for Drum

§

impl Send for Drum

§

impl Sync for Drum

§

impl Unpin for Drum

§

impl UnsafeUnpin for Drum

§

impl UnwindSafe for Drum

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.