bela-rs
now supports the new APIs (BelaHw
/board
and stopButtonPin
)
Realtime audio drivers in Rust
- Edited
If you want to try out my branches of bela-sys
or bela-rs
, add
[patch.'https://github.com/andrewcsmith/bela-sys.git'.bela-sys]
git = "https://github.com/l0calh05t/bela-sys.git"
branch = "bela0.3.8b_rust1.52.0"
[patch.'https://github.com/andrewcsmith/bela-rs.git'.bela-rs]
git = "https://github.com/l0calh05t/bela-rs.git"
branch = "bela0.3.8b_rust1.52.0"
to your Cargo.toml
and add the original version to your dependencies. (I didn't change any of the URLs in case @andrewcsmith is interested in merging these patches)
Would you mind doing a PR for this so we can get it merged upstream? I'm not sure Andrew is looking at this forum.
I'm on other parts of my project (doing all the analog bits), so I didn't update the board and didn't recompile anything for quite some time now, so this went unnoticed.
fwiw, cargo and rustc work well on bela, but it's horribly slow. I was doing it on the device initially, but since it's so easy to cross-compile with rust, I ended up compiling on my laptops and sending the binary.
We can also figure out the dasp situation, surely there is a way to sort it out.
padenot Would you mind doing a PR for this so we can get it merged upstream? I'm not sure Andrew is looking at this forum.
Done
padenot fwiw, cargo and rustc work well on bela, but it's horribly slow. I was doing it on the device initially, but since it's so easy to cross-compile with rust, I ended up compiling on my laptops and sending the binary.
Yeah, I suspected as much and decided against trying it
padenot We can also figure out the dasp situation, surely there is a way to sort it out.
With the new min_const_generics
feature, it should be possible to have a generic implementation where the proper compile-time channel counts is selected at run-time from a fixed set of known channel counts. Without such workarounds AFAICT not without changing dasp
itself to support run-time variable channel counts.
I also started looking into getting bindings for the Midi support library: https://github.com/andrewcsmith/bela-rs/issues/12 / https://github.com/l0calh05t/bela-sys/tree/midi
An update for anyone interested: Midi support is in (both bela-sys
and bela-rs
, although only one with a merged PR) https://github.com/l0calh05t/bela-rs/tree/midi
After noticing a number of safety issues, I also started (and pretty much finished aside from documentation) what is pretty much a full redesign of bela-rs
: https://github.com/l0calh05t/bela-rs/tree/next
Hey @l0calh05t ! Is your next
branch a good starting place? I'm new to Rust and looking forward to learning
djensenius I hope it is a better starting point than the original, as it fixes a number of correctness/safety issues. However, it isnāt really documented yet (beyond the examples). I am working on a series of blog posts that will hopefully be helpful too: https://electric-snow.net/2021/08/26/rust-heart-bela-setting-up-cargo-for-cross-compilation/
l0calh05t Oh cool! This is great. I really look forward to your next post and reading about getting bela-sys
and bela-rs
working and happy.
I'd be happy to help make a tutorial for Mac and Unix users as well.
- Edited
djensenius Cool! Rust/Cargo are pretty damn good at cross platform, so I believe everything so far should work as-is on Mac and Linux as well (do Macs have rsync?!)
If you're completely new to Rust, check out Rustlings (and of course The Rust Programming Language!)
l0calh05t do Macs have rsync?
Yes.
l0calh05t Part two is out now: https://electric-snow.net/2021/09/13/rust-heart-bela-simd-sines/ I promise next time will contain more actual Bela specifics!
- Edited
To make Rust on Bela easier to use for everyone, I just published a cargo-generate template on GitHub: https://github.com/l0calh05t/bela-template
Would love to hear reports if it worked well for you or if you ran into any issues!
Amazing! Thanks for all that you are doing @l0calh05t !
djensenius You're welcome! And thank you so much for the show of appreciation! Blogging and tweeting can feel a lot like talking to a wall when you only have a handful of followers, so thanks for the motivation to continue
And finally getting to the juicy bits: how the new FFI crate is designed and why
https://electric-snow.net/2021/10/08/rust-heart-bela-ffi-api-design/
Part four of my Rust Bela series is out now! This time with some actual sound!
https://electric-snow.net/2021/11/30/rust-heart-bela-midi-and-sound/
Thanks for the interesting write up, it's nice to see how straightforward it is to do SIMD in Rust.
The reĀal thing alĀso had to apĀply some tricks to conĀtrol clickĀing.
Tell me about it (I wrote about it, glad to see some common interests ).
Some of them even sound kinĀda orĀgan-ish.
I modified an open source Hammond emulator for conducting a study (Ch 4 here) and something that made a big difference in the "realism" (or at least in making the sound passable) was the relative weighing of the partials: in practice the gains are far from unitary. To get an approximation of that I played all the notes on a Hammond C3 with only one drawbar active at any time. With a Matlab script I was able to infer the relative weights. Although clearly these are just an approximation of what happens when they are summed together, the difference it made to the sound was night and day.
- Edited
giuliomoro Thanks for the interesting write up, it's nice to see how straightforward it is to do SIMD in Rust.
Yeah, and not even a single CPU-specific line of code was necessary. This was my first experiment with Rustās explicit SIMD support and I was very impressed as well. Since my original post on the topic, the Rust library team actually integrated the portable_simd
crate into the standard library (still nightly only though!)
giuliomoro Tell me about it (I wrote about it, glad to see some common interests
).
Cool! Thanks for the link I was planning to base it on info I find around the web on pages like the Hammond Wiki (such as how the manuals are tapered). And it turns out they actually link your article on the key click page! I may have to pick your brain on some topics when the project is further along
giuliomoro I modified an open source Hammond emulator for conducting a study (Ch 4 here) and something that made a big difference in the "realism" (or at least in making the sound passable) was the relative weighing of the partials: in practice the gains are far from unitary. To get an approximation of that I played all the notes on a Hammond C3 with only one drawbar active at any time. With a Matlab script I was able to infer the relative weights. Although clearly these are just an approximation of what happens when they are summed together, the difference it made to the sound was night and day.
I wonder why I didnāt find that one during my research But for now Iāll stick to basing it on tech specs instead of existing code. If Iām not mistaken, the tapering, interacting with the passive summing via the drawbar transformers and the preamp creates the weighting of the partials (which may vary if multiple keys use the same tone wheel). And as your thesis abstract states: standard MIDI keyboards really arenāt the correct approach for a Hammond simulation! But no time (or skill) for custom hardware
l0calh05t And it turns out they actually link your article on the key click page!
Wow I had no idea. I have been a big fan of that site obviously!
l0calh05t But for now Iāll stick to basing it on tech specs instead of existing code.
that sounds good. In the end I spent perhaps more time understanding their code than it would have taken to implement it from scratch ... they try to be clever about many things that make perhaps sense in a VST context but not so much in the context of an embedded instrument...