Spectrogram

Struct Spectrogram 

Source
pub struct Spectrogram<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> Spectrogram<N>
where Assert<{ _ }>: IsTrue,

Source

pub fn new(fs: usize, win: Window) -> Self

Examples found in repository?
examples/spectrogram.rs (line 7)
6fn main() -> Result<()> {
7    let spec = Spectrogram::<16>::new(1, Window::Hann);
8    let mut transformed = [0.0; 354];
9    SPECTRUM.iter().enumerate().for_each(|(i, x)| {
10        transformed[i] = 1.0 / x.exp();
11    });
12    let mut out = spec.compute(&transformed);
13
14    let mut min = f32::MAX;
15    let mut max = f32::MIN;
16    for row in out.iter_mut() {
17        for v in row.iter_mut() {
18            let new_v = v.ln();
19            if new_v < min {
20                min = new_v;
21            };
22            if new_v > max {
23                max = new_v;
24            };
25            *v = new_v;
26        }
27    }
28    let height = out.len();
29    let width = out[0].len();
30
31    let mut f = BufWriter::new(File::create("microspectrogram.ppm")?);
32    writeln!(f, "P3")?;
33    writeln!(f, "{} {}", width, height)?;
34    writeln!(f, "255")?;
35    for row in out.iter().rev() {
36        for v in row.iter() {
37            let idx = (49.0 * (v - min) / (max - min)) as usize;
38            let col = VIRIDIS[idx];
39            write!(f, "{} {} {} ", col[0], col[1], col[2])?;
40        }
41        writeln!(f)?;
42    }
43    Ok(())
44}
Source

pub fn compute<const X: usize>(&self, data: &[f32; X]) -> [[f32; { _ }]; { _ }]
where [(); { _ }]: Sized,

Examples found in repository?
examples/spectrogram.rs (line 12)
6fn main() -> Result<()> {
7    let spec = Spectrogram::<16>::new(1, Window::Hann);
8    let mut transformed = [0.0; 354];
9    SPECTRUM.iter().enumerate().for_each(|(i, x)| {
10        transformed[i] = 1.0 / x.exp();
11    });
12    let mut out = spec.compute(&transformed);
13
14    let mut min = f32::MAX;
15    let mut max = f32::MIN;
16    for row in out.iter_mut() {
17        for v in row.iter_mut() {
18            let new_v = v.ln();
19            if new_v < min {
20                min = new_v;
21            };
22            if new_v > max {
23                max = new_v;
24            };
25            *v = new_v;
26        }
27    }
28    let height = out.len();
29    let width = out[0].len();
30
31    let mut f = BufWriter::new(File::create("microspectrogram.ppm")?);
32    writeln!(f, "P3")?;
33    writeln!(f, "{} {}", width, height)?;
34    writeln!(f, "255")?;
35    for row in out.iter().rev() {
36        for v in row.iter() {
37            let idx = (49.0 * (v - min) / (max - min)) as usize;
38            let col = VIRIDIS[idx];
39            write!(f, "{} {} {} ", col[0], col[1], col[2])?;
40        }
41        writeln!(f)?;
42    }
43    Ok(())
44}

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Spectrogram<N>

§

impl<const N: usize> RefUnwindSafe for Spectrogram<N>

§

impl<const N: usize> Send for Spectrogram<N>

§

impl<const N: usize> Sync for Spectrogram<N>

§

impl<const N: usize> Unpin for Spectrogram<N>

§

impl<const N: usize> UnwindSafe for Spectrogram<N>

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, 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.