Skip to content

mziad-dev/rust-audio-dsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Audio DSP Processor

Real-time audio effects processor powered by Rust + WebAssembly

A professional-grade audio workstation running entirely in your browser with stunning visualizations and 15 effect presets!

Audio DSP License

Algorithms used from: https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html

You can try it from here: https://mohammedx6.github.io/rust-audio-dsp/

Features

Audio Effects

  • Gain Control - Volume adjustment
  • Low-Pass Filter - Remove high frequencies
  • High-Pass Filter - Remove low frequencies
  • Distortion - Warm analog-style saturation
  • Delay/Echo - Time-based effects with feedback

15 Professional Presets

  1. Clean - Pure audio
  2. Podcast - Broadcast quality
  3. Telephone - Vintage phone
  4. Radio - AM radio effect
  5. Walkie-Talkie - Two-way radio
  6. Robot - Robotic voice
  7. Alien - Extraterrestrial
  8. Ghost - Spooky effect
  9. Underwater - Submerged sound
  10. Cave - Indoor reverb
  11. Valley - Long dramatic echo
  12. Stadium - Sports arena
  13. Concert Hall - Live performance
  14. Space - Cosmic ambience
  15. Psychedelic - Trippy swirling

Real-Time Visualizations

  • 4 Visualization Modes:

    • Waveform - Oscilloscope view
    • Spectrum - Frequency analyzer
    • Bars - Frequency bars
    • Circle - Circular waveform
  • Live Audio Stats:

    • Peak & RMS levels
    • Dominant frequency detection
    • DSP call counter
    • Processing speed metrics
    • Total data processed

Performance

  • < 1% CPU usage - Incredibly efficient
  • 170x faster than realtime - Rust power!
  • Zero latency - Instant processing
  • Clean audio - No background noise

Quick Start

Prerequisites

  • Rust 1.70+ (installed via rustup)
  • wasm-pack
  • Node.js 16+ (for local server)
  • Modern web browser (Chrome, Firefox, Edge)

Installation

# 1. Install Rust via rustup (official toolchain manager)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 2. Add Rust to your PATH
source $HOME/.cargo/env

# 3. Install WASM target
rustup target add wasm32-unknown-unknown

# 4. Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# 5. Clone the repository
git clone https://github.com/mohammedX6/rust-audio-dsp.git
cd rust-audio-dsp

# 6. Install Node.js dependencies
npm install

# 7. Build the WASM module
npm run build

# 8. Start local server
npm start

# 9. Open browser
open http://localhost:8000

Important: Rust Setup

This project requires rustup (the official Rust toolchain manager). If you installed Rust via Homebrew, you may encounter errors. The npm scripts automatically source the Rust environment from ~/.cargo/env.

To verify your setup:

# Should output: /Users/YOUR_USERNAME/.cargo/bin/rustc
which rustc

# Should list: wasm32-unknown-unknown
rustup target list --installed

If you have Rust via Homebrew, rustup will work alongside it. The package.json scripts are configured to use rustup's Rust installation.

Development

Project Structure

rust-audio-dsp/
├── src/
│   └── lib.rs          # Rust DSP implementation
├── docs/               # Documentation
│   ├── ARCHITECTURE.md
│   ├── RUST_GUIDE.md
│   ├── QUICK_REFERENCE.md
│   └── ...
├── pkg/                # Compiled WASM output (generated)
├── index.html          # UI
├── main.js             # Web Audio API integration
├── style.css           # Styling
├── Cargo.toml          # Rust dependencies
└── README.md           # This file

Building

# Development build
wasm-pack build --target web

# Release build (optimized)
wasm-pack build --target web --release

Key Technologies

  • Rust - High-performance DSP processing
  • WebAssembly - Near-native speed in browser
  • Web Audio API - Browser audio integration
  • Canvas API - Real-time visualizations

Documentation

Comprehensive documentation is available in the docs/ folder:

How It Works

Audio Signal Flow

Microphone → Browser Noise Suppression → JavaScript Noise Gate
    ↓
Rust/WASM DSP Processing:
    • Gain
    • Distortion
    • Filters (Biquad)
    • Delay/Echo
    ↓
Speakers

DSP Architecture

  • Buffer Size: 4096 samples (16 KB per call)
  • Sample Rate: 48 kHz (professional quality)
  • Bit Depth: 32-bit float (maximum precision)
  • Latency: < 1 ms processing time

Performance Metrics

  • Processing Speed: ~170x realtime
  • CPU Usage: 0.5-5% typical
  • Memory: ~192 KB for Rust processor
  • Data Rate: 192 KB/sec uncompressed

Usage Tips

Best Results

  1. Use headphones - Prevents feedback
  2. Start with Clean preset - Test baseline
  3. Try different presets - Explore effects
  4. Adjust individual controls - Fine-tune sound
  5. Watch the visualizer - See your audio!

Effect Combinations

  • Radio DJ: Podcast + slight compression
  • Sci-Fi Voice: Alien + Echo
  • Haunted: Ghost + Cave reverb
  • Retro Game: Robot + Short delay

Technical Details

Rust Implementation

  • Zero-copy buffer processing
  • Efficient biquad filters
  • Circular delay buffer
  • Optimized for WASM

JavaScript Integration

  • Web Audio API ScriptProcessor
  • Real-time visualization (60 FPS)
  • Performance monitoring
  • Browser noise suppression

Contributing

Contributions are welcome! Feel free to:

  • Add new effects
  • Improve presets
  • Enhance visualizations
  • Fix bugs
  • Improve documentation

License

MIT License - see LICENSE file for details

Acknowledgments

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published