11 releases

Uses old Rust 2015

0.2.4 Jan 14, 2021
0.2.3 Nov 19, 2020
0.2.2 Apr 29, 2020
0.2.1 Jul 7, 2019
0.1.5 Oct 30, 2018

#187 in Audio

Download history 4401/week @ 2023-12-23 2755/week @ 2023-12-30 3310/week @ 2024-01-06 3250/week @ 2024-01-13 3316/week @ 2024-01-20 3621/week @ 2024-01-27 5407/week @ 2024-02-03 4229/week @ 2024-02-10 1732/week @ 2024-02-17 2169/week @ 2024-02-24 2703/week @ 2024-03-02 2942/week @ 2024-03-09 4344/week @ 2024-03-16 4775/week @ 2024-03-23 3292/week @ 2024-03-30 4223/week @ 2024-04-06

17,093 downloads per month
Used in 4 crates

BSD-2-Clause

28KB
482 lines

Samplerate

Build Status Docs

A samplerate conversion library for Rust. This library provides a high-level API for libsamplerate-sys and hence is built on top of libsamplerate.

Example

extern crate samplerate;
extern crate hound;

use samplerate::{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

~4MB