You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use rust-samplerate inside a CPAL call-back (which lives in it's own thread). The idea is to have the Samplerate object persist between call-back calls, to enable stream processing.
My use case is that the real-time DSP code I'm working on requires a sample rate that the host does not support, and I was going to SRC the data from/to the host to match the required rate.
However, this doesn't seem possible:
error[E0277]: `*mut libsamplerate_sys::SRC_STATE_tag` cannot be sent between threads safely
--> src/audio_subsystem/cpal_manager.rs:310:52
|
310 | self.input_stream = Some(self.input_device.build_input_stream(
| ^^^^^^^^^^^^^^^^^^ `*mut libsamplerate_sys::SRC_STATE_tag` cannot be sent between threads safely
|
= help: within `CpalManager`, the trait `Send` is not implemented for `*mut libsamplerate_sys::SRC_STATE_tag`
= note: required because it appears within the type `Samplerate`
Could the Send trait be added to enable this use case? Or am I doing something silly instead?
Update: I've changed the following in "samplerate.rs", and now things compile. But, I'm very uncertain whether or not this is valid...
pub struct Samplerate {
ptr: *mut SRC_STATE,
from_rate: u32,
to_rate: u32,
}
// TODO: Hack to make this work for the CPAL call-back thread in rci-dsp-test.
// But, is this VALID?????
unsafe impl Send for Samplerate {}
Thank you
The text was updated successfully, but these errors were encountered:
I faced the same design issue while integrating with jack, I could fix it by not using the callback API and then I could initialize Samplerate directly inside the thread where it will be used.
There is no point sending it from thread to thread, in your case it might work fine but it would be unsafe in general AFAIU.
Hello,
I'm trying to use rust-samplerate inside a CPAL call-back (which lives in it's own thread). The idea is to have the Samplerate object persist between call-back calls, to enable stream processing.
My use case is that the real-time DSP code I'm working on requires a sample rate that the host does not support, and I was going to SRC the data from/to the host to match the required rate.
However, this doesn't seem possible:
Could the Send trait be added to enable this use case? Or am I doing something silly instead?
Update: I've changed the following in "samplerate.rs", and now things compile. But, I'm very uncertain whether or not this is valid...
Thank you
The text was updated successfully, but these errors were encountered: