https://github.com/prior99/rust-samplerate
High level Rust bindings for libsamplerate.
https://github.com/prior99/rust-samplerate
Last synced: 4 months ago
JSON representation
High level Rust bindings for libsamplerate.
- Host: GitHub
- URL: https://github.com/prior99/rust-samplerate
- Owner: Prior99
- License: bsd-2-clause
- Created: 2018-10-26T23:35:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-15T09:44:32.000Z (almost 3 years ago)
- Last Synced: 2025-02-27T16:17:34.812Z (over 1 year ago)
- Language: Rust
- Size: 24.4 KB
- Stars: 16
- Watchers: 3
- Forks: 16
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Samplerate
[](https://travis-ci.org/Prior99/rust-samplerate)
[](https://docs.rs/samplerate/)
A samplerate conversion library for Rust.
This library provides a high-level API for [libsamplerate-sys](https://github.com/Prior99/libsamplerate-sys) and hence is built on top of [libsamplerate](http://www.mega-nerd.com/SRC/api.html).
# Example
```rust
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 = (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());
}
```