Crates.io | sine_macro |
lib.rs | sine_macro |
version | 0.1.1 |
created_at | 2025-06-03 05:15:47.745149+00 |
updated_at | 2025-06-05 13:55:49.572417+00 |
description | Procedural macro for generating sine wave arrays |
homepage | |
repository | https://github.com/Tomin1/sine_macro |
max_upload_size | |
id | 1698662 |
size | 54,912 |
This provides a procedural macro for generating signed integer sine waves as
arrays. Mainly useful for producing different beep sounds on embedded systems
which might not even have alloc
crate or a floating point unit.
Add as a dependency:
cargo add sine_macro
Amend your code:
use sine_macro::sine_wave;
// Sine wave defined as const:
sine_wave! {
const MY_CONST_SINE_WAVE = sine_wave(frequency: 440, rate: 48_000);
}
// Or define sine wave as a local variable:
let wave = sine_wave!(frequency: 440, rate: 48_000);
These are both arrays of type [i16; 109]
. Some rounding will be applied when
the sampling rate is not an exact multiple of the frequency.
For more knobs and examples, please see the documentation.
This crate is MIT licensed. See LICENSE for more information. Dependency crates have their own licenses.