#sample-rate #version #pure #fork #transpiled #c2rust

samplerate-rs

A fork of the samplerate crate that uses the pure C2Rust transpiled version of libsamplerate

1 unstable release

0.1.0 Jul 11, 2022

#1289 in Audio

Download history 2/week @ 2024-11-13 4/week @ 2024-11-20 3/week @ 2024-12-04 8/week @ 2024-12-11 57/week @ 2024-12-18 17/week @ 2025-01-15 23/week @ 2025-01-22 16/week @ 2025-01-29 61/week @ 2025-02-05 30/week @ 2025-02-12 43/week @ 2025-02-19 48/week @ 2025-02-26

188 downloads per month

BSD-2-Clause

30KB
682 lines

Samplerate-rs

Docs

A samplerate conversion library for Rust.

This is a fork of the samplerate crate the uses the pure C2Rust transpiled version of libsamplerate in place of the bindings to the C library. This allows compilation without needing to have CMake installed.

Example

extern crate samplerate;
extern crate hound;

use samplerate_rs::{convert, ConverterType};
use hound::{WavSpec, WavWriter, SampleFormat};

fn main() {
    // Generate a 880Hz sine wave for 1 second in 44100Hz with one channel.
    let freq = std::f32::consts::PI * 880f32 / 44100f32;
    let input: Vec<f32> = (0..44100 * 5).map(|i| (freq * i as f32).sin()).collect();

    // Resample the input from 44100Hz to 48000Hz.
    let resampled = convert(44100, 48000, 1, ConverterType::SincBestQuality, &input).unwrap();

    // Write the resampled pcm data to disk.
    let mut writer = WavWriter::create("resampled.wav", WavSpec {
        channels: 1,
        sample_rate: 48000,
        bits_per_sample: 32,
        sample_format: SampleFormat::Float,
    }).unwrap();
    resampled.iter().for_each(|i| writer.write_sample(*i).unwrap());
}

Dependencies

~27MB
~369K SLoC