Should I use DirectSound or WASAPI for my audio project? - c#

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.

Related

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.

Split an audio file to play down each channel of 5.1 using C#.Net

I have a Sweex 5.1 PCI card and ideally I'd like to play separate mono audio down each channel.
Is this possible at all even if not using C#.Net?
As an insight, it's basically for a Halloween Party. I'd like to extend the speakers into different rooms and play sound effects from the PC thus one speaker in one room playing one sound, and so forth.
I've tried searching on here but the solutions seem to be the opposite way round :-/
Many thanks in advance

Recording sound in real time with c++ or C#

I have a professional sound card, and I want to record the signals from the guitar with c++ or c# for developing guitar effects in real time.
How can i record in real time through a c++ method ?
Is it mean that I need the sound card API ?
this one is enough?
Although may not be as easy as using a pre-built library, you may be able to get a C++ SDK for your sound card from the manufacturer. I would start by browsing their site or contacting support.
If that isn't an option, you can also use DirectSound which is part of the DirectX family of products. The learning curve is fairly steep but I believe it should do just about anything you want.
One final option is to look at a favorite tool (such as sound forge). A number of these tools support automation which means you can click through the app, decide what you want, then automate that sequence of events (See this as an example).
Hope that helps, best of luck!
Side Note: I have developed a number of hardware interfaces and in my experience its best to start with an example that does at least something like what you are looking for, then modify the code from there. If any particular option doesn't have an example like this I would probably skip it in favor of an example that does.
Examples
Direct Sound - Microsoft has a learning site for direct sound which you can find here. I also found this blog article which has an example for recording audio with direct sound.
Sound Forge - If you download the "Script Developers Kit" there are examples for C# in the scripts folder that should get you started. I believe this particular tool is more focused on editing and effects but I am guessing there should be automation for recording.
To just record audio in real time, any API will be fine. Note that WASAPI is the primary API (since Vista), and legacy APIs like WaveIn API, DirectSound are implemented on top of WASAPI as compatibility layers.
Regular APIs assume you are okay to certain processing latency/overhead, on the order of tens of milliseconds.
If you are going to be faster than this, and you need real time performance, such as to process data and return in back for playback as soon as possible, you need so called exclusive mode streams, where you can achieve latencies on the order of a few milliseconds, which is on par to professional audio development kits.
Windows SDK has a few audio recording samples in \Samples\multimedia\audio (C++)
It's probably a good idea to use a third party library for that.
There's a multitude of options. The ones I know of are portaudio and STK.
I like the Fmod API which supports recording (Sound recording with FMOD library) and realtime effects.

sending a beep through microphone input

Is a way of creating a program (either in C(+,++,#) or VB.net) that would be able to send a beep sound through the same line-in that is being used for audacity (not stereo mix)?
I am trying to make a way of syncing up audio and video from 2 different programs, in a similar way that a clapper bored works in the movies.
Would there be a way of using a sort of microphone enhancement that could be created because they affect the microphone input?
I assume you're trying to implement something like http://www.singularsoftware.com/pluraleyes.html then? I think the best way would be to write a VST/LADSPA plug-in for Audacity that inserts the beeps synced to a timecode stream (or whatever you're syncing to).
There's a neat little library called VST.NET that allows you to write VST plug-ins in standard C#/VB.NET if you like.

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