#audio #samplerate

samplerate

A library based on libsamplerate for converting samplerates

8 releases

0.2.1 Jul 7, 2019
0.2.0 Apr 24, 2019
0.1.5 Oct 30, 2018

#51 in Audio

Download history 26/week @ 2019-04-24 1/week @ 2019-05-01 20/week @ 2019-05-08 18/week @ 2019-05-15 7/week @ 2019-05-22 28/week @ 2019-05-29 8/week @ 2019-06-05 8/week @ 2019-06-12 21/week @ 2019-06-19 42/week @ 2019-06-26 71/week @ 2019-07-03 30/week @ 2019-07-10 4/week @ 2019-07-17 2/week @ 2019-07-24 14/week @ 2019-07-31

81 downloads per month

BSD-2-Clause

26KB
461 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

~4–5.5MB
~37K SLoC