Skip to content

trait Send for *mut libsamplerate_sys::SRC_STATE_tag #9

@TomDeRybel

Description

@TomDeRybel

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions