#conversion #converting #channel #libsamplerate

samplerate

A library based on libsamplerate for converting samplerates

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

#215 in Audio

Download history 1819/week @ 2024-07-21 2855/week @ 2024-07-28 3695/week @ 2024-08-04 2331/week @ 2024-08-11 5190/week @ 2024-08-18 5921/week @ 2024-08-25 6460/week @ 2024-09-01 5958/week @ 2024-09-08 4410/week @ 2024-09-15 5276/week @ 2024-09-22 6790/week @ 2024-09-29 8063/week @ 2024-10-06 7433/week @ 2024-10-13 6072/week @ 2024-10-20 8221/week @ 2024-10-27 8524/week @ 2024-11-03

31,462 downloads per month
Used in 5 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