pub struct Stft { /* private fields */ }Expand description
A planned STFT. It computes one frame at a time into a buffer it owns, so a long stem never holds its whole spectrogram in memory.
The transform is not normalised: a frame holds
X[m, k] = sum_n w[n] x[m hop - N/2 + n] exp(-j 2 pi k n / (p N)).
use sound_to_patch::audio::SampleRate;
use sound_to_patch::dsp::{Stft, StftParams};
let rate = SampleRate::new(8_000)?;
let params = StftParams::new(256)?;
let mut stft = Stft::new(params);
let signal: Vec<f64> = (0..1_000).map(|n| (0.1 * f64::from(n)).sin()).collect();
assert_eq!(params.frame_count(signal.len()), 16);
let peak = stft
.frame(&signal, 8)
.iter()
.enumerate()
.max_by(|a, b| a.1.norm().total_cmp(&b.1.norm()))
.map(|(bin, _)| bin);
// 0.1 rad per sample is 127.3 Hz at 8 kHz: bin 4 of 31.25 Hz.
assert_eq!(peak, Some(4));Implementations§
Source§impl Stft
impl Stft
Sourcepub fn new(params: StftParams) -> Self
pub fn new(params: StftParams) -> Self
Plans the FFT and the window for these parameters.
Sourcepub fn params(&self) -> StftParams
pub fn params(&self) -> StftParams
Returns the parameters.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Stft
impl !UnwindSafe for Stft
impl Freeze for Stft
impl Send for Stft
impl Sync for Stft
impl Unpin for Stft
impl UnsafeUnpin for Stft
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn 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>
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)
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)
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
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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