Get sample of sound from stereo mix in Windows - c#

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.

Related

Getting the input level of microphone in windows IOT Core UWP

I'm trying to get the actual input volume of a microphone while not recording.
My point is to start recording when sound go up some limit for a while.
I've found the NAudio nuget but it seems that's the wavein class dont exist in UWP.
How can i get the actual input volume of a microphone in c# whitout recording ?
I was looking for the same thing. Did you find anything?
If not, you can check this link
Windows IoT Core : Sensing Sound Levels
https://blog.falafel.com/windows-iot-core-sensing-sound/
It uses following components
1) Electret Microphone Amplifier – MAX9814 with Auto Gain Control
2) MCP3008 – 8 Channel 10-Bit ADC with SPI Interface
3) Pi Cobbler Plus
4) Your existing Raspberry Pi – Windows IoT Core Setup
In case if the above doesn't work try this Youtube URL and it might give you some hint to find the actual code: https://www.youtube.com/watch?v=f3Wt4xpkBYk
I have tried and tested the code as is in my project and it worked. Although there is hardware dependency such as you may need amplifiers to make it accurate otherwise small sounds doesn't work But then amplifiers need to be handled well otherwise smallest sounds make huge difference on the bar. I am trying to modify this to work with any USB microphone or computer so that I don't have to rely on mentioned hardware.

Change system volume in Windows Phone 8

Up until now I thought that changing the system volume from your app is impossible, until recently a new app called Quite Hours (http://www.windowsphone.com/en-us/store/app/quiet-hours/f347a36b-80c0-430f-8631-e55046ee5a2a) actually did just that in a very neat way.
Does anyone please know how to do that programmatically? I tried using the MediaElement or the xna MediaPlayer and the backgroundAudioPlayer and nothing worked. Any help would be appreciated!
Thank you!
The developers of the apps mentioned in the OP were able to change system volume under WP8.0. Apparently whatever method they used has now been disabled under WP8.1. The following apps now display disclaimers that they no longer work on Windows Phone 8.1: Quiet Hours and Volume Manager
They direct to the following page to vote to allow this functionality: Windows Phone Dev User Voice
Additionally please read the following thread on the MSDN forum: MSDN change system volume Windows Phone 8. This functionality was likely achieved using WASAPI (which I have personally tried, and failed, it does not work, comment if you want my code to try it.), or the developers of the volume apps might have had access to AudioClientRestricted.h. If one had that h file, one would have access to system volume under WP8.1, so I somehow doubt the developers used the h file designated for OEMs because it would work un 8.1.
Talking with James Dailey (who works # MSFT) indicates it is technically possible using WASAPI ISimpleAudioVolume If you read # the bottom of that page there is a comment indicating you must use IAudioEndpointVolume
Added note from James Dailey # MSFT:
AFAIK there is no good way to manipulate the global audio level on
Windows Phone 8.1 (WP8.1). Theoretically you can change the audio
volume of any app that uses the default audio session “zero”. However,
if the app chooses to initialize it’s audio session with a custom
GUID you will not have access to the session volume for its custom
audio session. Again this is theoretical based on my knowledge of the
inner workings of WASAPI. I’ve never actually tried it on the phone.
To manipulate the audio volume of apps using audio session “zero” you
simply initialize your IAudioClient with an AudioSessionGuid parameter
of “{00000000-0000-0000-0000-000000000000}”. You can then use
ISimpleAudioVolume::SetMasterVolume to set the volume for this audio
session. You will need to use C++ / Cx since we do not support
calling WASAPI from managed code.
There currently is no API available for controlling the system volume. You can however control the volume in the elements of your application (via the classes MediaElement, BackgroundAudioAgent).
You can also control the volume on sound effects of your application using XNA API.
See http://msdn.microsoft.com/en-us/library/bb195052%28v=xnagamestudio.30%29.aspx

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.

Windows 8 Metro record audio (filter noise, change pitch)

Is it possible to record audio only when there is someone talking? I want to listen to the microphone and only start recording when the "volume" is greater than some noise level (meaning someone is talking) I also need to change the pitch of the recorded audio.
I tried MediaCapture class in C# but StartRecordToStorageFileAsync from a sample is not useable in my scenario. In Windows Phone I use XNA but I cannot find a similiar API in Windows 8.
Check this thread on MSDN forums: How to get the decibel with C#?
It seems like there is and probably will not be APIs for doing that in C#, Visual Basic or JavaScript and you need to do it in a native component.
The Core Audio/WASAPI APIs from the article mentioned in that thread should have what you need: Win32 and COM for Metro style apps (multimedia)
I think this document has a description of a sample for capturing audio from a Kinect sensor that might have relevant code samples showing how you would use GetBuffer() calls to get the buffer of raw audio samples that you could process to get the information you need.

how to run nAudio on Windows XP?

I am using nAudio on my WPF Application.
I have followed their tutorial on How to play mp3 And everything works fine.
However, in their tutorial they mention :
3) In a method – that only needs to be called once, setup the
waveOutDevice. In this example we will use WASPI – which is available
on Vista and Windows 7. A more detailed discussion on which output
device to chose and when, to come latter
waveOutDevice = new WasapiOut(AudioClientShareMode.Shared, 100);
And for some reason, they didn't discuss on how to do that.
Anyone has a clue?
And if you do know which output device i should use, do i need to check which OS
the user has and set output device accordingly or the one for XP will work on
You basically have four options for playing audio with NAudio:
AsioOut - For most things, ASIO is probably overkill. But if you need very low latency playback, this is your best bet. It requires a sound card with ASIO drivers or the program ASIO4ALL.
DirectSoundOut - Uses DirectX for playback.
WasapiOut - General purpose playback for Vista and Windows 7.
WaveOut - General purpose playback for any version of Windows.
All of them implement IWavePlayer, so once instantiated, using them is pretty much the same for each class - just call Init() and pass in your IWaveProvider. All of them except WasapiOut can be constructed without paramaters, so all you need is:
waveOutDevice = new WaveOut();

Categories