katyo / aubio-rs

Rust bindings for Aubio library
37 stars 7 forks source link

How to use the Resampler #14

Closed Flocksserver closed 3 years ago

Flocksserver commented 3 years ago

Hey, first of all thanks you for your work.

I am a bit confused about how to use some parts of your lib.

For example: I would like to resample some wav files. But I don't know which parameters I have use to call the function do_.

let output_sample_rate = 8000;
let mut reader = WavReader::open("./test.wav").unwrap();
let input_sample_rate = reader.spec().sample_rate;
let ratio = (output_sample_rate / input_sample_rate) as f32;
let mut rs = Resampler::new(ratio, ResampleMode::BestQuality).unwrap();

do_ takes structs from your library. One can construct them by calling FVec::from and FVecMut::from but I have a BufReader<File> as input and what as output? And how to pass/convert a BufReader<File> to [f32]

Maybe my question is stupid - but it would be really nice if you support me.

In general it would be a massiv improvement to have more examples :) Best :)

katyo commented 3 years ago

@Flocksserver Thanks for interest to this bindings. This little bit far to completion especially in aspect of docs and examples.

The types FVec and FVecMut wraps slices of Rust's f32 to use as an aubio's fvec_t type to transfer audio data.

The aubio's APIs operates with sample buffers. So you should read some number of audio samples to memory buffer (for ex. Vec<f32>) first. For offline (non-realtime) conversion I recommend use buffers as large as possible to get the maximum performance with reasonable RAM usage.

The N means the input buffer size in samples. Say you want to resample the buffer which contains 33 samples from 48000Hz to 44100Hz. In that case you must provide output buffer to write at least 30 samples ((33.0 * 44100.0 / 48000.0).floor()).

Flocksserver commented 3 years ago

Ok that makes sense! Thanks for the explanation.