Rust Audio

Example source code for calling Rust from GNU Octave

Hi all,

As we all know, Rust is a great language for writing real-time audio software because it does not rely on a garbage collector for memory safety, because of its zero-cost abstractions and its excellent tooling.

But when it comes to prototyping, you want an interactive language with lots of support for linear algebra and numerical mathematics and with the ability to plot your data. Something like GNU Octave (or Python, or …).

But what if you want to call your Rust code from GNU Octave? Octave supports extending with “.oct” files, which you can write in C++ … from which you can call your Rust code.

I have written an example that illustrates how you can do this. It’s permissively “licensed” under the unlicense, so that you can easily copy-paste into your own projects without worrying.

Have fun!


That sounds neat!

I have two questions, being completely new around here

  1. How do I see the output in action? I don’t see any run instructions on the repo and don’t have much Octave experience.
  2. Strange enough, Arch Linux doesn’t appear to have a liboctave-dev available for download, so it doesn’t appear I can try it – I googled a little and didn’t spot any guides. It compiled fine without me downloading anything extra. Do you know what files need to be present for the compilation? I can try and find them.

These are great questions!

  1. I have updated the README to include instructions for using the generated .oct file.

  2. I have no experience at all with Arch Linux, so I can’t tell for sure. Generally speaking, look for a package that contains the mkoctfile command.

Also, I have forgotten to mention that if you have no experience with GNU Octave, but you have experience with Python, it’s good to know that Python can also be used interactively and also has packages for numerical mathematics and that Rust can also be integrated in a Python workflow.

Thanks for the update, I’ll give it a shot!
As to the “mkoctfile” command, you can add to your README that for Arch Linux you simply need to install “octave”, as it is distributed with that package. :slight_smile:

Done! Thanks for your input!

1 Like