rubato icon indicating copy to clipboard operation
rubato copied to clipboard

asynchronous sampler crashes with access violation in fn interp_lin<T> when using chunksize of 1

Open nat3Github opened this issue 1 year ago • 4 comments

i got a access violation exception calling resampler.process_into_buffer(&self.resampler_input, &mut self.resampler_output, Some(&self.channel_mask)) ; using rubato = "0.14.1" using FastFixedOut = FastFixedOut::new(96000.0/44100.0, 100.0, PolynomialDegree::Linear, 1, 8); using Resampler::input_buffer_allocate and Resampler::output_buffer_allocate(); methods to preallocate the io buffers. this happened after a few successful calls to proccess_into_buffer() so i'm completely lost on what could be happening. image image image

nat3Github avatar Jan 11 '24 16:01 nat3Github

after testing this exception only occurs with a chunk_size of 1. if this isn't intended, here is a test to reproduce this error:

#[test] fn test_rubato() { // new resampler let parameters = SincInterpolationParameters { sinc_len: 32, f_cutoff: 0.95, oversampling_factor: 32, interpolation: rubato::SincInterpolationType::Nearest, window: rubato::WindowFunction::Blackman }; const CHUNK_SIZE:usize = 4; let resamplerx: SincFixedOut = rubato::SincFixedOut::new(44100.0/44100.0, 10.0, parameters, CHUNK_SIZE, 2).ok().unwrap(); let mut resampler_input: Vec>= Resampler::input_buffer_allocate(&resamplerx, true); let mut resampler_output: Vec>= Resampler::output_buffer_allocate( &resamplerx, true); let mut resampler: SincFixedOut = resamplerx;
let delay = Duration::from_micros(3);
for _ in 0..4000 {
    sleep(delay);
    Resampler::process_into_buffer(&mut resampler, &resampler_input, &mut resampler_output, None).unwrap();
}

}

if this is intended then id be happy if an assertion or note in the docs is added. thank you

nat3Github avatar Jan 11 '24 19:01 nat3Github

Thanks for the report! Running with a chunksize of 1 will be extremely inefficient, so it's not something to recommend ever doing. But it should still work. I'll fix it in the next release. Try to use a chunksize of at least 100 (ideally a bit larger, like 1000) if you want good performance.

HEnquist avatar Jan 11 '24 19:01 HEnquist

my goal was sample accurate resampling related to resample ratio. but you're right thats probably overkill. nonetheless in my case chunksize has to be small in order to get low latency.

thank you for your work and quick response! :)

nat3Github avatar Jan 12 '24 01:01 nat3Github

A fix is included in https://github.com/HEnquist/rubato/pull/78

HEnquist avatar Feb 27 '24 22:02 HEnquist