Struct sonogram::SpecOptionsBuilder
source · pub struct SpecOptionsBuilder { /* private fields */ }
Expand description
A builder struct that will output a spectrogram creator when complete.
This builder will require the height and width of the final spectrogram,
at a minimum. However you can load data from a .wav file, or directly
from a Vec
Example
let mut spectrograph = SpecOptionsBuilder::new(512, 128)
.set_window_fn(utility::blackman_harris)
.load_data_from_file(&std::path::Path::new("test.wav"))?
.build();
Implementations§
source§impl SpecOptionsBuilder
impl SpecOptionsBuilder
sourcepub fn new(num_bins: usize) -> Self
pub fn new(num_bins: usize) -> Self
Create a new SpecOptionsBuilder. The final height and width of
the spectrogram must be supplied. Before the build
function
can be called a load_data_from_*
function needs to be called.
Arguments
num_bins
- Number of bins in the discrete fourier transform (FFT)
sourcepub fn load_data_from_file(self, fname: &Path) -> Result<Self, SonogramError>
pub fn load_data_from_file(self, fname: &Path) -> Result<Self, SonogramError>
sourcepub fn load_data_from_memory(self, data: Vec<i16>, sample_rate: u32) -> Self
pub fn load_data_from_memory(self, data: Vec<i16>, sample_rate: u32) -> Self
Load data directly from memory - i16 version.
Arguments
data
- The raw wavform data that will be converted to a spectrogram.sample_rate
- The sample rate, in Hz, of the data.
sourcepub fn load_data_from_memory_f32(self, data: Vec<f32>, sample_rate: u32) -> Self
pub fn load_data_from_memory_f32(self, data: Vec<f32>, sample_rate: u32) -> Self
Load data directly from memory - f32 version.
Arguments
data
- The raw wavform data that will be converted to a spectrogram. Samples must be in the range -1.0 to 1.0.sample_rate
- The sample rate, in Hz, of the data.
sourcepub fn downsample(self, divisor: usize) -> Self
pub fn downsample(self, divisor: usize) -> Self
Down sample the data by the given divisor. This is a cheap way of improving the performance of the FFT.
Arguments
divisor
- How much to reduce the data by.
sourcepub fn channel(self, channel: u16) -> Self
pub fn channel(self, channel: u16) -> Self
Set the audio channel to use when importing a WAV file. By default this is 1.
sourcepub fn set_window_fn(self, window_fn: fn(_: usize, _: usize) -> f32) -> Self
pub fn set_window_fn(self, window_fn: fn(_: usize, _: usize) -> f32) -> Self
A window function describes the type of window to use during the DFT (discrete fourier transform). See (here)[https://en.wikipedia.org/wiki/Window_function] for more details.
Arguments
window
- The window function to be used.
sourcepub fn set_step_size(self, step_size: usize) -> Self
pub fn set_step_size(self, step_size: usize) -> Self
This is the step size (as the number of samples) between each application of the window function. A smaller step size may increase the smoothness of the sample, but take more time. The default step size, if not set, is the same as the number of FFT bins. This there is no overlap between windows and it most cases will suit your needs.
sourcepub fn build(self) -> Result<SpecCompute, SonogramError>
pub fn build(self) -> Result<SpecCompute, SonogramError>
The final method to be called. This will create an instance of [Spectrograph].