#fetcher #retrieve #fetch #source #frequency #shady

shady-audio

A high level library build upon cpal to retrieve audio for visualisation

2 releases

0.1.2 Dec 31, 2024
0.1.0 Dec 31, 2024

#260 in Audio

Download history 222/week @ 2024-12-30 14/week @ 2025-01-06

236 downloads per month

GPL-3.0-or-later

28KB
495 lines

shady-audio is the audio backend for the other shady tools. Its interface let's you easily fetch the frequency presence of the given audio source by selecting an audio source which implemented the Fetcher trait.

Example

use std::num::NonZeroUsize;
use shady_audio::{ShadyAudio, fetcher::DummyFetcher, config::ShadyAudioConfig};

fn main() {
    let mut audio = {
        let fetcher = DummyFetcher::new();
        let config = ShadyAudioConfig::default();
        ShadyAudio::new(fetcher, config)
    };
    // Retrieve a spline which you can use, to get any points from the frequancy bands of your audio fetcher.
    // `shady-audio` will take care of the rest. Let it be
    //   - gravity effect
    //   - smooth transition
    //   - etc.
    let spline = audio.get_spline();

    // All relevant points of the spline are stored within the range [0, 1].
    // Since we're currently using the [DummyFetcher] our spline equals the function `f(x) = 0`:
    assert_eq!(spline.sample(0.0), Some(0.0));
    assert_eq!(spline.sample(0.5), Some(0.0));
    // actually for some reason, `splines::Spline` returns `None` here and I don't know why ._.
    assert_eq!(spline.sample(1.0), None);

    // Any other value inside [0, 1] is fine:
    assert_eq!(spline.sample(0.123456789), Some(0.0));
}

Dependencies

~4–31MB
~456K SLoC