pub struct SpectrumVisualizer<'a> { /* private fields */ }Expand description
Builder that renders a frequency spectrum as an image.
Input is a list of (frequency in Hz, magnitude) pairs; it does not need
to be sorted. The x-axis is labeled with the frequencies, the y-axis
ranges from zero to the largest magnitude unless Self::y_range fixes
it.
This crate does not compute spectra itself; pair it with an FFT crate such
as spectrum-analyzer. Individual frequencies can be highlighted in the
resulting chart, which is handy to verify that an expected peak is where
it should be. For real-time visualization see crate::live.
§Example
use audio_visualizer::SpectrumVisualizer;
let spectrum: Vec<(f32, f32)> = vec![(55.0, 0.1), (60.0, 0.9), (65.0, 0.2)];
SpectrumVisualizer::new(&spectrum)
.highlight(60.0)
.write_png("spectrum.png")
.unwrap();Implementations§
Source§impl<'a> Spectrum<'a>
impl<'a> Spectrum<'a>
Sourcepub const fn new(data: &'a [(f32, f32)]) -> Self
pub const fn new(data: &'a [(f32, f32)]) -> Self
Creates a spectrum visualization of (frequency in Hz, magnitude)
pairs.
Sourcepub fn highlight(self, frequency_hz: f32) -> Self
pub fn highlight(self, frequency_hz: f32) -> Self
Highlights the spectrum entry closest to the given frequency with a red marker. Can be called multiple times.
Sourcepub fn highlights(self, frequencies_hz: &[f32]) -> Self
pub fn highlights(self, frequencies_hz: &[f32]) -> Self
Highlights the spectrum entry closest to the given frequencies with a red marker. Can be called multiple times.
Sourcepub const fn y_range(self, range: Range<f32>) -> Self
pub const fn y_range(self, range: Range<f32>) -> Self
Fixes the y-axis to the given range instead of fitting it to the data. Magnitudes outside the range are clipped to its bounds.
This makes images of different spectra comparable.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Spectrum<'a>
impl<'a> RefUnwindSafe for Spectrum<'a>
impl<'a> Send for Spectrum<'a>
impl<'a> Sync for Spectrum<'a>
impl<'a> Unpin for Spectrum<'a>
impl<'a> UnsafeUnpin for Spectrum<'a>
impl<'a> UnwindSafe for Spectrum<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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