audioviz is a libary to transform raw audiodata to be visually pleasing.

Overview

audioviz

A modular and simple libary to make raw and realtime audiodata captured for example from cpal visually more appealing.

It is not intended for scientifically usecases.

demo

simple implementation

Features

  • Fast Fourier transform via RustFFT with space and volume normalisation
  • configuration that can be live modified at runtime
  • buffering for smoothing over time
  • smoothing
  • resolution control
  • configurable refresh rate
  • scalable custom frequencies
  • very simple interface
  • only about 350 lines of code
  • multithreaded event based approach
  • should be able to be implemented in any project

Example with cpal

) { // sends the raw data to audio_stream via the event_sender sender.send(audioviz::Event::SendData(data.to_vec())).unwrap(); } fn err_fn(err: cpal::StreamError) { eprintln!("an error occurred on stream: {}", err); } ">
use audioviz::*;
use std::thread;
use std::sync::mpsc;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};

fn main() {
    // creates the AudioStream object, which handles the interface
    let audio_stream = AudioStream::init(
        // using the default configuration
        Config {
            ..Default::default()
        }
    );

    // getting the event_sender of audio_stream for easy implementation
    let event_sender = audio_stream.get_event_sender();

    // initiating the audio sending thread, that captures audio using cpal and then sends it to audio_stream via the event_sender
    // I actually dont fully know how to use cpal so it could be partially wrong but it works at least a bit
    let event_sender_clone = event_sender.clone();
    thread::spawn(move || {
        let host = cpal::default_host();

        let device = host.default_output_device().unwrap();

        let device_config =  device.default_output_config().unwrap();

        let stream = match device_config.sample_format() {
            cpal::SampleFormat::F32 => device.build_input_stream(
                &device_config.into(),
                move |data, _: &_| handle_input_data_f32(data, event_sender_clone.clone()),
                err_fn,
            ).unwrap(),
            other => {
                panic!("Unsupported sample format {:?}", other);
            }
        };

        stream.play().unwrap();

        // parks the thread so stream.play() does not get dropped and stops
        thread::park();
    });

    // receives calculated and converted data from audio_stream
    loop {
        // Method 1:
        let data = audio_stream.get_audio_data();
        
        // Method 2:
        let (tx, rx) = mpsc::channel();
        event_sender.send(Event::RequestData(tx)).unwrap();
        let data = rx.recv().unwrap();

        // Do something with data...
    }

}

// functions for cpal
fn handle_input_data_f32(data: &[f32], sender: mpsc::Sender
   ) {
    
   // sends the raw data to audio_stream via the event_sender
    sender.
   send(audioviz
   ::Event
   ::
   SendData(data.
   to_vec())).
   unwrap();
}


   fn 
   err_fn(err: cpal::StreamError) {
    
   eprintln!(
   "an error occurred on stream: {}", err);
}
  

The received data is stored via Vec

You might also like...
Use raw-window-handle 0.5 with crates that depend on 0.4.

OldHasRawWindowHandleWrapper Wrap any type that implements HasRawWindowHandle and HasRawDisplayHandle from raw-window-handle 0.5 in OldHasRawWindowHan

Pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way.

DNG-rs   A pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way. Also containing code for re

A black-box raw calldata decoder using only calldata to guess types and parse parameters.
A black-box raw calldata decoder using only calldata to guess types and parse parameters.

Calldata Decoder A black-box raw calldata decoder using only calldata. Based off the topics discussed in DeGatchi's article, Reverse The EVM: Raw Call

A crate to help you copy things into raw buffers without invoking spooky action at a distance (undefined behavior).

🗜 presser Utilities to help make copying data around into raw, possibly-uninitialized buffers easier and safer. presser can help you when copying dat

A rust crate to view a structure as raw bytes (&[u8])

rawbytes A Rust crate to view a structure as a plain byte array (&[u8]). Super simple. Tiny. Zero dependencies. This is a safer interface to slice::fr

Transform Linux Audit logs for SIEM usage

Linux Audit – Usable, Robust, Easy Logging TLDR: Instead of audit events that look like this… type=EXECVE msg=audit(1626611363.720:348501): argc=3 a0=

A tool to deserialize data from an input encoding, transform it and serialize it back into an output encoding.

dts A simple tool to deserialize data from an input encoding, transform it and serialize it back into an output encoding. Requires rust = 1.56.0. Ins

A set of cryptographic primitives for building a multi-hop Proxy Re-encryption scheme, known as Transform Encryption.

recrypt A pure-Rust library that implements a set of cryptographic primitives for building a multi-hop Proxy Re-encryption scheme, known as Transform

Instrument and transform wasm modules.

wasm-instrument A Rust library containing a collection of wasm module instrumentations and transformations mainly useful for wasm based block chains a

SWC Transform to prefix logs. Useful for adding file and line number to logs

SWC Transform to prefix logs. Useful for adding file and line number to logs

TODO pass transform struct instead of trying to modify particles everywhere.

Sparticles RS TODO pass transform struct instead of trying to modify particles everywhere. Roadmap add animations. move particle away if on top of eac

Automatically transform your Next.js Pages to use SuperJSON with SWC

🔌 NEXT SUPERJSON PLUGIN export default function Page({ date }) { return ( div Today is {date.toDateString()} /div ) } // You c

SWC plugin for transform Vue3-jsx syntax

swc-plugin-transform-vue3-jsx 💡 SWC plugin for faster conversion vue3-jsx. Installation npm npm install swc-plugin-transform-vue3-jsx -D yarn yarn ad

Transform your terminal into an art canvas where you can draw stuff!
Transform your terminal into an art canvas where you can draw stuff!

Termdraw Turn your terminal into the drawing cavnas of your dream... or not! Installation To install this dream-come-true of a tool simply run cargo i

Rust implementations of Fast Fourier Transform convolution and correlation for n-dimensional arrays

fftconvolve Rust implementations of Fast Fourier Transform convolution and correlation for n-dimensional arrays Examples 1-dimensional use fftconvolve

A cool-headed display transform
A cool-headed display transform

🌈 Tony McMapface 🌈 Takes HDR Rec.709/sRGB stimulus, and maps it to LDR. It's tranquil and collected, and won't set your eyes ablaze. About Tony is a

Rust-lang Continuous Wavelet Transform(CWT) library inspired by fCWT.

fastcwt Rust-lang Continuous Wavelet Transform(CWT) library inspired by fCWT. This crate is a direct translation of fCWT Library written in C++ by Art

Transform tagged Markdown string to HTML during build time.

tagged-md Transform tagged Markdown string to HTML! Check out the examples! Motivation Have you ever written HTML strings in your JavaScript code? It'

This is a small demo of how to transform a simple single-server RocksDB service written in Rust into a distributed version using OmniPaxos.

OmniPaxos Demo This is a small demo of how to transform a simple single-server RocksDB service into a distributed version using OmniPaxos. Related res

Owner
null
Prototype for a CLI/Libary designed for interacting with NASA Open APIs with Rust.

Overview Voyager is a swiss army knife library for the NASA Open APIs. It is designed to bundle all the NASA APIs into a single package. Voyager can b

Ethan Gallucci 4 Aug 14, 2022
Visually cluster your emails by sender, domain, and more to identify waste

Postsack A high level visual overview of swaths of email TLDR! A web demo that shows how Postsack clusters a set of 10.000 fake emails Do you have man

Benedikt Terhechte 298 Dec 26, 2022
libc - Raw FFI bindings to platforms' system libraries

libc provides all of the definitions necessary to easily interoperate with C code (or "C-like" code) on each of the platforms that Rust supports. This includes type definitions (e.g. c_int), constants (e.g. EINVAL) as well as function headers (e.g. malloc).

The Rust Programming Language 1.5k Jan 1, 2023
🪣 Types for a `Vec`'s raw parts

raw-parts A wrapper around the decomposed parts of a Vec<T>. This struct contains the Vec's internal pointer, length, and allocated capacity. RawParts

Artichoke Ruby 3 Sep 1, 2022
Camera RAW to DNG file format converter

DNGLab - A camera RAW to DNG file format converter Command line tool to convert camera RAW files to Digital Negative Format (DNG). It is currently in

null 92 Jan 6, 2023
Allow raw pointer access without those pesky unsafe blocks everywhere!

Allow raw pointer access without those pesky unsafe blocks everywhere!

null 1 Jan 23, 2022
A raw implementation of Interoperable Private Attribution

Raw IPA A collaborative effort to generate a raw, but broadly functional, prototype of the Interoperable Private Attribution (IPA) proposal. The goal

Martin Thomson 1 Dec 12, 2022
A safe wrapper around Gamercade's raw Api.

gamercade-rs A safe wrapper around Gamercade's Raw Api. As the Raw Api requires using a lot of unsafe and hiding of values through different types (fo

null 1 Aug 23, 2022
Unopinionated low level API bindings focused on soundness, safety, and stronger types over raw FFI.

?? firehazard ?? Create a fire hazard by locking down your (Microsoft) Windows so nobody can escape (your security sandbox.) Unopinionated low level A

null 5 Nov 17, 2022
Key-value store for embedded systems, for raw NOR flash, using an LSM-Tree.

ekv Key-value store for embedded systems, for raw NOR flash, using an LSM-Tree. Features None yet TODO Everything Minimum supported Rust version (MSRV

Dario Nieuwenhuis 16 Nov 22, 2022