Skip to content

Commit

Permalink
Merge pull request #24 from meyda/add-readme-example
Browse files Browse the repository at this point in the history
  • Loading branch information
hughrawlinson authored Feb 5, 2022
2 parents 9236e0c + 9d37150 commit 38bce4e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ approx = "0.5.1"
serde = "1.0.7"
serde_derive = "1.0.7"
serde_json = "1.0"
rand = "0.8.4"
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/meyda/meyda-rs.svg?branch=master)](https://travis-ci.org/meyda/meyda-rs)
[![Code coverage](https://codecov.io/github/meyda/meyda-rs/coverage.svg?branch=master)](https://codecov.io/gh/meyda/meyda-rs)

*It's like [meyda](https://github.com/hughrawlinson/meyda), but for Rust.*
_It's like [meyda](https://github.com/hughrawlinson/meyda), but for Rust._

This project is heavily WIP and it's not wise to use it in production yet.

Expand All @@ -27,28 +27,30 @@ fn main() {

// create a vector of white noise
let mut generator = rand::thread_rng();
let signal: Vec<f64> = vec![0; BUFFER_SIZE].iter()
.map(|&sample| generator.gen_range(-1_f64, 1_f64))
let signal: Vec<f64> = vec![0; BUFFER_SIZE]
.iter()
.map(|&_sample| generator.gen_range(-1_f64..1_f64))
.collect();

// compute features
let rms = meyda::get_rms(&signal);
let energy = meyda::get_energy(&signal);
let zcr = meyda::get_zcr(&signal);
let power_spectrum = meyda::get_power_spectrum(&signal);
// let power_spectrum = meyda::get_power_spectrum(&signal);
let spectral_centroid = meyda::get_spectral_centroid(&signal);
let spectral_flatness = meyda::get_spectral_flatness(&signal);
let spectral_kurtosis = meyda::get_spectral_kurtosis(&signal);
let spectral_rolloff = meyda::get_spectral_rolloff(&signal, SAMPLE_RATE, 0.95);
let spectral_rolloff = meyda::get_spectral_rolloff(&signal, SAMPLE_RATE, Some(0.95));
let bark_loudness = meyda::get_bark_loudness(&signal, SAMPLE_RATE);

println!("RMS is {} \n energy is {:?}, zcr is {:?},\n spectral centroid is {},\n spectral flatness is {},\n spectral kurtosis is {},\n spectral rolloff is {},\n Bark loudness is {}", rms, energy, zcr, spectral_centroid, spectral_flatness, spectral_kurtosis,
println!("RMS is {} \n energy is {:?}, zcr is {:?},\n spectral centroid is {},\n spectral flatness is {},\n spectral kurtosis is {},\n spectral rolloff is {},\n Bark loudness is {:?}", rms, energy, zcr, spectral_centroid, spectral_flatness, spectral_kurtosis,
spectral_rolloff, bark_loudness);
}

```

## Development

Contributions are always welcome. The library *should* be test-driven and all new features *should* have accompanying tests.
Contributions are always welcome. The library _should_ be test-driven and all new features _should_ have accompanying tests.

Tests can be run with `cargo test` – each extractor function *should* have a test module in the same file, and should make use of [meyda/gauge](https://github.com/meyda/gauge), which is submodule'd in `/src/utils`. The deserialized gauge data is provided by `utils::test` as a vector of `TestDataSet` structures.
Tests can be run with `cargo test` – each extractor function _should_ have a test module in the same file, and should make use of [meyda/gauge](https://github.com/meyda/gauge), which is submodule'd in `/src/utils`. The deserialized gauge data is provided by `utils::test` as a vector of `TestDataSet` structures.
30 changes: 30 additions & 0 deletions examples/white-noise.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern crate meyda;
extern crate rand;

use rand::Rng;

fn main() {
const BUFFER_SIZE: usize = 1024;
const SAMPLE_RATE: f64 = 44100.0;

// create a vector of white noise
let mut generator = rand::thread_rng();
let signal: Vec<f64> = vec![0; BUFFER_SIZE]
.iter()
.map(|&_sample| generator.gen_range(-1_f64..1_f64))
.collect();

// compute features
let rms = meyda::get_rms(&signal);
let energy = meyda::get_energy(&signal);
let zcr = meyda::get_zcr(&signal);
// let power_spectrum = meyda::get_power_spectrum(&signal);
let spectral_centroid = meyda::get_spectral_centroid(&signal);
let spectral_flatness = meyda::get_spectral_flatness(&signal);
let spectral_kurtosis = meyda::get_spectral_kurtosis(&signal);
let spectral_rolloff = meyda::get_spectral_rolloff(&signal, SAMPLE_RATE, Some(0.95));
let bark_loudness = meyda::get_bark_loudness(&signal, SAMPLE_RATE);

println!("RMS is {} \n energy is {:?}, zcr is {:?},\n spectral centroid is {},\n spectral flatness is {},\n spectral kurtosis is {},\n spectral rolloff is {},\n Bark loudness is {:?}", rms, energy, zcr, spectral_centroid, spectral_flatness, spectral_kurtosis,
spectral_rolloff, bark_loudness);
}

0 comments on commit 38bce4e

Please sign in to comment.