dasp-rs 0.5.0

Pure-Rust digital audio signal processing: I/O, STFT/CQT, spectral & MIR features, pitch, and music/phonetics notation.
Documentation

dasp-rs

Crates.io Documentation License: MIT

dasp-rs is a pure-Rust library for digital audio signal processing, analysis, and synthesis as a fast, dependency-light crate that builds with no system libraries. It is aimed at developers, audio/ML researchers, phoneticians, and music-information-retrieval work.

Highlights

  • Pure Rust, no system dependencies. No OpenBLAS, pkg-config, or C toolchain required (unlike earlier versions). Builds out of the box on Linux, macOS, and Windows.
  • Standards-based STFT: periodic Hann window and centered (reflect-padded) framing by default, the conventional choices for spectral analysis.
  • Ergonomic builder APIs for the common entry points (Decoder, stft, istft, spectral, yin/pyin, cqt, tempo, griffinlim, clicks, …).
  • WAV I/O for 8/16/24/32-bit PCM and 32-bit float, with segment loading, on-load resampling / mono conversion, and streaming readers for large files.
  • Broad feature set: time–frequency transforms, spectral/MIR features, pitch & tuning, magnitude scaling & loudness weighting, signal generation, and extensive music/phonetics notation utilities.
  • Parallelized with rayon where it helps.

Installation

[dependencies]
dasp-rs = "0.5"

No additional system packages are required.

Quick start

use dasp_rs::io::Decoder;
use dasp_rs::proc::stft;
use dasp_rs::feat::spectral;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load a WAV file as mono at 22.05 kHz
    let audio = Decoder::new("input.wav")
        .sample_rate(22_050)
        .mono()
        .load()?;

    // Short-Time Fourier Transform
    let spec = stft(&audio.samples).n_fft(2048).hop_length(512).compute()?;
    println!("STFT: {} bins x {} frames", spec.nrows(), spec.ncols());

    // MFCCs via the spectral-feature builder
    let cc = spectral(&audio.samples, audio.sample_rate)
        .n_fft(2048)
        .hop_length(512)
        .mfcc()?;
    println!("MFCC: {:?}", cc.shape());

    Ok(())
}

The crate root re-exports the API by concern: types, io, ops, proc, feat, pitch, mag, generate, util, and a prelude.

Features

Audio I/O — io / types

  • AudioDataf32 sample container (samples, sample_rate, channels) with to_mono, split_channels, duration, frame_count, to_raw.
  • Decoder — builder for loading: .sample_rate(), .mono(), .offset(), .duration(), .load().
  • load — load a WAV (with optional resample, mono, offset, duration).
  • export — write a 32-bit float WAV.
  • stream / stream_lazy — block/streaming readers for large files (stream_lazy delivers Result items so mid-stream decode errors surface).
  • Reads 8/16/24/32-bit PCM and 32-bit float WAV.

Sample-wise operations — ops

  • mix_signals, subtract_signals, multiply_signals, divide_signals, scalar_operation.

Signal processing — proc

  • Channels / amplitude: to_mono, amplify, attenuate, normalize.
  • Mixing: stereo_mix, multi_channel_mix, dry_wet_mix.
  • Panning: stereo_pan, multi_channel_pan.
  • Resampling: resample (sinc-based, via rubato).
  • Time domain: delay, time_reversal, time_crop, zero_padding, autocorrelate, lpc, zero_crossings, mu_compress, mu_expand, log_energy.
  • Time–frequency: stft / istft, cqt / icqt, vqt, pseudo_cqt, hybrid_cqt, fmt, iirt, reassigned_spectrogram, magphase, phasor.
  • Effects: trim, split_silence, time_stretch, pitch_shift, remix.

Feature extraction — feat

  • Spectral / MIR via the spectral(&y, sr) builder with terminal methods: .melspectrogram(), .mfcc(), .rms(), .chroma_cqt(), .chroma_cens(), .spectral_centroid(), .spectral_bandwidth(), .spectral_contrast(), .spectral_flatness(), .spectral_rolloff(), .spectral_flux(), .spectral_entropy(), .poly_features(), .tonnetz(), .pitch_chroma(), .hpss(), .pitch_autocorr(), .vad_features(), .spectral_subband_centroids(), .formant_frequencies(). Also chroma_stft, chroma_vqt, and cmvn(&feats) builders.
  • Harmonics: interp_harmonics, salience, f0_harmonics, phase_vocoder.
  • Rhythm: tempo, tempogram, ratio tempogram, fourier_tempogram, onset_strength_multi.
  • Manipulation: stack_memory, temporal_kurtosis, zero_crossing_rate.
  • Masks & normalisation: softmask, normalize (L1/L2/L∞), sparsify_rows.
  • Phase reconstruction: griffinlim, griffinlim_cqt.
  • Inverse transforms: compute_delta, mel_to_stft, mel_to_audio, mfcc_to_mel, mfcc_to_audio.
  • Harmonic/percussive separation: harmonic, percussive convenience builders.
  • Segmentation & structure: recurrence_matrix, cross_similarity, agglomerative, subsegment, path_enhance, timelag_filter.
  • Sequence / HMM: dtw, viterbi, viterbi_discriminative, viterbi_binary; transition-matrix builders transition_loop, transition_local, transition_uniform, transition_cycle, transition_acyclic.
  • NMF decomposition: decompose (Lee–Seung multiplicative updates).

Pitch & tuning — pitch

  • yin(&y, fmin, fmax), pyin(&y, fmin, fmax) — fundamental-frequency estimation (builders: .sample_rate(), .frame_length(), .hop_length(), .compute()).
  • piptrack — spectral peak pitch tracking.
  • estimate_tuning(&y) (builder), pitch_tuning — tuning-deviation estimation.

Magnitude & loudness — mag

  • amplitude_to_db, db_to_amplitude, power_to_db, db_to_power.
  • perceptual_weighting, frequency_weighting, multi_frequency_weighting.
  • a_weighting, b_weighting, c_weighting, d_weighting.
  • pcen — per-channel energy normalization.

Signal generation — generate

  • tone (sine), chirp (linear sweep), clicks.

Utilities — util

  • Time / framing: get_duration, get_duration_from_path, get_samplerate, frames_to_samples, frames_to_time, samples_to_frames, samples_to_time, time_to_frames, time_to_samples, blocks_to_frames, blocks_to_samples, blocks_to_time, samples_like, times_like.
  • Frequency / scales: hz_to_midi, midi_to_hz, hz_to_note, note_to_hz, note_to_midi, midi_to_note, hz_to_mel, mel_to_hz, hz_to_octs, octs_to_hz, a4_to_tuning, tuning_to_a4, fft_frequencies, cqt_frequencies, mel_frequencies, tempo_frequencies, fourier_tempo_frequencies.
  • Array / signal utilities: localmax, localmin, peak_pick, frame, pad_center, fix_length, sync (Mean/Median/Max/Min), match_intervals, expand_to.
  • Notation:
    • Western: key_to_notes, key_to_degrees, fifths_to_note.
    • Carnatic: mela_to_svara, mela_to_degrees, list_mela, hz_to_svara_c, midi_to_svara_c, note_to_svara_c.
    • Hindustani: thaat_to_degrees, list_thaat, hz_to_svara_h, midi_to_svara_h, note_to_svara_h.
    • Just intonation: interval_to_fjs, hz_to_fjs, interval_frequencies, pythagorean_intervals, plimit_intervals.

Full item-level documentation, with signatures and examples, is on docs.rs.

Audio format support

dasp-rs reads and writes WAV via hound. Internally all audio is f32.

Format Read Write
8-bit PCM
16-bit PCM
24-bit PCM
32-bit PCM
32-bit float

export writes 32-bit float WAV (lossless for the internal representation).

Performance

  • rayon-based parallelism for large workloads.
  • Streaming readers (stream, stream_lazy) keep memory bounded for large files.
  • FFTs via rustfft; resampling via rubato; linear algebra via pure-Rust nalgebra.

Contributing

Issues and pull requests are welcome on GitHub. Please run cargo test before submitting.

License

Licensed under the MIT License. See LICENSE.

Acknowledgements

Thanks to @Levitanus for reporting the OpenBLAS build failure and 24-bit decoding issues, and for the diagnosis in #4.