Skip to main content

EnvelopeLayer

Struct EnvelopeLayer 

Source
pub struct EnvelopeLayer {
Show 22 fields pub notes: Vec<NoteEnvelope>, pub pooled: Vec<bool>, pub attack: Estimate<Stats<Seconds>, Seconds>, pub hold: Estimate<Stats<Seconds>, Seconds>, pub decay: Estimate<Stats<Seconds>, Seconds>, pub sustain: Estimate<Stats<Decibels>, Decibels>, pub note_off_offset: Estimate<Stats<Seconds>, Seconds>, pub release: Estimate<Stats<Seconds>, Seconds>, pub tail_rt60: Estimate<Stats<Seconds>, Seconds>, pub tail_weight: Estimate<Stats<Ratio>, Ratio>, pub release_confidence: Option<Level>, pub tail_votes: TailVotes, pub level_spread: Estimate<Decibels, NoSpread>, pub levels: Vec<Option<Decibels>>, pub ripple: Option<Decibels>, pub residual: Option<Decibels>, pub pump: Option<Pump>, pub overlap_fraction: f64, pub flags: EnvelopeFlags, pub confidence: Confidence<NoSpread>, pub counts: EnvelopeCounts, pub silent: Vec<(Seconds, MidiPitch)>,
}
Expand description

The envelope layer of a stem.

Fields§

§notes: Vec<NoteEnvelope>

The envelope of each read note, in note order.

§pooled: Vec<bool>

Which of notes form the pool.

§attack: Estimate<Stats<Seconds>, Seconds>

The attack over the pool: 0 to 100 % for a linear ramp.

§hold: Estimate<Stats<Seconds>, Seconds>

The hold over the pool.

§decay: Estimate<Stats<Seconds>, Seconds>

The decay over the pool.

§sustain: Estimate<Stats<Decibels>, Decibels>

The sustain level from the peak over the pool.

§note_off_offset: Estimate<Stats<Seconds>, Seconds>

The note’s end in the list minus its knee, over the pooled notes with a knee.

§release: Estimate<Stats<Seconds>, Seconds>

The linear release over the pool; no estimate when the tail hides it.

§tail_rt60: Estimate<Stats<Seconds>, Seconds>

The RT60 of the tail over the pooled notes that have one.

§tail_weight: Estimate<Stats<Ratio>, Ratio>

The weight of the tail over the pooled notes with a fit.

§release_confidence: Option<Level>

How far to trust the release: low when no release is written; None when no pooled note has a tail fit.

§tail_votes: TailVotes

The votes that the tail is reverb.

§level_spread: Estimate<Decibels, NoSpread>

The 90th minus the 10th percentile of the full-band levels of the pooled notes. read_levels sets it; before, it holds no estimate.

§levels: Vec<Option<Decibels>>

The full-band level of each note of the list, in list order; None when its span holds no frame. Unlike peak_db, it compares notes that read different harmonics. read_levels sets it; before, it is empty.

§ripple: Option<Decibels>

The median ripple over the pool.

§residual: Option<Decibels>

The median fit residual over the pool.

§pump: Option<Pump>

The pump read; None with fewer than PUMP_BEATS_MIN sustained beats.

§overlap_fraction: f64

The share of the notes in the list that overlap another.

§flags: EnvelopeFlags

The flags.

§confidence: Confidence<NoSpread>

The confidence of the layer as a whole; no estimate without notes.

§counts: EnvelopeCounts

The counts behind the summary.

§silent: Vec<(Seconds, MidiPitch)>

The onset and pitch of each note whose amp proxy peaks at the silence floor.

Implementations§

Source§

impl EnvelopeLayer

Source

pub fn of(input: &EnvelopeInput<'_>) -> Result<Self, EnvelopeError>

Reads the envelope layer of a stem.

A 220 Hz sine held from 0.1 s, released linearly from 0.8 to 0.9 s, reads one note at a sustain near its peak, with its note-off knee where the release starts:

use sound_to_patch::audio::{BeatGrid, SampleRate};
use sound_to_patch::estimate::envelope::{EnvelopeInput, EnvelopeLayer};
use sound_to_patch::notes::{Note, NoteList};
use sound_to_patch::units::{Bpm, MidiPitch, Seconds};

let rate = SampleRate::new(22_050)?;
let mono: Vec<f64> = (0..22_050)
    .map(|n| {
        let t = f64::from(n) / 22_050.0;
        let gain = if t < 0.1 { 0.0 } else { ((0.9 - t) / 0.1).clamp(0.0, 1.0) };
        0.5 * gain * (std::f64::consts::TAU * 220.0 * t).sin()
    })
    .collect();
let note = Note::new(Seconds::new(0.1)?, Seconds::new(0.9)?, MidiPitch::new(57.0)?)?;
let notes = NoteList::new(vec![note]);
let grid = BeatGrid::new(Bpm::new(120.0)?, Seconds::new(0.0)?);
let layer = EnvelopeLayer::of(&EnvelopeInput { stereo: None, mono: &mono, rate, notes: &notes, grid })?;
assert_eq!(layer.counts.read, 1);
let sustain = layer.sustain.value().map(|s| s.median().get());
assert!(sustain.is_some_and(|s| s > -1.0));
let knee = layer.notes[0].knee.map(Seconds::get);
assert!(knee.is_some_and(|k| (k - 0.8).abs() < 0.01));
§Errors

Returns an EnvelopeError when a harmonic band reaches the Nyquist frequency, or a confidence cannot be built.

Source

pub fn read_levels( &mut self, input: &EnvelopeInput<'_>, mono_line: bool, ) -> Result<(), EnvelopeError>

Reads the full-band level of each note and their spread over the pool, as LEVEL_SPREAD_CONVENTION defines them. The levels wait for the voices layer, which reads this layer first: mono_line is the one voicing the final notes use, and on a mono line a level’s span ends at the next later onset.

§Errors

Returns an EnvelopeError when the spread’s confidence cannot be built.

Source

pub fn summary(&self) -> Vec<String>

Returns the lines that tell what the layer found.

Trait Implementations§

Source§

impl Clone for EnvelopeLayer

Source§

fn clone(&self) -> Self

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 Debug for EnvelopeLayer

Source§

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

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

impl PartialEq for EnvelopeLayer

Source§

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

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> CloneAny for T
where T: Any + Clone,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.