FrameworkComputer / inputmodule-rs

Framework Laptop 16 Input Module SW/FW
MIT License
223 stars 24 forks source link

Waveform audio input on `ledmatrix` #34

Closed zachfeldman closed 1 year ago

zachfeldman commented 1 year ago

Trying to work with an example at https://github.com/Rahix/visualizer2/blob/canon/README.md and @JohnAZoidberg 's boilerplate eq module code to get the ledmatrix to show a rough waveform of actual current audio input!

Got it working at this point. This is just grabbing the audio input stream with some Rust wrappers for it cpal https://github.com/RustAudio/cpal and https://github.com/diwic/alsa-rs to access the underlying alsa layer at the system level.

Demo: https://photos.app.goo.gl/C6NMsZdKnLAnXpwW9

Testing Instructions

cargo run --target x86_64-unknown-linux-gnu -p inputmodule-control led-matrix --input-eq

Then make some noise, assuming your microphone/input is on - try clapping, singing, putting on some music decently loudly, etc!

Next on the to-do list:

zachfeldman commented 1 year ago

@JohnAZoidberg any tips on how to solve the problem with the build? It seems like some of the crates are defining duplicate symbols but not even sure where to start debugging that :)...

JohnAZoidberg commented 1 year ago

@JohnAZoidberg any tips on how to solve the problem with the build? It seems like some of the crates are defining duplicate symbols but not even sure where to start debugging that :)...

You've got AnalyzerResult twice in the code. Just need to remove that.

JohnAZoidberg commented 1 year ago

Oh you mean = note: rust-lld: error: duplicate symbol: _rphal_unsigned_divmod when building the FW, not the tool. Yeah... that's because it tried to build with multiple different incompatible versions of the rp2040-hal crate. I thought I had fixed it already.

JohnAZoidberg commented 1 year ago

Can confirm it works

zachfeldman commented 1 year ago

@JohnAZoidberg no rush at all, but I think this is ready for another review when you are.

Thanks for the help whipping it into shape!

zachfeldman commented 1 year ago

@JohnAZoidberg I made the audio-visualizations an optional feature but for some reason even when I build without it the Cargo.lock still gets updated. I restored the one from main, but should I just push the modified one when I build? I imagine next time someone does a build it'll get modified anyway, and the main thing that'll improve build times is making it an optional feature, it may not matter that the Cargo.lock is longer now, right?

EDIT: A bit of Googling made me realize this is expected behavior https://github.com/rust-lang/cargo/issues/10801 so I removed the commit to restore Cargo.lock. Build times are still faster with this as an opt-in feature and it's clear it's just in the Cargo.lock as part of how this currently works.

JohnAZoidberg commented 1 year ago

Yeah, that's perfectly fine. A bit odd, but does no harm.

JohnAZoidberg commented 1 year ago

Alright, let's go ahead and merge this! Feel free to improve upon it.