| Crates.io | wave_forms |
| lib.rs | wave_forms |
| version | 0.1.0 |
| created_at | 2025-11-25 22:26:12.056467+00 |
| updated_at | 2025-11-25 22:26:12.056467+00 |
| description | no std wave forms |
| homepage | |
| repository | https://github.com/Loag/sinusoidal |
| max_upload_size | |
| id | 1950548 |
| size | 6,279 |
A no_std Rust library for generating waveform data. This library provides standard-library-free implementations of waveforms.
#![no_std]) - suitable for embedded systems and constrained environmentsuse wave_forms::generate_sine_wave;
let mut buffer = [0.0; 1000];
generate_sine_wave(&mut buffer, 440.0, 44100.0, 1.0);
// buffer now contains 1000 samples of a 440Hz sine wave
use wave_forms::generate_square_wave;
let mut buffer = [0.0; 1000];
generate_square_wave(&mut buffer, 1.0);
// buffer now contains 1000 samples of a square wave
use wave_forms::generate_triangle_wave;
let mut buffer = [0.0; 1000];
generate_triangle_wave(&mut buffer, 1.0);
// buffer now contains 1000 samples of a triangle wave
For more control, you can calculate individual samples:
use wave_forms::sin_val;
let sample = sin_val(440.0, 0, 44100.0, 1.0);
// Calculate the first sample of a 440Hz sine wave
generate_sine_wave(output: &mut [f64], frequency: f64, sample_rate: f64, amplitude: f64)Generates a sine wave into the provided mutable slice.
output: Mutable slice to fill with waveform samplesfrequency: Frequency in Hzsample_rate: Sample rate in Hz (e.g., 44100.0)amplitude: Amplitude of the waveformgenerate_square_wave(output: &mut [f64], amplitude: f64)Generates a square wave into the provided mutable slice.
output: Mutable slice to fill with waveform samplesamplitude: Amplitude of the waveformgenerate_triangle_wave(output: &mut [f64], amplitude: f64)Generates a triangle wave into the provided mutable slice.
output: Mutable slice to fill with waveform samplesamplitude: Amplitude of the waveformsin_val(frequency: f64, i: usize, sample_rate: f64, amplitude: f64) -> f64Calculates a single sine wave sample value.
frequency: Frequency in Hzi: Sample indexsample_rate: Sample rate in Hzamplitude: Amplitude of the waveformiThe sine wave implementation uses a Taylor series approximation:
sin(x) = x - x³/3! + x⁵/5! - x⁷/7! + x⁹/9! - x¹¹/11! + x¹³/13!
The input is normalized to the range [-π, π] for optimal convergence of the series.
MIT