Using Rust code in a standard C++ UGen

I wanted to see if you could write DSP code in Rust then link to that code in a standard SC UGen. Well, you can! I have made an example, and very basic, UGen here:

You should be able to download and compile this with a combination of cargo and cmake. Instructions are in the ReadMe. I don’t claim this is a good idea or the best implementation, but more of a proof of concept for those of us who might like coding in Rust. It does seem efficient, though not as efficient as LFSaw.

One thing that I am unsure of is whether the destructor ever gets called in the Rust code. It should be called from the UGen destructor.

Sam

5 Likes

@nathan - this may be of interest to you…

Just an update on this. I made two versions of the RustSaw, one that calls Rust to calculate each sample, one at a time, and one (RustSawN) that passes the input and output buffers to Rust and Rust calculates the entire block of samples. This doesn’t seem to change efficiency. I realize this is niche knowledge that I don’t even know if I will use, but I wanted to make it as complete as I could. I am no expert in Rust FFI, so take this solution with a grain of salt. If anyone wants to improve upon it, I’d love that.

Sam

1 Like