1个不稳定版本
0.1.0 | 2022年7月11日 |
---|
939 在 音频
每月 75次下载
30KB
682 代码行
Samplerate-rs
Rust的采样率转换库。
这是一个对samplerate crate的分支,使用libsamplerate的纯C2Rust转换版本代替C库的绑定。这允许在无需安装CMake的情况下编译。
示例
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());
}
依赖项
~27MB
~369K SLoC