#audio-processing #music #audio-library #audio-samples #sample #sample-rate #low-level

no-std soundtouch

A utility wrapper around the SoundTouch C++ audio library

8 releases (4 breaking)

0.5.0 May 11, 2025
0.4.3 May 11, 2025
0.4.2 Aug 31, 2024
0.4.1 Jun 27, 2024
0.1.0 Oct 15, 2023

#348 in Audio

Download history 26/week @ 2025-03-15 37/week @ 2025-03-22 41/week @ 2025-03-29 29/week @ 2025-04-05 30/week @ 2025-04-12 22/week @ 2025-04-19 26/week @ 2025-04-26 38/week @ 2025-05-03 375/week @ 2025-05-10 61/week @ 2025-05-17 36/week @ 2025-05-24 15/week @ 2025-05-31 27/week @ 2025-06-07 21/week @ 2025-06-14 37/week @ 2025-06-21 59/week @ 2025-06-28

145 downloads per month
Used in 2 crates (via termusic-playback)

LGPL-2.1

335KB
256 lines

soundtouch

Crates.io Documentation

A safe utility wrapper around the SoundTouch C++ audio library. The API is very similar to the original C++ API. For dynamic and static linking configuration see soundtouch-ffi's linking behavior.

Most of the documentation is copied from the SoundTouch repository.

High Level Example

use soundtouch::{SoundTouch, Setting};

let mut soundtouch = SoundTouch::new();
soundtouch
    .set_channels(2)
    .set_sample_rate(44100)
    .set_tempo(1.10)
    // Recommended setting to speed up processing
    .set_setting(Setting::UseQuickseek, 1);

// use actual audio samples here
let samples = vec![0.0; 44100 * 2];
let output_samples = soundtouch.generate_audio(&samples);

// do something with output_samples

Low Level Example

use soundtouch::{SoundTouch, Setting};

let mut soundtouch = SoundTouch::new();
soundtouch
    .set_channels(2)
    .set_sample_rate(44100)
    .set_tempo(1.10)    
    // Recommended setting to speed up processing
    .set_setting(Setting::UseQuickseek, 1);

// use actual audio samples here
let mut samples = vec![0.0; 44100 * 2];

const BUF_SIZE: usize = 6720;
let mut new_samples: [f32; BUF_SIZE] = [0.0; BUF_SIZE];
let mut output_samples: Vec<f32> = Vec::with_capacity(samples.len());
soundtouch.put_samples(&samples, samples.len() / 2);
let mut n_samples = 1;
while n_samples != 0 {
    n_samples = soundtouch.receive_samples(
        new_samples.as_mut_slice(),
        BUF_SIZE / 2
        );
    output_samples.extend_from_slice(&new_samples);
}
soundtouch.flush();

// do something with output_samples

Both examples should produce the same output.

Dependencies

~1–3.5MB
~52K SLoC