sine_macro

Crates.iosine_macro
lib.rssine_macro
version0.1.1
created_at2025-06-03 05:15:47.745149+00
updated_at2025-06-05 13:55:49.572417+00
descriptionProcedural macro for generating sine wave arrays
homepage
repositoryhttps://github.com/Tomin1/sine_macro
max_upload_size
id1698662
size54,912
Tomi Leppänen (Tomin1)

documentation

README

Procedural rust macro for generating sine wave arrays

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.

Crates.io MIT licensed docs.rs

Usage

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.

License

This crate is MIT licensed. See LICENSE for more information. Dependency crates have their own licenses.

Commit count: 24

cargo fmt