Crate mel [] [src]

example of using the mel create to build up a filter matrix that can then be used to repeatedly and efficiently (in-place) transform a huge (2048) power spectrum vector to a mel filtered vector of lower dimension (100).

extern crate mel;

extern crate nalgebra;
use nalgebra::{DMatrix, DVector};

fn main() {
    let sample_rate = 44100;
    let window_size = 4096;
    let power_spectrum_size = window_size / 2;
    let filter_count = 100;

    // build up the mel filter matrix
    let mut mel_filter_matrix =
        DMatrix::<f64>::zeros(filter_count, power_spectrum_size);
    for (row, col, coefficient) in mel::enumerate_mel_scaling_matrix(
        sample_rate,
        window_size,
        power_spectrum_size,
        filter_count,
    ) {
        mel_filter_matrix[(row, col)] = coefficient;
    }

    let power_spectrum_vector =
        DVector::<f64>::from_element(power_spectrum_size, 1.);

    let mut mel_vector =
        DVector::<f64>::zeros(filter_count);

    // mel_vector <- mel_filter_matrix * power_spectrum_vector
    mel_filter_matrix.mul_to(&power_spectrum_vector, &mut mel_vector);

    // mel_vector now contains a mel filtered version
    // of the power_spectrum_vector!
}

Structs

MelScalingMatrixEnumerator

col index changes fastest

Functions

enumerate_mel_scaling_matrix

one filter per row

enumerate_mel_scaling_matrix_base

(or many vectors at once in form of a matrix) to transform that vector into mel space. efficiently rows are mel cols are freq TODO get frequency index pair for nth mel TODO enumerate scaling vector TODO which dimension first

hertz_from_mel
mel_from_hertz