#audio-processing #music #audio-samples #audio-library

no-std soundtouch

A utility wrapper around the SoundTouch C++ audio library

5 releases (3 breaking)

0.4.1 Jun 27, 2024
0.4.0 Oct 20, 2023
0.3.0 Oct 17, 2023
0.2.0 Oct 16, 2023
0.1.0 Oct 15, 2023

#198 in Audio

Download history 106/week @ 2024-03-19 21/week @ 2024-03-26 42/week @ 2024-04-02 47/week @ 2024-04-09 19/week @ 2024-04-16 17/week @ 2024-04-23 64/week @ 2024-04-30 22/week @ 2024-05-07 5/week @ 2024-05-14 7/week @ 2024-05-21 13/week @ 2024-05-28 11/week @ 2024-06-04 59/week @ 2024-06-11 15/week @ 2024-06-18 178/week @ 2024-06-25 9/week @ 2024-07-02

264 downloads per month

LGPL-2.1

330KB
255 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.

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–3MB
~48K SLoC