Skip to content

Implement WASAPI loopback support#339

Merged
est31 merged 1 commit into
RustAudio:masterfrom
lucy:master
Nov 17, 2019
Merged

Implement WASAPI loopback support#339
est31 merged 1 commit into
RustAudio:masterfrom
lucy:master

Conversation

@lucy

@lucy lucy commented Oct 12, 2019

Copy link
Copy Markdown
Contributor

This works by detecting output devices in build_input_stream() and
setting the AUDCLNT_STREAMFLAGS_LOOPBACK flag to enable loopback
recording.

closes #251

@lucy

lucy commented Oct 12, 2019

Copy link
Copy Markdown
Contributor Author

Tested with:

diff --git a/examples/record_wav.rs b/examples/record_wav.rs
index 9127123..01f7c2d 100644
--- a/examples/record_wav.rs
+++ b/examples/record_wav.rs
@@ -13,9 +13,9 @@ fn main() -> Result<(), failure::Error> {
     let host = cpal::default_host();

     // Setup the default input device and stream with the default input format.
-    let device = host.default_input_device().expect("Failed to get default input device");
+    let device = host.default_output_device().expect("Failed to get default input device");
     println!("Default input device: {}", device.name()?);
-    let format = device.default_input_format().expect("Failed to get default input format");
+    let format = device.default_output_format().expect("Failed to get default input format");
     println!("Default input format: {:?}", format);
     let event_loop = host.event_loop();
     let stream_id = event_loop.build_input_stream(&device, &format)?;

@ishitatsuyuki

ishitatsuyuki commented Oct 13, 2019

Copy link
Copy Markdown
Collaborator

I think this is okay, but the current API design makes it a very hidden feature. Would you like to add some docs?

Though I think we might change the Device API to differ between input and output devices, someday. At that time we might need to add a Windows-specific function to convert an output to "loopback" input.

@lucy

lucy commented Oct 19, 2019

Copy link
Copy Markdown
Contributor Author

What's a good place to document this?

@ishitatsuyuki

Copy link
Copy Markdown
Collaborator

I think you can document it as a part of WasapiHost.

This works by detecting output devices in build_input_stream() and
setting the AUDCLNT_STREAMFLAGS_LOOPBACK flag to enable loopback
recording.

closes RustAudio#251
@memchk

memchk commented Nov 17, 2019

Copy link
Copy Markdown

Is there a way I can help push this forward? I have a project here, that would really benefit from this being merged. I currently have a vendored version of cpal with hacked together loopback support, it would be awesome if I could use a upstream version.

@est31

est31 commented Nov 17, 2019

Copy link
Copy Markdown
Member

Merging as per @ishitatsuyuki 's approval, there seem to be docs now.

@est31 est31 merged commit 90be524 into RustAudio:master Nov 17, 2019
@memchk

memchk commented Nov 17, 2019

Copy link
Copy Markdown

Awesome! Thank y'all for the continued work on cpal!

@open-trade

Copy link
Copy Markdown

Is there any document or example about how to use loopback in RustAudio/cpal?

@SirJson

SirJson commented Jun 28, 2020

Copy link
Copy Markdown

It used to be as simple as just creating an input stream and sticking that into your output stream. The cpal API changed tho and I didn't had the time to wrap my head around it so I can't provide example code. But I guess the general idea didn't change here, just the function names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support WASAPI Loopback

6 participants