Struct Spectrogram

Source
pub struct Spectrogram { /* private fields */ }

Implementations§

Source§

impl Spectrogram

Source

pub fn from_raw<T: NumCast + Copy>( buf: &[T], width: usize, height: usize, ) -> Result<Spectrogram, SonogramError>

Create a new Spectrogram from a raw buffer. It must of the correct size (width * height). But can be of any numeric type that can be converted to f32.

§Arguments
  • buf - The raw buffer of data to create the spectrogram from, real numbers only.
  • width - The width of the spectrogram.
  • height - The height of the spectrogram.
Source

pub fn to_png( &mut self, fname: &Path, freq_scale: FrequencyScale, gradient: &mut ColourGradient, w_img: usize, h_img: usize, ) -> Result<(), Error>

Save the calculated spectrogram as a PNG image.

§Arguments
  • fname - The path to the PNG to save to the filesystem.
  • freq_scale - The type of frequency scale to use for the spectrogram.
  • gradient - The colour gradient to use for the spectrogram.
  • w_img - The output image width.
  • h_img - The output image height.
Source

pub fn to_png_in_memory( &mut self, freq_scale: FrequencyScale, gradient: &mut ColourGradient, w_img: usize, h_img: usize, ) -> Result<Vec<u8>, Error>

Create the spectrogram in memory as a PNG.

§Arguments
  • freq_scale - The type of frequency scale to use for the spectrogram.
  • gradient - The colour gradient to use for the spectrogram.
  • w_img - The output image width.
  • h_img - The output image height.
Source

pub fn to_rgba_in_memory( &mut self, freq_scale: FrequencyScale, gradient: &mut ColourGradient, w_img: usize, h_img: usize, ) -> Vec<u8>

Create the spectrogram in memory as raw RGBA format.

§Arguments
  • freq_scale - The type of frequency scale to use for the spectrogram.
  • gradient - The colour gradient to use for the spectrogram.
  • w_img - The output image width.
  • h_img - The output image height.
Source

pub fn to_csv( &mut self, fname: &Path, freq_scale: FrequencyScale, cols: usize, rows: usize, ) -> Result<(), Error>

Save the calculated spectrogram as a CSV file.

§Arguments
  • fname - The path to the CSV to save to the filesystem.
  • freq_scale - The type of frequency scale to use for the spectrogram.
  • cols - The number of columns.
  • rows - The number of rows.
Source

pub fn to_buffer( &self, freq_scale: FrequencyScale, img_width: usize, img_height: usize, ) -> Vec<f32>

Map the spectrogram to the output buffer. Essentially scales the frequency to map to the vertical axis (y-axis) of the output and scale the x-axis to match the output. It will also convert the spectrogram to dB.

§Arguments
  • freq_scale - The type of frequency scale to use for the spectrogram.
  • img_width - The output image width.
  • img_height - The output image height.
Source

pub fn get_min_max(&self) -> (f32, f32)

Get the minimum and maximum values from the current spectrogram.

Source

pub fn shape(&self) -> (usize, usize)

Get the width and height of the spectrogram.

Source

pub fn row_iter<'a>( &'a self, row_idx: usize, ) -> impl Iterator<Item = &'a f32> + 'a

Get an iterator over the spectrogram data by row index.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.