Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross platform desktop audio recording? #35

Open
nestarz opened this issue Oct 17, 2021 · 2 comments
Open

Cross platform desktop audio recording? #35

nestarz opened this issue Oct 17, 2021 · 2 comments
Labels
question Further information is requested

Comments

@nestarz
Copy link

nestarz commented Oct 17, 2021

Hello @AldaronLau !

I am following your answer you made at the exact same question I am asking now but on reddit Cross platform desktop audio recording, do you know if it's already doable with your crate ? And if not do you know any other way to do it without configuring the audio output as input, maybe with https://github.com/RustAudio/rust-jack ?

I am asking this mainly because I can't run modprobe snd-aloop to create a loopback in my environment (bc its linux container on an arbitrary kernel that will not support module snd-aloop and netiher its host).

Thanks for your work !

I tried with no luck this adaptation of your test code:

use fon::{stereo::Stereo32, Sink, Audio};
use pasts::{exec, wait};
use wavy::{Speakers, SpeakersSink};

enum Event<'a> {
    Record(SpeakersSink<'a, Stereo32>),
}

struct State {
    buffer: Audio<Stereo32>,
}

impl State {
    fn event(&mut self, event: Event<'_>) {
        match event {
            Event::Record(microphone) => self.buffer.extend(microphone),
        }
    }
}

/// Program start.
fn main() {
    let mut state = State { buffer: Audio::with_silence(48_000, 0) };
    let mut speakers = Speakers::default();

    exec!(state.event(wait! {
        Event::Record(speakers.play().await),
    }));
}
@AldaronLau
Copy link
Member

@nestarz I believe there are different ways to setup audio output as an input, but they vary based on whether you're using Jack, PulseAudio or Pipewire. You will likely have to have one of them installed in your container, or maybe there's even an ALSA configuration that works (although maybe not since you can't do modprobe snd-aloop).

Your example is based on the playback example - so it doesn't actually record anything. You will have to use the Microphone type even though it's not an actual microphone (it's application audio output emulating a microphone).

If it's an issue with wavy, I'd like to fix it - so, can you provide information on what kind of container setup / host OS you are using?

Personally, I have done the desktop recording with a PulseAudio setup, which turns ALSA's default microphone to the application's audio output, allowing it to work with wavy.

@nestarz
Copy link
Author

nestarz commented Oct 17, 2021

Thank you for your help @AldaronLau

I will use an OCI container which includes Supercollider that should run on any host, with or without sound card, and without tweaking the host (hence no modprobe snd-aloop) which could be linux, osx or windows.
Supercollider must be connected to Jack, so I will run Jack or something like Pipewire emulating Jack on a dummy driver.
Then I want to use Rust to capture what is sent to Jack/Pipewire to be able to process the data.

I have an experiment where it works but by using Icecast and Darkice with Jack dummy driver and a right asound.rc, but those two tools do not meet the live requirements I need. So I am trying to be fully in control of the capture and processing using Rust (also because it's a great excuse for me to learn Rust !).

I opened an issue on rust-jack RustAudio/rust-jack#145 to know if we could do the loopback exclusively from Rust and Jack API.

After that I also discovered Pipewire thanks to an answer in a related issue on the cpal crate here RustAudio/cpal#310 (comment) so I am right now trying to use Pipewire Rust bindings, and see if I understand how it can works.

Related to wavy, I don't really know what I should do from Rust to allow wavy to capture the audio playback, I'm still trying to figure if wavy can help me do all that.

@AldaronLau AldaronLau added the question Further information is requested label May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants