mirror of
https://github.com/mii443/maudio-router.git
synced 2025-08-22 16:05:35 +00:00
resampling using rubato
This commit is contained in:
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -495,6 +495,7 @@ dependencies = [
|
||||
"cpal",
|
||||
"num",
|
||||
"num-traits",
|
||||
"rubato",
|
||||
"rustfft",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
@ -844,6 +845,15 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
|
||||
|
||||
[[package]]
|
||||
name = "realfft"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "953d9f7e5cdd80963547b456251296efc2626ed4e3cbf36c869d9564e0220571"
|
||||
dependencies = [
|
||||
"rustfft",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
@ -882,6 +892,18 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "rubato"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6dd52e80cfc21894deadf554a5673002938ae4625f7a283e536f9cf7c17b0d5"
|
||||
dependencies = [
|
||||
"num-complex",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"realfft",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
|
@ -13,3 +13,4 @@ num-traits = "0.2.18"
|
||||
rustfft = "6.2.0"
|
||||
serde = { version = "1.0.196", features = ["derive"] }
|
||||
serde_yaml = "0.9.31"
|
||||
rubato = "0.14.1"
|
@ -0,0 +1 @@
|
||||
pub mod resampling;
|
@ -0,0 +1,21 @@
|
||||
use rubato::{Resampler, SincFixedIn, SincInterpolationParameters, SincInterpolationType, WindowFunction};
|
||||
|
||||
pub fn resampling(current_sample_rate: u32, target_sample_rate: u32, data: Vec<Vec<f32>>) -> Vec<Vec<f32>> {
|
||||
let params = SincInterpolationParameters {
|
||||
sinc_len: 256,
|
||||
f_cutoff: 0.95,
|
||||
interpolation: SincInterpolationType::Linear,
|
||||
oversampling_factor: 128,
|
||||
window: WindowFunction::BlackmanHarris2,
|
||||
};
|
||||
|
||||
let mut resampler = SincFixedIn::<f32>::new(
|
||||
current_sample_rate as f64 / target_sample_rate as f64,
|
||||
2.0,
|
||||
params,
|
||||
data[0].len(),
|
||||
data.len()
|
||||
).unwrap();
|
||||
|
||||
resampler.process(&data, None).unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user