oscy 0.1.2

Minimalistic Rust library for audio oscillators supporting common waveform shapes.
Documentation
  • Coverage
  • 100%
    19 out of 19 items documented2 out of 12 items with examples
  • Size
  • Source code size: 28.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.26 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • paramako/oscy
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • paramako

oscy

Crates.io Docs.rs License: MIT Changelog

A Rust library for audio oscillators, waveform generation, and noise.

Sound sources

Source Description
NaiveOsc Simple oscillator without anti-aliasing. Fast but produces aliasing at higher frequencies.
PolyBlepOsc Band-limited oscillator using polyBLEP for reduced aliasing.
NoiseGen Noise generator with white, pink, and brown noise. Requires noise feature.

Usage

Filling an audio buffer

use oscy::{poly_blep::PolyBlepOsc, Oscillator, Waveform};

let mut osc = PolyBlepOsc::new(44100.0, 440.0, Waveform::Saw);
let mut buffer = [0.0f32; 512];
osc.fill(&mut buffer);

Using as an iterator

use oscy::{poly_blep::PolyBlepOsc, Waveform};

let osc = PolyBlepOsc::new(44100.0, 440.0, Waveform::Square);
let samples: Vec<f32> = osc.take(1024).collect();

Naive vs PolyBLEP

Use NaiveOsc when performance is critical and aliasing is acceptable (e.g., low frequencies, or when followed by filtering). Use PolyBlepOsc for cleaner sound at higher frequencies.

use oscy::{naive::NaiveOsc, poly_blep::PolyBlepOsc, Oscillator, Waveform};

// Naive: simple and fast, but aliases
let mut naive = NaiveOsc::new(44100.0, 2000.0, Waveform::Saw);

// PolyBLEP: smooths discontinuities to reduce aliasing
let mut blep = PolyBlepOsc::new(44100.0, 2000.0, Waveform::Saw);

Noise generator

Enable the noise feature in your Cargo.toml:

oscy = { version = "0.1", features = ["noise"] }
use oscy::noise::NoiseGen;

let mut noise = NoiseGen::pink();
let samples: Vec<f32> = noise.take(1024).collect();

Available types: white(), pink(), brown().

Supported waveforms

  • Sine
  • Saw
  • Square
  • Triangle

License

MIT License - see LICENSE for details.