Skip to content

Commit f1207d1

Browse files
authored
Merge pull request #118 from HEnquist/patch101
Fix process_all length calc
2 parents 2cc6bdb + 582018d commit f1207d1

4 files changed

Lines changed: 20 additions & 27 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rubato"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
rust-version = "1.74"
55
authors = ["HEnquist <henrik.enquist@gmail.com>"]
66
description = "Asynchronous resampling library intended for audio data"

README.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ The resamplers allow specifying which side should have a fixed size.
8787
The input chunk size will vary depending on how many new samples the resampler needs to calculate the output.
8888
This is meant to be used for resampling data that will be sent to some target that requires fixed size chunks.
8989
* **Both input and output fixed**: Both input and output chunk sizes are fixed.
90-
This is only available for the synchronous resampler.
90+
This mode is only available for the synchronous resampler.
9191
In this mode, the chunk size parameter is used as a hint,
9292
and the actual chunk sizes are calculated to fit the resampling ratio exactly.
9393
For example, a 44.1 kHz to 48 kHz resampler must use an input chunk size that is a multiple of 147,
9494
and an output chunk size that is a multiple of 160, in order to maintain the correct resampling ratio.
95+
96+
This mode avoids some internal buffering compared to fixed input or fixed output modes,
97+
and is therefore somewhat more efficient.
98+
9599
For asynchronous resamplers, fixing both input and output chunk sizes is not possible
96100
since the resampling ratio can change, requiring at least one side to be variable.
97101

@@ -130,8 +134,11 @@ The resampler trait provides the `Resampler::process_all_into_buffer()` method
130134
for resampling a full audio clip of arbitrary length.
131135
To use this, create a resampler of suitable type, for example `Fft` which is fast and gives good quality.
132136
The chunk size can be chosen arbitrarily. Start with a chunk size of for example 1024.
133-
Then call `Resampler::process_all_needed_output_len()` to find out the length of the result.
134-
Create an output buffer, and call `Resampler::process_all_into_buffer()`.
137+
In this application, the exact input or output chunk sizes are not important
138+
and therefore the `FixedSync::Both` setting can be used for the `Fft` resampler.
139+
After creating the resampler, call `Resampler::process_all_needed_output_len()`
140+
to find out the minimum length of the needed output buffer.
141+
Create a suitable output buffer, and then call `Resampler::process_all_into_buffer()`.
135142

136143
If there is more than one clip to resample from and to the same sample rates,
137144
the same resampler should be reused.
@@ -232,27 +239,11 @@ Resample a dummy audio file from 44100 to 48000 Hz.
232239
See also the "process_f64" example that can be used to process a file from disk.
233240
```rust
234241
use rubato::{
235-
Resampler, Async, FixedAsync, Indexing,
236-
SincInterpolationType, SincInterpolationParameters,
237-
WindowFunction
242+
Resampler, Fft, FixedSync, Indexing
238243
};
239244
use audioadapter_buffers::direct::InterleavedSlice;
240245

241-
let params = SincInterpolationParameters {
242-
sinc_len: 256,
243-
f_cutoff: 0.95,
244-
interpolation: SincInterpolationType::Linear,
245-
oversampling_factor: 256,
246-
window: WindowFunction::BlackmanHarris2,
247-
};
248-
let mut resampler = Async::<f64>::new_sinc(
249-
48000 as f64 / 44100 as f64,
250-
2.0,
251-
&params,
252-
1024,
253-
2,
254-
FixedAsync::Input,
255-
).unwrap();
246+
let mut resampler = Fft::<f64>::new(48000, 44100, 1024, 2, 2, FixedSync::Both).unwrap();
256247

257248
// create a short dummy audio clip, assuming it's stereo stored as interleaved f64 values
258249
let audio_clip = vec![0.0; 2*10000];
@@ -322,6 +313,8 @@ Many audio editors, for example Audacity, are also able to directly import and e
322313
The `rubato` crate requires rustc version 1.74 or newer.
323314

324315
## Changelog
316+
- v1.0.1
317+
- Fix calculation in process_all_needed_output_len method.
325318
- v1.0.0
326319
- New API using the AudioAdapter crate to handle different buffer layouts and sample formats.
327320
- Merged the FixedIn, FixedOut and FixedInOut resamplers into single types that supports all modes.

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ impl fmt::Display for ResampleError {
198198
Self::InsufficientInputBufferSize { expected, actual } => {
199199
write!(
200200
f,
201-
"Insufficient buffer size {}, expected {} frames",
201+
"Insufficient input buffer size {}, expected {} frames",
202202
actual, expected
203203
)
204204
}
205205
Self::InsufficientOutputBufferSize { expected, actual } => {
206206
write!(
207207
f,
208-
"Insufficient buffer size {}, expected {} frames",
208+
"Insufficient output buffer size {}, expected {} frames",
209209
actual, expected
210210
)
211211
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ where
220220
indexing.output_offset += nbr_out;
221221
if frames_to_trim > 0 && output_len > frames_to_trim {
222222
debug!(
223-
"output, {} is longer than delay to trim, {}, trimming..",
223+
"output, {} is longer than delay to trim, {}, trimming..",
224224
output_len, frames_to_trim
225225
);
226226
// move useful output data to start of output buffer
@@ -262,9 +262,9 @@ where
262262
/// [process_all_into_buffer](Resampler::process_all_into_buffer).
263263
fn process_all_needed_output_len(&mut self, input_len: usize) -> usize {
264264
let delay_frames = self.output_delay();
265-
let output_frames_next = self.output_frames_next();
265+
let output_frames_max = self.output_frames_max();
266266
let expected_output_len = (self.resample_ratio() * input_len as f64).ceil() as usize;
267-
delay_frames + output_frames_next + expected_output_len
267+
delay_frames + output_frames_max + expected_output_len
268268
}
269269

270270
/// Get the maximum possible number of input frames per channel the resampler could require.

0 commit comments

Comments
 (0)