Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rubato"
version = "1.0.1"
rust-version = "1.74"
version = "2.0.0"
rust-version = "1.85"
authors = ["HEnquist <henrik.enquist@gmail.com>"]
description = "Asynchronous resampling library intended for audio data"
license = "MIT"
Expand All @@ -25,24 +25,24 @@ realfft = { version = "3.5.0", optional = true }
num-complex = { version = "0.4", optional = true }
num-integer = "0.1.45"
num-traits = "0.2"
#audioadapter = {version = "2.0.0", path = "../audioadapter-rs/audioadapter"}
audioadapter = "2.0"
#audioadapter-buffers = {version = "2.0.0", path = "../audioadapter-rs/audioadapter-buffers"}
audioadapter-buffers = "2.0"
#audioadapter = {version = "3.0.0", path = "../audioadapter-rs/audioadapter"}
audioadapter = "3.0"
#audioadapter-buffers = {version = "3.0.0", path = "../audioadapter-rs/audioadapter-buffers"}
audioadapter-buffers = "3.0"
visibility = "0.1.1"
windowfunctions = "0.1.1"

[dev-dependencies]
env_logger = "0.10.0"
env_logger = "0.11.0"
criterion = "0.8"
rand = "0.8.5"
rand = "0.10.0"
num-traits = "0.2.15"
log = "0.4.18"
approx = "0.5.1"
test-log = "0.2.16"
test-case = "3"
#audioadapter-sample = {version = "2.0.0", path = "../audioadapter-rs/audioadapter-sample"}
audioadapter-sample = "2.0"
#audioadapter-sample = {version = "3.0.0", path = "../audioadapter-rs/audioadapter-sample"}
audioadapter-sample = "3.0"

[[bench]]
name = "resamplers"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ Many audio editors, for example Audacity, are also able to directly import and e

## Compatibility

The `rubato` crate requires rustc version 1.74 or newer.
The `rubato` crate requires rustc version 1.85 or newer.

## Changelog
- v2.0.0
- Update to `audioadapter` 3.0.
- Add re-export of `audioadapter-buffers`.
- v1.0.1
- Fix calculation in process_all_needed_output_len method.
- v1.0.0
Expand Down
88 changes: 87 additions & 1 deletion src/asynchro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ mod tests {
};
use crate::{Async, FixedAsync};
use audioadapter_buffers::direct::SequentialSliceOfVecs;
use rand::Rng;
use test_case::test_matrix;

fn basic_params() -> SincInterpolationParameters {
Expand Down Expand Up @@ -815,4 +814,91 @@ mod tests {
resampler.set_chunk_size(600).unwrap();
check_output!(resampler, f64);
}

fn process_and_get_frame_counts(resampler: &mut Async<f64>) -> (usize, usize) {
let input_frames = resampler.input_frames_next();
let output_frames_max = resampler.output_frames_max();
let input_data = vec![vec![0.25; input_frames]; 2];
let input = SequentialSliceOfVecs::new(&input_data, 2, input_frames).unwrap();

let mut output_data = vec![vec![0.0; output_frames_max]; 2];
let mut output =
SequentialSliceOfVecs::new_mut(&mut output_data, 2, output_frames_max).unwrap();

let (consumed_frames, produced_frames) = resampler
.process_into_buffer(&input, &mut output, None)
.unwrap();
(consumed_frames, produced_frames)
}

fn process_chunks_and_get_total_frame_counts(
resampler: &mut Async<f64>,
nbr_chunks: usize,
) -> (usize, usize) {
(0..nbr_chunks).fold((0, 0), |(sum_in, sum_out), _| {
let (frames_in, frames_out) = process_and_get_frame_counts(resampler);
(sum_in + frames_in, sum_out + frames_out)
})
}

fn assert_ratio_within_tolerance(
total_in: usize,
total_out: usize,
expected_ratio: f64,
tolerance: f64,
label: &str,
) {
let measured_ratio = total_out as f64 / total_in as f64;
let lower = expected_ratio - tolerance;
let upper = expected_ratio + tolerance;
assert!(
measured_ratio >= lower && measured_ratio <= upper,
"{} ratio out of range: got {}, expected {} +/- {} (out {}, in {})",
label,
measured_ratio,
expected_ratio,
tolerance,
total_out,
total_in,
);
}

fn check_relative_ratio_changes_frame_ratio(mut resampler: Async<f64>) {
let nbr_chunks = 8;
let tolerance = 0.01;

let (baseline_in, baseline_out) =
process_chunks_and_get_total_frame_counts(&mut resampler, nbr_chunks);
assert_ratio_within_tolerance(baseline_in, baseline_out, 1.0, tolerance, "Baseline");

// Lower ratio speeds up output.
resampler.set_resample_ratio_relative(0.75, false).unwrap();
let (lower_in, lower_out) =
process_chunks_and_get_total_frame_counts(&mut resampler, nbr_chunks);
assert_ratio_within_tolerance(lower_in, lower_out, 0.75, tolerance, "0.75x");

// Higher ratio slows down output.
resampler.set_resample_ratio_relative(1.25, false).unwrap();
let (higher_in, higher_out) =
process_chunks_and_get_total_frame_counts(&mut resampler, nbr_chunks);
assert_ratio_within_tolerance(higher_in, higher_out, 1.25, tolerance, "1.25x");
}

#[test_log::test(test_matrix(
[FixedAsync::Input, FixedAsync::Output]
))]
fn poly_relative_ratio_changes_frame_ratio(fixed: FixedAsync) {
let resampler =
Async::<f64>::new_poly(1.0, 4.0, PolynomialDegree::Cubic, 1024, 2, fixed).unwrap();
check_relative_ratio_changes_frame_ratio(resampler);
}

#[test_log::test(test_matrix(
[FixedAsync::Input, FixedAsync::Output]
))]
fn sinc_relative_ratio_changes_frame_ratio(fixed: FixedAsync) {
let params = basic_params();
let resampler = Async::<f64>::new_sinc(1.0, 4.0, &params, 1024, 2, fixed).unwrap();
check_relative_ratio_changes_frame_ratio(resampler);
}
}
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate log;

pub use audioadapter;
pub use audioadapter_buffers;

use audioadapter::{Adapter, AdapterMut};
use audioadapter_buffers::owned::InterleavedOwned;
Expand Down Expand Up @@ -679,11 +680,10 @@ pub mod tests {
($resampler:ident) => {
let frames_in = $resampler.input_frames_next();

let mut rng = rand::thread_rng();
let mut input_data = vec![vec![0.0f64; frames_in]; 2];
input_data
.iter_mut()
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rng.gen()));
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rand::random()));

let input = SequentialSliceOfVecs::new(&input_data, 2, frames_in).unwrap();

Expand Down Expand Up @@ -718,11 +718,10 @@ pub mod tests {
($resampler:ident) => {
let frames_in = $resampler.input_frames_next();

let mut rng = rand::thread_rng();
let mut input_data_1 = vec![vec![0.0f64; frames_in]; 2];
input_data_1
.iter_mut()
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rng.gen()));
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rand::random()));

let offset = 123;
let mut input_data_2 = vec![vec![0.0f64; frames_in + offset]; 2];
Expand Down Expand Up @@ -771,11 +770,10 @@ pub mod tests {
($resampler:ident) => {
let frames_in = $resampler.input_frames_next();

let mut rng = rand::thread_rng();
let mut input_data = vec![vec![0.0f64; frames_in]; 2];
input_data
.iter_mut()
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rng.gen()));
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rand::random()));

let input = SequentialSliceOfVecs::new(&input_data, 2, frames_in).unwrap();

Expand Down Expand Up @@ -823,11 +821,10 @@ pub mod tests {
($resampler:ident) => {
let frames_in = $resampler.input_frames_next();

let mut rng = rand::thread_rng();
let mut input_data = vec![vec![0.0f64; frames_in]; 2];
input_data
.iter_mut()
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rng.gen()));
.for_each(|ch| ch.iter_mut().for_each(|s| *s = rand::random()));

let input = SequentialSliceOfVecs::new(&input_data, 2, frames_in).unwrap();

Expand Down
7 changes: 2 additions & 5 deletions src/sinc_interpolator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ mod tests {
use super::SincInterpolator;
use crate::WindowFunction;
use num_traits::Float;
use rand::Rng;
use test_log::test;

fn get_sinc_interpolated<T: Float>(wave: &[T], index: usize, sinc: &[T]) -> T {
Expand All @@ -169,10 +168,9 @@ mod tests {

#[test]
fn test_scalar_interpolator_64() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f64>());
wave.push(rand::random::<f64>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand All @@ -188,10 +186,9 @@ mod tests {

#[test]
fn test_scalar_interpolator_32() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f32>());
wave.push(rand::random::<f32>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand Down
7 changes: 2 additions & 5 deletions src/sinc_interpolator/sinc_interpolator_avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ mod tests {
use crate::sinc_interpolator::SincInterpolator;
use crate::WindowFunction;
use num_traits::Float;
use rand::Rng;
use test_log::test;

fn get_sinc_interpolated<T: Float>(wave: &[T], index: usize, sinc: &[T]) -> T {
Expand All @@ -232,10 +231,9 @@ mod tests {

#[test]
fn test_avx_interpolator_64() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f64>());
wave.push(rand::random::<f64>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand All @@ -259,10 +257,9 @@ mod tests {

#[test]
fn test_avx_interpolator_32() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f32>());
wave.push(rand::random::<f32>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand Down
7 changes: 2 additions & 5 deletions src/sinc_interpolator/sinc_interpolator_neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ mod tests {
use crate::sinc_interpolator::SincInterpolator;
use crate::WindowFunction;
use num_traits::Float;
use rand::Rng;
use test_log::test;

fn get_sinc_interpolated<T: Float>(wave: &[T], index: usize, sinc: &[T]) -> T {
Expand All @@ -236,10 +235,9 @@ mod tests {

#[test]
fn test_neon_interpolator_64() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f64>());
wave.push(rand::random::<f64>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand All @@ -255,10 +253,9 @@ mod tests {

#[test]
fn test_neon_interpolator_32() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f32>());
wave.push(rand::random::<f32>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand Down
7 changes: 2 additions & 5 deletions src/sinc_interpolator/sinc_interpolator_sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ mod tests {
use crate::sinc_interpolator::SincInterpolator;
use crate::WindowFunction;
use num_traits::Float;
use rand::Rng;
use test_log::test;

fn get_sinc_interpolated<T: Float>(wave: &[T], index: usize, sinc: &[T]) -> T {
Expand All @@ -244,10 +243,9 @@ mod tests {

#[test]
fn test_sse_interpolator_64() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f64>());
wave.push(rand::random::<f64>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand All @@ -263,10 +261,9 @@ mod tests {

#[test]
fn test_sse_interpolator_32() {
let mut rng = rand::thread_rng();
let mut wave = Vec::new();
for _ in 0..2048 {
wave.push(rng.gen::<f32>());
wave.push(rand::random::<f32>());
}
let sinc_len = 256;
let f_cutoff = 0.94733715;
Expand Down
1 change: 0 additions & 1 deletion src/synchro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ mod tests {
};
use approx::assert_abs_diff_eq;
use audioadapter_buffers::direct::SequentialSliceOfVecs;
use rand::Rng;
use test_case::test_matrix;

#[test_log::test]
Expand Down
Loading