7 releases
0.1.6 | May 15, 2020 |
---|---|
0.1.5 | May 15, 2020 |
0.1.2 | Nov 10, 2019 |
#531 in Audio
21 downloads per month
5KB
periodicsynth
A periodic waveform generator which calls arbitrary functions for generating waveforms with an arbitrary samplerate which is translated into time-position between (0..1) and provided to the generator.
Some functions are provided by default (eg. sine, cosine, square, null). To implement a one follow this kind of syntax:
struct YourData; // v you can use your own type.
fn gen(t: f64, dat: YourData) -> f64 { 1.0 }
Using a default function packed (sin):
use periodicsynth::{synth, sin};
fn main()
{ let samp = synth(sin, &mut 440f64, 8000); }
Using our own and handcrafted function:
use periodicsynth::synth;
struct YourData; // you can use any type at here.
fn gen(t: f64, dat: YourData) -> f64 { 1.0 }
fn main()
{ let samp = synth(gen, &mut YourData{}, 8000); }
Motivation
The WebAudio API's OscillatorNode
generates periodic waveforms with different functions. Something
like that doesn't exist so this is created to do just
that or even further to that by allowing end-users to
define custom functions to generate waveforms.