7 unstable releases (3 breaking)

0.4.1 Jan 2, 2023
0.4.0 Dec 29, 2022
0.3.0 Dec 9, 2022
0.2.2 Jul 22, 2022
0.1.0 Jun 29, 2022

#648 in Audio

Download history 47/week @ 2024-06-17 70/week @ 2024-06-24 51/week @ 2024-07-01 29/week @ 2024-07-08 14/week @ 2024-07-15 15/week @ 2024-07-22 51/week @ 2024-07-29 10/week @ 2024-08-05 8/week @ 2024-08-12 4/week @ 2024-08-19 22/week @ 2024-08-26 5/week @ 2024-09-02 37/week @ 2024-09-09 4/week @ 2024-09-16 87/week @ 2024-09-23 17/week @ 2024-09-30

145 downloads per month

MIT license

180KB
484 lines

wavegen

github Crates.io docs Build status

wavegen is a wavefrom generator made with 🦀

How to use it?

  1. Add wavegen to your project:
[dependencies]
wavegen = "0.4"

Or, to use the no_std version (custom global allocator is required):

[dependencies]
wavegen = { version = "0.4", default-features = false, features = ["libm"] }
  1. Define a waveform with sampling frequency and function components:
let waveform = wf!(f64, 200., sine!(frequency: 100., amplitude: 10.), dc_bias!(20.));
  1. Turn it into an iterator and sample:
let some_samples: Vec<f64> = waveform.iter().take(200).collect();

Refer to documentation for more exhaustive usage examples.

Show me some examples!

Interactive demo

Check out the demo at https://wavegen-demo.netlify.app

Plot charts

  • Simple sine

Sine plot

  • Two superposed phase-shifted sines

Superposed sines plot

  • "Real life" example: 300Hz sine signal with 50Hz interference noise

300_50_hz_sines

  • Sawtooth

Sawtooth plot

  • Superposition of sine + sawtooth

Sine and sawtooth superposed

  • Square wave

Square wave

  • Superposition of Sine, Square and Sawtooth with different frequencies

Something funky

All above examples are generated with simple program found in examples/plot.rs. Run cargo run --example plot to generate them yourself.

MSRV

The Minimum Supported Rust Version is 1.60.

Similar crates

  • Waver which was the inspiration for this crate

Breaking changes

0.2

  • Braking change in how macros are annotated, changing the annotation form from frequency = n to frequency: n

0.4

  • Waveform::get_sample_rate renamed to Waveform::sample_rate and now returns a borrowed values, as per rust API specs.
  • Waveform::get_components_len removed. The functionality can be achieved by a new getter Waveform::components.

Dependencies