playback audio to a non-default playback device in .net - c#

How can I playback audio to a non-default playback device in .net? Help would be wonderful! Audio playback to the default playback device is easy, however machines can have multiple playback devices for many reasons, and many common application allow selecting a non-default device for playback and recording. Is there a way to do this hopefully avoiding pinvoke? media foundation or core audio? Thank you in advance.

KindReality,
This might be useful to you. NAudio has seemingly already wrapped up a few API's for you (and, I imagine, handles those low level calls so you don't have to). Scrolling down to "NAudio Features" will most likely reveal whether or not this is what you're looking for.

Related

Monitor USB for camera connection

I have a USB microscope camera and I would like to open the Windows 10 camera app automatically if the camera gets connected to a USB port. After checking that this isn't possible with Windows 10 at the settings level, I have decided to write a short C# program that monitors the USB ports for a camera device connection (and runs the camera display app).
As to the monitoring I haven't got a slightest clue where to begin. Needless to say that the monitoring program should be lean with respect to blocking ressources, because it would be running all the time. Can I simply obtain an event notification of USB connection? Do I have to expect problems with permissions?
And of course, suggestions for alternative approaches are welcome, if any. Note that I do not want to capture and display video from the camera myself, unless it is easier to do it that way instead of opening the existing camera app.
assuming the microscope is using the web-camera interface I would look for guides about how to enumerate and connect to web-cameras. I have found a few alternatives:
Media capture API
Aforge
Versatile WebCam
I had most success with versatile webcam, but if you just want to enumerate devices any of them should do. Aforge is probably the easiest to use.
You can then use a timer to check for devices, and do something if the microscope is connected.
If the microscope is not a webcamera you will need to refer to the camera documentation on how to enumerate devices.

Capture speaker output

I've seen that I can capture the microphone and sound-files with elements in the Windows.Media.Audio namespace. I'm looking to capture the speaker output, though. For example, I click on something and the system sounds the alert sound - I want to be able to capture that.
Is there any way of doing that using elements in Windows.Media.Audio (instead of going more low level into Win32 calls)?
Well, even with "low level Win32 calls", you can't do any loopback recording in UWP.
This is traditionally done with WASAPI, but due to the sandboxed execution of universal applications, you can't open any capture streams on audio render devices in WASAPI.
In general, if you dive into COM APIs which have been ported to UWP, you will notice that there have been a lot of restrictions.

Should I use DirectSound or WASAPI for my audio project?

I am starting a project where minimum requirements will be Windows 7. I'll be using NAudio as my interface to audio. I am not sure what I should be using: DirectSound or WASAPI? I am going to be doing the following:
Manipulating volume/mute on multiple USB sound cards for both speaker and the microphone.
Rerouting input from sound card 2 into the output of the sound card 2 (if that's possible).
Manipulating the audio input of the sound card with some effects.
I understand that behind the scenes DirectSound processes all the audio via WASAPI anyway and it sounds like DirectSound has joined the list of deprecated technologies.
However, my question is more from a functional level: which API will let me do what I described above.
where minimum requirements will be Windows 7
Certainly WASAPI - you have better control over things, WASAPI interfaces/API are well made and easier to use, less overhead if you need to be close to real time. There is nothing on th elist that DirectSound can give you and WASAPI can not.
The only reason to use DirectSound if you need pre-Vista systems where WASAPI was just not available.

Simulating Screen capturing as a webcam?

Do we have a way to simulate a webcam driver, that will provide realtime captured screen (30 frames per sec) as it's output?
This is one of several features of ManyCam (free). It is a virtual webcam driver through which you can stream your real webcam video (with optional real-time video effects), video or image files, or your full/partial desktop.
Yes, just google video2webcam. It works quite well and will loop a video or picture as output.
The driver's job is to provide a level of abstraction between the software and hardware. The driver is supposed to issue commands to the hardware. It's not responsible for taking pictures and turning it into an animated GIF for instance. It's going to do low level stuff like, turn the device on and off, send raw data to a socket.
That being said, if you need to create a virtual device driver. Here's an overview of VDD's. Windows Programming/Device Driver Introduction
Generally these are not written in higher-level languages such as C#. Rather, they are written in languages such as C/C++. You will need the KMDF, or Kernel-Mode Driver Framework.
If you just need to access a webcam from a .NET application on a system with a webcam, you just need an API.
Open your browser.. go to google.com and type ".NET webcam API"
You will see something like this:
Webcam in your own application
It appears that this is a wrapper for the DirectShow class.

Get sample of sound from stereo mix in Windows

Is there a way in Windows using C# to record a sample of the stereo mix?
In other words, record all pings, beeps and music being played via any application? I've had a look at NAudio which will record the microphone as it's source, but I can't figure out how to point it at Windows' stereo mix?
Or, if anyone knows, any pointers on how to target and record sound from a specific application? For this I'm only concerned with Vista or Windows 7, as both the aforementioned operating systems support mixing applications separately - so I wasn't sure if there was a way to tap into that.
I've looked at WINMM and COREDLL too, but I'm a bit lost.
I think first you have to activate the stereo mix device in the control panel, then you should be able to record from it. Check this msdn thread: How to record from 'Wave' or 'Stereo Mix' in Vista.

Categories