-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from phip1611/dev
Release v1.3
- Loading branch information
Showing
27 changed files
with
680 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use spectrum_analyzer::{ | ||
samples_fft_to_spectrum, scaling, windows, FrequencyLimit, FrequencySpectrum, | ||
}; | ||
|
||
fn spectrum_without_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
samples_fft_to_spectrum(samples, 44100, FrequencyLimit::All, None).unwrap() | ||
} | ||
|
||
fn spectrum_with_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
samples_fft_to_spectrum( | ||
samples, | ||
44100, | ||
FrequencyLimit::All, | ||
Some(&scaling::divide_by_N_sqrt), | ||
) | ||
.unwrap() | ||
} | ||
|
||
fn spectrum_with_multiple_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
let mut spectrum = spectrum_with_scaling(samples); | ||
|
||
let mut working_buffer = vec![(0.0.into(), 0.0.into()); spectrum.data().len()]; | ||
|
||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
// create 2048 random samples | ||
let samples = (0..2048) | ||
.map(|_| rand::random::<i16>()) | ||
.map(|x| x as f32) | ||
.collect::<Vec<_>>(); | ||
let hann_window = windows::hann_window(&samples); | ||
|
||
c.bench_function("spectrum without scaling", |b| { | ||
b.iter(|| spectrum_without_scaling(black_box(&hann_window))) | ||
}); | ||
c.bench_function("spectrum with scaling", |b| { | ||
b.iter(|| spectrum_without_scaling(black_box(&hann_window))) | ||
}); | ||
c.bench_function("spectrum with multiple scaling steps", |b| { | ||
b.iter(|| spectrum_with_multiple_scaling(black_box(&hann_window))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
pkgs.mkShell rec { | ||
nativeBuildInputs = with pkgs; [ | ||
pkg-config | ||
]; | ||
|
||
buildInputs = with pkgs; [ | ||
alsa-lib | ||
fontconfig | ||
libxkbcommon | ||
xorg.libXcursor | ||
xorg.libX11 | ||
]; | ||
|
||
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.